Search is not available for this dataset
text
stringlengths
75
104k
def list_reced_topics(self, user_alias=None, start=0): """ 推荐的话题列表 :param user_alias: 指定用户,默认当前 :param start: 翻页 :return: 带下一页的列表 """ user_alias = user_alias or self.api.user_alias xml = self.api.xml(API_GROUP_LIST_USER_RECED_TOPICS % user_alias, ...
def add_topic(self, group_alias, title, content): """ 创建话题(小心验证码~) :param group_alias: 小组ID :param title: 标题 :param content: 内容 :return: bool """ xml = self.api.req(API_GROUP_ADD_TOPIC % group_alias, 'post', data={ 'ck': self.api.ck(),...
def remove_topic(self, topic_id): """ 删除话题(需要先删除所有评论,使用默认参数) :param topic_id: 话题ID :return: None """ comment_start = 0 while comment_start is not None: comments = self.list_comments(topic_id, comment_start) for comment in comments[...
def update_topic(self, topic_id, title, content): """ 更新话题 :param topic_id: 话题ID :param title: 标题 :param content: 内容 :return: bool """ xml = self.api.req(API_GROUP_UPDATE_TOPIC % topic_id, 'post', data={ 'ck': self.api.ck(), ...
def list_comments(self, topic_id, start=0): """ 回复列表 :param topic_id: 话题ID :param start: 翻页 :return: 带下一页的列表 """ xml = self.api.xml(API_GROUP_GET_TOPIC % topic_id, params={'start': start}) xml_results = xml.xpath('//ul[@id="comments"]/li') ...
def add_comment(self, topic_id, content, reply_id=None): """ 添加评论 :param topic_id: 话题ID :param content: 内容 :param reply_id: 回复ID :return: None """ return self.api.req(API_GROUP_ADD_COMMENT % topic_id, 'post', data={ 'ck': self.api.ck()...
def remove_comment(self, topic_id, comment_id, reason='0', other=None): """ 删除评论(自己发的话题所有的都可以删除,否则只能删自己发的) :param topic_id: 话题ID :param comment_id: 评论ID :param reason: 原因 0/1/2 (内容不符/反动/其它) :param other: 其它原因的具体(2) :return: None """ params...
def list_user_comments(self, topic_id, user_alias=None): """ 列出用户在话题下的所有回复 :param topic_id: 话题ID :param user_alias: 用户ID,默认当前 :return: 纯列表 """ user_alias = user_alias or self.api.user_alias comment_start = 0 results = [] while comm...
def remove_commented_topic(self, topic_id): """ 删除回复的话题(删除所有自己发布的评论) :param topic_id: 话题ID :return: None """ return [self.remove_comment(topic_id, item['id']) for item in self.list_user_comments(topic_id)]
def shell(name=None, **attrs): """Creates a new :class:`Shell` with a function as callback. This works otherwise the same as :func:`command` just that the `cls` parameter is set to :class:`Shell`. """ attrs.setdefault('cls', Shell) return click.command(name, **attrs)
def getLogger(name): """This is used by gcdt plugins to get a logger with the right level.""" logger = logging.getLogger(name) # note: the level might be adjusted via '-v' option logger.setLevel(logging_config['loggers']['gcdt']['level']) return logger
def _discover(self): """Discovers methods in the XML-RPC API and creates attributes for them on this object. Enables stuff like "magento.cart.create(...)" to work without having to define Python methods for each XML-RPC equivalent. """ self._resources = {} resources = se...
def keep_session_alive(self): """If the session expired, logs back in.""" try: self.resources() except xmlrpclib.Fault as fault: if fault.faultCode == 5: self.login() else: raise
def help(self): """Prints discovered resources and their associated methods. Nice when noodling in the terminal to wrap your head around Magento's insanity. """ print('Resources:') print('') for name in sorted(self._resources.keys()): methods = sorted(self._r...
def run(self): """Import the controller and run it. This mimics the processing done by :func:`helper.start` when a controller is run in the foreground. A new instance of ``self.controller`` is created and run until a keyboard interrupt occurs or the controller stops on its own ...
def get_info(self): """ Scans the input path and automatically determines the optimal piece size based on ~1500 pieces (up to MAX_PIECE_SIZE) along with other basic info, including total size (in bytes), the total number of files, piece size (in bytes), and resulting numb...
def generate(self, callback=None): """ Computes and stores piece data. Returns ``True`` on success, ``False`` otherwise. :param callback: progress/cancellation callable with method signature ``(filename, pieces_completed, pieces_total)``. Useful for reporting pro...
def info_hash_base32(self): """ Returns the base32 info hash of the torrent. Useful for generating magnet links. .. note:: ``generate()`` must be called first. """ if getattr(self, '_data', None): return b32encode(sha1(bencode(self._data['info'])).digest()) ...
def info_hash(self): """ :return: The SHA-1 info hash of the torrent. Useful for generating magnet links. .. note:: ``generate()`` must be called first. """ if getattr(self, '_data', None): return sha1(bencode(self._data['info'])).hexdigest() else...
def req(self, url, method='get', params=None, data=None, auth=False): """ 请求API :type url: str :param url: API :type method: str :param method: HTTP METHOD :type params: dict :param params: query :type data: dict ...
def json(self, url, method='get', params=None, data=None): """ 请求并返回json :type url: str :param url: API :type method: str :param method: HTTP METHOD :type params: dict :param params: query :type data: di...
def xml(self, url, method='get', params=None, data=None): """ 请求并返回xml :type url: str :param url: API :type method: str :param method: HTTP METHOD :type params: dict :param params: query :type data: dict ...
def persist(self): """ 持久化会话信息 """ with open(self.persist_file, 'w+') as f: json.dump({ 'cookies': self.cookies, 'user_alias': self.user_alias, }, f, indent=2) self.logger.debug('persist session to <%s>' % self.persist_f...
def load(self): """ 加载会话信息 """ if not os.path.isfile(self.persist_file): return with open(self.persist_file, 'r') as f: cfg = json.load(f) or {} self.cookies = cfg.get('cookies', {}) self.user_alias = cfg.get('user_alias') or None ...
def flush(self): """ 更新会话信息,主要是ck, user_alias """ if 'dbcl2' not in self.cookies: return r = self.req(API_ACCOUNT_HOME) if RE_SESSION_EXPIRE.search(r.url): return self.expire() self.cookies.update(dict(r.cookies)) self.user_alias = ...
def login(self, username, password): """ 登录 :type username: str :param username: 用户名(手机号或者邮箱) :type password: str :param password: 密码 """ r0 = self.req(API_HOME) time.sleep(1) cookies = dict(r0.cookies) data = { ...
def use(self, cookies): """ 如果遭遇验证码,用这个接口 :type cookies: str|dict :param cookies: cookie字符串或者字典 :return: self """ self.cookies = dict([item.split('=', 1) for item in re.split(r'; *', cookies)]) \ if isinstance(cookies, str) else cookies ...
def logout(self): """ 登出会话 :return: self """ self.req(API_ACCOUNT_LOGOUT % self.ck()) self.cookies = {} self.user_alias = None self.persist()
def deploy(awsclient, applicationName, deploymentGroupName, deploymentConfigName, bucket, bundlefile): """Upload bundle and deploy to deployment group. This includes the bundle-action. :param applicationName: :param deploymentGroupName: :param deploymentConfigName: :param bucket: ...
def output_deployment_status(awsclient, deployment_id, iterations=100): """Wait until an deployment is in an steady state and output information. :param deployment_id: :param iterations: :return: exit_code """ counter = 0 steady_states = ['Succeeded', 'Failed', 'Stopped'] client_codedep...
def stop_deployment(awsclient, deployment_id): """stop tenkai deployment. :param awsclient: :param deployment_id: """ log.info('Deployment: %s - stopping active deployment.', deployment_id) client_codedeploy = awsclient.get_client('codedeploy') response = client_codedeploy.stop_deployment(...
def _list_deployment_instances(awsclient, deployment_id): """list deployment instances. :param awsclient: :param deployment_id: """ client_codedeploy = awsclient.get_client('codedeploy') instances = [] next_token = None # TODO refactor generic exhaust_function from this while True...
def _get_deployment_instance_summary(awsclient, deployment_id, instance_id): """instance summary. :param awsclient: :param deployment_id: :param instance_id: return: status, last_event """ client_codedeploy = awsclient.get_client('codedeploy') request = { 'deploymentId': deploym...
def _get_deployment_instance_diagnostics(awsclient, deployment_id, instance_id): """Gets you the diagnostics details for the first 'Failed' event. :param awsclient: :param deployment_id: :param instance_id: return: None or (error_code, script_name, message, log_tail) """ client_codedeploy =...
def output_deployment_summary(awsclient, deployment_id): """summary :param awsclient: :param deployment_id: """ log.info('\ndeployment summary:') log.info('%-22s %-12s %s', 'Instance ID', 'Status', 'Most recent event') for instance_id in _list_deployment_instances(awsclient, deployment_id):...
def output_deployment_diagnostics(awsclient, deployment_id, log_group, start_time=None): """diagnostics :param awsclient: :param deployment_id: """ headline = False for instance_id in _list_deployment_instances(awsclient, deployment_id): diagnostics = _get_deployment_instance_diagnostic...
def is_type(self): """ :return: :rtype: bool """ if self.__is_type_result is not None: return self.__is_type_result self.__is_type_result = self.__is_type() return self.__is_type_result
def validate(self, error_message=None): """ :raises TypeError: If the value is not matched the type that the class represented. """ if self.is_type(): return if not error_message: error_message = "invalid value type" raise TypeError(...
def convert(self): """ :return: Converted value. :raises typepy.TypeConversionError: If the value cannot convert. """ if self.is_type(): return self.force_convert() raise TypeConversionError( "failed to convert from {} to {}".format(t...
def always_fails( self, work_dict): """always_fails :param work_dict: dictionary for key/values """ label = "always_fails" log.info(("task - {} - start " "work_dict={}") .format(label, work_dict)) raise Exception( wo...
def name_build(self, name, is_policy=False, prefix=True): """ Build name from prefix and name + type :param name: Name of the role/policy :param is_policy: True if policy should be added as suffix :param prefix: True if prefix should be added :return: Joined name ...
def name_strip(self, name, is_policy=False, prefix=True): """ Transforms name to AWS valid characters and adds prefix and type :param name: Name of the role/policy :param is_policy: True if policy should be added as suffix :param prefix: True if prefix should be added :re...
def build_policy(self, name, statements, roles, is_managed_policy=False): """ Generate policy for IAM cloudformation template :param name: Name of the policy :param statements: The "rules" the policy should have :param roles: The roles associated with this policy :param i...
def build_policy_bucket(self, bucket, name, statements): """ Generate bucket policy for S3 bucket :param bucket: The bucket to attach policy to :param name: The name of the bucket (to generate policy name from it) :param statements: The "rules" the policy should have :ret...
def build_role(self, name, policies=False): """ Generate role for IAM cloudformation template :param name: Name of role :param policies: List of policies to attach to this role (False = none) :return: Ref to new role """ # Build role template if policies: ...
def build_bucket(self, name, lifecycle_configuration=False, use_plain_name=False): """ Generate S3 bucket statement :param name: Name of the bucket :param lifecycle_configuration: Additional lifecycle configuration (default=False) :param use_plain_name: Just ...
def directive_SPACE(self, label, params): """ label SPACE num Allocate space on the stack. `num` is the number of bytes to allocate """ # TODO allow equations params = params.strip() try: self.convert_to_integer(params) except ValueError: ...
def directive_DCD(self, label, params): """ label DCD value[, value ...] Allocate a word space in read only memory for the value or list of values """ # TODO make this read only # TODO check for param size # TODO can take any length comma separated values (VAL ...
def directive_DCH(self, label, params): """ label DCH value[, value ...] Allocate a half word space in read only memory for the value or list of values """ # TODO make this read only # TODO check for word size # Align address if self.space_pointer % 2 ...
def directive_DCB(self, label, params): """ label DCB value[, value ...] Allocate a byte space in read only memory for the value or list of values """ # TODO make this read only # TODO check for byte size self.labels[label] = self.space_pointer if param...
def get_celery_app( name=os.getenv( "CELERY_NAME", "worker"), auth_url=os.getenv( "BROKER_URL", "redis://localhost:6379/9"), backend_url=os.getenv( "BACKEND_URL", "redis://localhost:6379/10"), include_tasks=[], ...
def check_arguments(self, **kwargs): """ Determine if the parameters meet the specifications kwargs contains lists grouped by their parameter rules are defined by methods starting with 'rule_' :param kwargs: :return: """ for key in kwargs: if k...
def link(self, key1, key2): """ Make these two keys have the same value :param key1: :param key2: :return: """ # TODO make this have more than one key linked # TODO Maybe make the value a set? self._linked_keys[key1] = key2 self._linked_key...
def instance_ik_model_receiver(fn): """ A method decorator that filters out sign_original_specals coming from models that don't have fields that function as ImageFieldSourceGroup sources. """ @wraps(fn) def receiver(self, sender, **kwargs): # print 'inspect.isclass(sender? %s'%(inspect....
def source_group_receiver(self, sender, source, signal, **kwargs): """ Relay source group signals to the appropriate spec strategy. """ from imagekit.cachefiles import ImageCacheFile source_group = sender instance = kwargs['instance'] # Ignore signals from unre...
def update_source_hashes(self, instance): """ Stores hashes of the source image files so that they can be compared later to see whether the source image has changed (and therefore whether the spec file needs to be regenerated). """ self.init_instance(instance) in...
def get_source_fields(self, instance): """ Returns a list of the source fields for the given instance. """ return set(src.image_field for src in self._source_groups if isinstance(instance, src.model_class))
def on_success(self, retval, task_id, args, kwargs): """on_success http://docs.celeryproject.org/en/latest/reference/celery.app.task.html :param retval: return value :param task_id: celery task id :param args: arguments passed into task :param kwargs: keyword arguments ...
def on_failure(self, exc, task_id, args, kwargs, einfo): """on_failure http://docs.celeryproject.org/en/latest/userguide/tasks.html#task-inheritance :param exc: exception :param task_id: task id :param args: arguments passed into task :param kwargs: keyword arguments pa...
def check_hook_mechanism_is_intact(module): """Check if the hook configuration is absent or has both register AND deregister. :param module: :return: True if valid plugin / module. """ result = True if check_register_present(module): result = not result if check_deregister_present(m...
def cfn_viz(template, parameters={}, outputs={}, out=sys.stdout): """Render dot output for cloudformation.template in json format. """ known_sg, open_sg = _analyze_sg(template['Resources']) (graph, edges) = _extract_graph(template.get('Description', ''), template['Res...
def _get_fillcolor(resource_type, properties, known_sg=[], open_sg=[]): """Determine fillcolor for resources (public ones in this case) """ fillcolor = None # check security groups if 'SecurityGroups' in properties: # check for external security groups for sg in properties['SecurityG...
def svg_output(dotfile, outfile='cloudformation.svg'): """Render template into svg file using the dot command (must be installed). :param dotfile: path to the dotfile :param outfile: filename for the output file :return: """ try: cmd = ['dot', '-Tsvg', '-o' + outfile, dotfile] s...
def start(controller_class): """Start the Helper controller either in the foreground or as a daemon process. :param controller_class: The controller class handle to create and run :type controller_class: callable """ args = parser.parse() obj = controller_class(args, platform.operating_sys...
def run(self, steps=float('inf')): """ Run to the current end of the program or a number of steps :return: """ while len(self.program) > (self.register['PC'] - 1): steps -= 1 if steps < 0: break self.program[self.register['PC'] ...
def _validate_type(self, name, obj, *args): """ Helper function that checks the input object type against each in a list of classes. This function also allows the input value to be equal to None. :param name: Name of the object. :param obj: Object to check the type of. :...
def _validate_list_type(self, name, obj, *args): """ Helper function that checks the input object type against each in a list of classes, or if the input object is a list, each value that it contains against that list. :param name: Name of the object. :param obj: Object to check...
def _validate_nested_list_type(self, name, obj, nested_level, *args): """ Helper function that checks the input object as a list then recursively until nested_level is 1. :param name: Name of the object. :param obj: Object to check the type of. :param nested_level: Integer with ...
def B(self, params): """ B label Unconditional branch to the address at label """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # TODO check if label is within +- 2 KB # B label def B_func...
def BL(self, params): """ BL label Branch to the label, storing the next instruction in the Link Register """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # TODO check if label is within +- 16 MB ...
def BLX(self, params): """ BLX Rj Branch to the address in Rj, storing the next instruction in the Link Register """ Rj = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(LR_or_general_purpose_registers=(Rj,)) def BLX_func(): ...
def BX(self, params): """ BX Rj Jump to the address in the Link Register """ Rj = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(LR_or_general_purpose_registers=(Rj,)) def BX_func(): self.register['PC'] = self.register[Rj] ...
def get_version(version): """ Returns a PEP 440-compliant version number from VERSION. Created by modifying django.utils.version.get_version """ # Now build the two parts of the version number: # major = X.Y[.Z] # sub = .devN - for development releases # | {a|b|rc}N - for alpha, be...
def get_git_changeset(): """Returns a numeric identifier of the latest git changeset. The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format. This value isn't guaranteed to be unique, but collisions are very unlikely, so it's sufficient for generating the development version numbers....
def load_cloudformation_template(path=None): """Load cloudformation template from path. :param path: Absolute or relative path of cloudformation template. Defaults to cwd. :return: module, success """ if not path: path = os.path.abspath('cloudformation.py') else: path = os.path....
def get_parameter_diff(awsclient, config): """get differences between local config and currently active config """ client_cf = awsclient.get_client('cloudformation') try: stack_name = config['stack']['StackName'] if stack_name: response = client_cf.describe_stacks(StackName=s...
def call_pre_hook(awsclient, cloudformation): """Invoke the pre_hook BEFORE the config is read. :param awsclient: :param cloudformation: """ # TODO: this is deprecated!! move this to glomex_config_reader # no config available if not hasattr(cloudformation, 'pre_hook'): # hook is not...
def deploy_stack(awsclient, context, conf, cloudformation, override_stack_policy=False): """Deploy the stack to AWS cloud. Does either create or update the stack. :param conf: :param override_stack_policy: :return: exit_code """ stack_name = _get_stack_name(conf) parameters = _generate_para...
def delete_stack(awsclient, conf, feedback=True): """Delete the stack from AWS cloud. :param awsclient: :param conf: :param feedback: print out stack events (defaults to True) """ client_cf = awsclient.get_client('cloudformation') stack_name = _get_stack_name(conf) last_event = _get_sta...
def list_stacks(awsclient): """Print out the list of stacks deployed at AWS cloud. :param awsclient: :return: """ client_cf = awsclient.get_client('cloudformation') response = client_cf.list_stacks( StackStatusFilter=[ 'CREATE_IN_PROGRESS', 'CREATE_COMPLETE', 'ROLLBACK_IN_PR...
def describe_change_set(awsclient, change_set_name, stack_name): """Print out the change_set to console. This needs to run create_change_set first. :param awsclient: :param change_set_name: :param stack_name: """ client = awsclient.get_client('cloudformation') status = None while s...
def delete_change_set(awsclient, change_set_name, stack_name): """Delete specified change set. Currently we only use this during automated regression testing. But we have plans so lets locate this functionality here :param awsclient: :param change_set_name: :param stack_name: """ client...
def write_template_to_file(conf, template_body): """Writes the template to disk """ template_file_name = _get_stack_name(conf) + '-generated-cf-template.json' with open(template_file_name, 'w') as opened_file: opened_file.write(template_body) print('wrote cf-template for %s to disk: %s' % ( ...
def generate_template(context, config, cloudformation): """call cloudformation to generate the template (json format). :param context: :param config: :param cloudformation: :return: """ spec = inspect.getargspec(cloudformation.generate_template)[0] if len(spec) == 0: return clou...
def info(awsclient, config, format=None): """ collect info and output to console :param awsclient: :param config: :param json: True / False to use json format as output :return: """ if format is None: format = 'tabular' stack_name = _get_stack_name(config) client_cfn = a...
def BCC(self, params): """ BCC label Branch to the instruction at label if the C flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BCC label def BCC_func(): if not se...
def BCS(self, params): """ BCS label Branch to the instruction at label if the C flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BCS label def BCS_func(): if self.is_C_...
def BEQ(self, params): """ BEQ label Branch to the instruction at label if the Z flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BEQ label def BEQ_func(): if self.is_Z_...
def BGE(self, params): """ BGE label Branch to the instruction at label if the N flag is the same as the V flag """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BGE label def BGE_func(): ...
def BGT(self, params): """ BGT label Branch to the instruction at label if the N flag is the same as the V flag and the Z flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BGT label ...
def BHI(self, params): """ BHI label Branch to the instruction at label if the C flag is set and the Z flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BHI label def BHI_func():...
def BHS(self, params): """ BHS label Branch to the instruction at label if the C flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BHS label def BHS_func(): if self.is_C_...
def BLE(self, params): """ BLE label Branch to the instruction at label if the Z flag is set or if the N flag is not the same as the V flag """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLE label ...
def BLO(self, params): """ BLO label Branch to the instruction at label if the C flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLO label def BLO_func(): if not se...
def BLS(self, params): """ BLS label Branch to the instruction at label if the C flag is not set or the Z flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLS label def BLS_func(): ...
def BLT(self, params): """ BLT label Branch to the instruction at label if the N flag is not the same as the V flag """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BLT label def BLT_func(): ...
def BMI(self, params): """ BMI label Branch to the instruction at label if the N flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BMI label def BMI_func(): if self.is_N_...
def BNE(self, params): """ BNE label Branch to the instruction at label if the Z flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BNE label def BNE_func(): if not se...
def BPL(self, params): """ BPL label Branch to the instruction at label if the N flag is set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BPL label def BPL_func(): if not self.i...
def BVC(self, params): """ BVC label Branch to the instruction at label if the V flag is not set """ label = self.get_one_parameter(self.ONE_PARAMETER, params) self.check_arguments(label_exists=(label,)) # BVC label def BVC_func(): if not se...