code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def set_distributed_assembled(self, irn_loc, jcn_loc, a_loc): self.set_distributed_assembled_rows_cols(irn_loc, jcn_loc) self.set_distributed_assembled_values(a_loc)
Set the distributed assembled matrix. Distributed assembled matrices require setting icntl(18) != 0.
def get_all_runs(self, only_largest_budget=False): all_runs = [] for k in self.data.keys(): runs = self.get_runs_by_id(k) if len(runs) > 0: if only_largest_budget: all_runs.append(runs[-1]) else: all_runs.extend(runs) return(all_runs)
returns all runs performed Parameters ---------- only_largest_budget: boolean if True, only the largest budget for each configuration is returned. This makes sense if the runs are continued across budgets and the info field contains the information you care about. If False, all runs of a configu...
def _adjusted_script_code(self, script): script_code = ByteData() if script[0] == len(script) - 1: return script script_code += VarInt(len(script)) script_code += script return script_code
Checks if the script code pased in to the sighash function is already length-prepended This will break if there's a redeem script that's just a pushdata That won't happen in practice Args: script (bytes): the spend script Returns: (bytes): the length-prep...
def do_application_actions_plus(parser, token): nodelist = parser.parse(('end_application_actions',)) parser.delete_first_token() return ApplicationActionsPlus(nodelist)
Render actions available with extra text.
def auth_interactive(self, username, handler, submethods=""): if (not self.active) or (not self.initial_kex_done): raise SSHException("No existing session") my_event = threading.Event() self.auth_handler = AuthHandler(self) self.auth_handler.auth_interactive( user...
Authenticate to the server interactively. A handler is used to answer arbitrary questions from the server. On many servers, this is just a dumb wrapper around PAM. This method will block until the authentication succeeds or fails, peroidically calling the handler asynchronously to get...
def _split_path(self, path): if '\\' in path: p = path.find('\\') hive = path[:p] path = path[p+1:] else: hive = path path = None handle = self._hives_by_name[ hive.upper() ] return handle, path
Splits a Registry path and returns the hive and key. @type path: str @param path: Registry path. @rtype: tuple( int, str ) @return: Tuple containing the hive handle and the subkey path. The hive handle is always one of the following integer constants: - L{win...
def _setup_transitions(tdef, states, prev=()): trs = list(prev) for transition in tdef: if len(transition) == 3: (name, source, target) = transition if is_string(source) or isinstance(source, State): source = [source] source = [states[src] for src in s...
Create a TransitionList object from a 'transitions' Workflow attribute. Args: tdef: list of transition definitions states (StateList): already parsed state definitions. prev (TransitionList): transition definitions from a parent. Returns: TransitionList: the list of transitions...
def det_cplx_loglr(self, det): try: return getattr(self._current_stats, '{}_cplx_loglr'.format(det)) except AttributeError: self._loglr() return getattr(self._current_stats, '{}_cplx_loglr'.format(det))
Returns the complex log likelihood ratio in the given detector. Parameters ---------- det : str The name of the detector. Returns ------- complex float : The complex log likelihood ratio.
def reflect_left(self, value): if value > self: value = self.reflect(value) return value
Only reflects the value if is > self.
def _reference_keys(self, reference): if not isinstance(reference, six.string_types): raise TypeError( 'When using ~ to reference dynamic attributes ref must be a str. a {0} was provided.'.format(type(reference).__name__) ) if '~' in reference: referen...
Returns a list of all of keys for a given reference. :param reference: a :string: :rtype: A :list: of reference keys.
def ValidateServiceGaps(self, problems, validation_start_date, validation_end_date, service_gap_interval): if service_gap_interval is None: return departures = self.GenerateDateTripsDeparturesList(valid...
Validate consecutive dates without service in the feed. Issue a warning if it finds service gaps of at least "service_gap_interval" consecutive days in the date range [validation_start_date, last_service_date) Args: problems: The problem reporter object validation_start_date: A dat...
def takes_parameters(count): def decorator(f): @wraps(f) def wrapper(filter_operation_info, location, context, parameters, *args, **kwargs): if len(parameters) != count: raise GraphQLCompilationError(u'Incorrect number of parameters, expected {} got ' ...
Ensure the filter function has "count" parameters specified.
def OnCellBackgroundColor(self, event): with undo.group(_("Background color")): self.grid.actions.set_attr("bgcolor", event.color) self.grid.ForceRefresh() self.grid.update_attribute_toolbar() event.Skip()
Cell background color event handler
def bin(self): bits = self.v == 4 and 32 or 128 return bin(self.ip).split('b')[1].rjust(bits, '0')
Full-length binary representation of the IP address. >>> ip = IP("127.0.0.1") >>> print(ip.bin()) 01111111000000000000000000000001
def _loadError(ErrorType, thrownError, tracebackString): RemoteException = asRemoteException(ErrorType) return RemoteException(thrownError, tracebackString)
constructor of RemoteExceptions
def device_id_partition_keygen(request_envelope): try: device_id = request_envelope.context.system.device.device_id return device_id except AttributeError: raise PersistenceException("Couldn't retrieve device id from " "request envelope, for partition k...
Retrieve device id from request envelope, to use as partition key. :param request_envelope: Request Envelope passed during skill invocation :type request_envelope: ask_sdk_model.RequestEnvelope :return: Device Id retrieved from request envelope :rtype: str :raises: :py:class:`ask_sdk_core.e...
def find_element(self, value, by=By.ID, update=False) -> Elements: if update or not self._nodes: self.uidump() for node in self._nodes: if node.attrib[by] == value: bounds = node.attrib['bounds'] coord = list(map(int, re.findall(r'\d+', bounds))) ...
Find a element or the first element.
def inheritance_diagram_directive(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): node = inheritance_diagram() class_names = arguments graph = InheritanceGraph(class_names) for name in graph...
Run when the inheritance_diagram directive is first encountered.
def parallel_bulk( client, actions, thread_count=4, chunk_size=500, max_chunk_bytes=100 * 1024 * 1024, queue_size=4, expand_action_callback=expand_action, *args, **kwargs ): from multiprocessing.pool import ThreadPool actions = map(expand_action_callback, actions) class B...
Parallel version of the bulk helper run in multiple threads at once. :arg client: instance of :class:`~elasticsearch.Elasticsearch` to use :arg actions: iterator containing the actions :arg thread_count: size of the threadpool to use for the bulk requests :arg chunk_size: number of docs in one chunk se...
def authorize_download(dataset_name=None): print(('Acquiring resource: ' + dataset_name)) print('') dr = data_resources[dataset_name] print('Details of data: ') print((dr['details'])) print('') if dr['citation']: print('Please cite:') print((dr['citation'])) print('')...
Check with the user that the are happy with terms and conditions for the data set.
def _setup_pyudev_monitoring(self): context = pyudev.Context() monitor = pyudev.Monitor.from_netlink(context) self.udev_observer = pyudev.MonitorObserver(monitor, self._udev_event) self.udev_observer.start() self.py3_wrapper.log("udev monitoring enabled")
Setup the udev monitor.
def process_api_config_response(self, config_json): with self._config_lock: self._add_discovery_config() for config in config_json.get('items', []): lookup_key = config.get('name', ''), config.get('version', '') self._configs[lookup_key] = config for config in self._configs.iterval...
Parses a JSON API config and registers methods for dispatch. Side effects: Parses method name, etc. for all methods and updates the indexing data structures with the information. Args: config_json: A dict, the JSON body of the getApiConfigs response.
def allow_unsigned(self, mav, msgId): if self.allow is None: self.allow = { mavutil.mavlink.MAVLINK_MSG_ID_RADIO : True, mavutil.mavlink.MAVLINK_MSG_ID_RADIO_STATUS : True } if msgId in self.allow: return True if self.settin...
see if an unsigned packet should be allowed
def read_files(*filenames): output = [] for filename in filenames: f = codecs.open(filename, encoding='utf-8') try: output.append(f.read()) finally: f.close() return '\n\n'.join(output)
Output the contents of one or more files to a single concatenated string.
def has_image(self, digest, mime_type, index, size=500): cache_key = f"img:{index}:{size}:{digest}" return mime_type.startswith("image/") or cache_key in self.cache
Tell if there is a preview image.
def fetch_user(app_id, token, ticket, url_detail='https://pswdless.appspot.com/rest/detail'): return FetchUserWithValidation(app_id, token, ticket, url_detail)
Fetch the user deatil from Passwordless
def render(self): value = self.value if value is None: value = [] fmt = [Int.fmt] data = [len(value)] for item_value in value: if issubclass(self.item_class, Primitive): item = self.item_class(item_value) else: i...
Creates a composite ``struct`` format and the data to render with it. The format and data are prefixed with a 32-bit integer denoting the number of elements, after which each of the items in the array value are ``render()``-ed and added to the format and data as well.
def get_batch_result_ids(self, job_id, batch_id): response = requests.get(self._get_batch_results_url(job_id, batch_id), headers=self._get_batch_info_headers()) response.raise_for_status() root = ET.fromstring(response.text) result_ids = [r.text for r in r...
Get result IDs of a batch that has completed processing. :param job_id: job_id as returned by 'create_operation_job(...)' :param batch_id: batch_id as returned by 'create_batch(...)' :return: list of batch result IDs to be used in 'get_batch_result(...)'
def split_by_idxs(seq, idxs): last = 0 for idx in idxs: if not (-len(seq) <= idx < len(seq)): raise KeyError(f'Idx {idx} is out-of-bounds') yield seq[last:idx] last = idx yield seq[last:]
A generator that returns sequence pieces, seperated by indexes specified in idxs.
def getModule(self, moduleName): if moduleName not in self.moduleCache: modulePath = FilePath( athena.jsDeps.getModuleForName(moduleName)._cache.path) cachedModule = self.moduleCache[moduleName] = CachedJSModule( moduleName, modulePath) else: ...
Retrieve a JavaScript module cache from the file path cache. @returns: Module cache for the named module. @rtype: L{CachedJSModule}
def update_stats_history(self): if self.get_key() is None: item_name = '' else: item_name = self.get_key() if self.get_export() and self.history_enable(): for i in self.get_items_history_list(): if isinstance(self.get_export(), list): ...
Update stats history.
def get_config_dict(self): config_dict = {} for dotted_key, value in self.get_config_values().items(): subkeys = dotted_key.split('.') d = config_dict for key in subkeys: d = d.setdefault(key, value if key == subkeys[-1] else {}) return config_...
Reconstruct the nested structure of this object's configuration and return it as a dict.
def _consume_next(self): response = six.next(self._response_iterator) self._counter += 1 if self._metadata is None: metadata = self._metadata = response.metadata source = self._source if source is not None and source._transaction_id is None: so...
Consume the next partial result set from the stream. Parse the result set into new/existing rows in :attr:`_rows`
def re_pipe(FlowRate, Diam, Nu): ut.check_range([FlowRate, ">0", "Flow rate"], [Diam, ">0", "Diameter"], [Nu, ">0", "Nu"]) return (4 * FlowRate) / (np.pi * Diam * Nu)
Return the Reynolds Number for a pipe.
def get(self, sid): return AssignedAddOnContext( self._version, account_sid=self._solution['account_sid'], resource_sid=self._solution['resource_sid'], sid=sid, )
Constructs a AssignedAddOnContext :param sid: The unique string that identifies the resource :returns: twilio.rest.api.v2010.account.incoming_phone_number.assigned_add_on.AssignedAddOnContext :rtype: twilio.rest.api.v2010.account.incoming_phone_number.assigned_add_on.AssignedAddOnContext
def get_repo_url(pypirc, repository): pypirc = os.path.abspath(os.path.expanduser(pypirc)) pypi_config = base.PyPIConfig(pypirc) repo_config = pypi_config.get_repo_config(repository) if repo_config: return repo_config.get_clean_url() else: return base.RepositoryURL(repository)
Fetch the RepositoryURL for a given repository, reading info from pypirc. Will try to find the repository in the .pypirc, including username/password. Args: pypirc (str): path to the .pypirc config file repository (str): URL or alias for the repository Returns: base.RepositoryURL ...
def get_open_spaces(board): open_spaces = [] for i in range(3): for j in range(3): if board[i][j] == 0: open_spaces.append(encode_pos(i, j)) return open_spaces
Given a representation of the board, returns a list of open spaces.
def _rebuild_fields(self): new_field_lists = [] field_list_len = self.min_elements while not field_list_len > self.max_elements: how_many = self.max_elements + 1 - field_list_len i = 0 while i < how_many: current = self.random.sample(self._fiel...
We take the original fields and create subsets of them, each subset will be set into a container. all the resulted containers will then replace the original _fields, since we inherit from OneOf each time only one of them will be mutated and used. This is super ugly and dangerous, any idea how to impleme...
def fromgroups(args): from jcvi.formats.bed import Bed p = OptionParser(fromgroups.__doc__) opts, args = p.parse_args(args) if len(args) < 2: sys.exit(not p.print_help()) groupsfile = args[0] bedfiles = args[1:] beds = [Bed(x) for x in bedfiles] fp = open(groupsfile) groups =...
%prog fromgroups groupsfile a.bed b.bed ... Flatten the gene familes into pairs, the groupsfile is a file with each line containing the members, separated by comma. The commands also require several bed files in order to sort the pairs into different piles (e.g. pairs of species in comparison.
def img2ascii(img_path, ascii_path, ascii_char="*", pad=0): if len(ascii_char) != 1: raise Exception("ascii_char has to be single character.") image = Image.open(img_path).convert("L") matrix = np.array(image) matrix[np.where(matrix >= 128)] = 255 matrix[np.where(matrix < 128)] = 0 lines...
Convert an image to ascii art text. Suppose we have an image like that: .. image:: images/rabbit.png :align: left Put some codes:: >>> from weatherlab.math.img2waveform import img2ascii >>> img2ascii(r"testdata\img2waveform\rabbit.png", ... r"testdata\img2wavef...
def find_typed_function(pytype, prefix, suffix, module=lal): laltype = to_lal_type_str(pytype) return getattr(module, '{0}{1}{2}'.format(prefix, laltype, suffix))
Returns the lal method for the correct type Parameters ---------- pytype : `type`, `numpy.dtype` the python type, or dtype, to map prefix : `str` the function name prefix (before the type tag) suffix : `str` the function name suffix (after the type tag) Raises ---...
def prepend(self, _, child, name=None): self._insert(child, prepend=True, name=name) return self
Adds childs to this tag, starting from the first position.
def from_dictionary(cls, dictionary): if not isinstance(dictionary, dict): raise TypeError('dictionary has to be a dict type, got: {}'.format(type(dictionary))) return cls(dictionary)
Parse a dictionary representing all command line parameters.
def screenshot(filename="screenshot.png"): if not settings.plotter_instance.window: colors.printc('~bomb screenshot(): Rendering window is not present, skip.', c=1) return w2if = vtk.vtkWindowToImageFilter() w2if.ShouldRerenderOff() w2if.SetInput(settings.plotter_instance.window) w2i...
Save a screenshot of the current rendering window.
def upload(config, remote_loc, u_filename): rcode = False try: sftp, transport = get_sftp_conn(config) remote_dir = get_remote_path(remote_loc) for part in ['sha1', 'asc']: local_file = '%s.%s' % (u_filename, part) remote_file = os.path.join(remote_dir, local_file...
Upload the files
def debug_callback(event, *args, **kwds): l = ['event %s' % (event.type,)] if args: l.extend(map(str, args)) if kwds: l.extend(sorted('%s=%s' % t for t in kwds.items())) print('Debug callback (%s)' % ', '.join(l))
Example callback, useful for debugging.
def interm_fluent_variables(self) -> FluentParamsList: fluents = self.domain.intermediate_fluents ordering = self.domain.interm_fluent_ordering return self._fluent_params(fluents, ordering)
Returns the instantiated intermediate fluents in canonical order. Returns: Sequence[Tuple[str, List[str]]]: A tuple of pairs of fluent name and a list of instantiated fluents represented as strings.
def parse_code(url): result = urlparse(url) query = parse_qs(result.query) return query['code']
Parse the code parameter from the a URL :param str url: URL to parse :return: code query parameter :rtype: str
def add_action_to(cls, parser, action, subactions, level): p = parser.add_parser(action.name, description=action.description, argument_default=argparse.SUPPRESS) for arg in action.args: arg.add_argument_to(p) if subactions: ...
Adds given action to given parser Args: parser: instance of devassistant_argparse.ArgumentParser action: devassistant.actions.Action subclass subactions: dict with subactions - {SubA: {SubB: {}}, SubC: {}}
def save(self, *args, **kwargs): if self.send_html: self.content = get_text_for_html(self.html_content) else: self.html_content = None super(EmailTemplate, self).save(*args, **kwargs)
If this is an HTML template, then set the non-HTML content to be the stripped version of the HTML. If this is a plain text template, then set the HTML content to be null.
def lr_find(self, start_lr=1e-5, end_lr=10, wds=None, linear=False, **kwargs): self.save('tmp') layer_opt = self.get_layer_opt(start_lr, wds) self.sched = LR_Finder(layer_opt, len(self.data.trn_dl), end_lr, linear=linear) self.fit_gen(self.model, self.data, layer_opt, 1, **kwargs) ...
Helps you find an optimal learning rate for a model. It uses the technique developed in the 2015 paper `Cyclical Learning Rates for Training Neural Networks`, where we simply keep increasing the learning rate from a very small value, until the loss starts decreasing. Args: ...
def _compute_gas_price(probabilities, desired_probability): first = probabilities[0] last = probabilities[-1] if desired_probability >= first.prob: return int(first.gas_price) elif desired_probability <= last.prob: return int(last.gas_price) for left, right in sliding_window(2, proba...
Given a sorted range of ``Probability`` named-tuples returns a gas price computed based on where the ``desired_probability`` would fall within the range. :param probabilities: An iterable of `Probability` named-tuples sorted in reverse order. :param desired_probability: An floating point representation...
def add_exception_handler(self, exception_handler): if exception_handler is None or not isinstance( exception_handler, AbstractExceptionHandler): raise DispatchException( "Input is not an AbstractExceptionHandler instance") self._exception_handlers.append(exce...
Checks the type before adding it to the exception_handlers instance variable. :param exception_handler: Exception Handler instance. :type exception_handler: ask_sdk_runtime.dispatch_components.exception_components.AbstractExceptionHandler :raises: :py:class:`ask_sdk_runtime.exceptions.D...
def week(self): self.magnification = 345600 self._update(self.baseNumber, self.magnification) return self
set unit to week
def make_random_client_id(self): if PY2: return ('py_%s' % base64.b64encode(str(random.randint(1, 0x40000000)))) else: return ('py_%s' % base64.b64encode(bytes(str(random.randint(1, 0x40000000)), 'ascii'...
Returns a random client identifier
def _get_fct_number_of_arg(self, fct): py_version = sys.version_info[0] if py_version >= 3: return len(inspect.signature(fct).parameters) return len(inspect.getargspec(fct)[0])
Get the number of argument of a fuction.
def message(blockers): if not blockers: encoding = getattr(sys.stdout, 'encoding', '') if encoding: encoding = encoding.lower() if encoding == 'utf-8': flair = "\U0001F389 " else: flair = '' return [flair + 'You have 0 proj...
Create a sequence of key messages based on what is blocking.
def to_json(self): sets = self.sets() return sorted(sorted(x) for x in sets)
Returns the equivalence classes a sorted list of sorted lists.
def configure(self, config): self.config = config self.update_monitors() for profile in ('worker', 'result'): for _ in range(config['threads'][profile]['number']): worker = threading.Thread(target=config['threads'][profile]['function']) worker.daemon =...
Configure Monitor, pull list of what to monitor, initialize threads
def prepare_uuid(data, schema): if isinstance(data, uuid.UUID): return str(data) else: return data
Converts uuid.UUID to string formatted UUID xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
def profile_add(user, profile): ret = {} profiles = profile.split(',') known_profiles = profile_list().keys() valid_profiles = [p for p in profiles if p in known_profiles] log.debug( 'rbac.profile_add - profiles=%s, known_profiles=%s, valid_profiles=%s', profiles, known_profi...
Add profile to user user : string username profile : string profile name CLI Example: .. code-block:: bash salt '*' rbac.profile_add martine 'Primary Administrator' salt '*' rbac.profile_add martine 'User Management,User Security'
def withSize(cls, minimum, maximum): class X(cls): subtypeSpec = cls.subtypeSpec + constraint.ValueSizeConstraint( minimum, maximum) X.__name__ = cls.__name__ return X
Creates a subclass with value size constraint.
def supports_caller(func): def wrap_stackframe(context, *args, **kwargs): context.caller_stack._push_frame() try: return func(context, *args, **kwargs) finally: context.caller_stack._pop_frame() return wrap_stackframe
Apply a caller_stack compatibility decorator to a plain Python function. See the example in :ref:`namespaces_python_modules`.
def ic_pos(self, row1, row2=None): if row2 is None: row2 = [0.25,0.25,0.25,0.25] score = 0 for a,b in zip(row1, row2): if a > 0: score += a * log(a / b) / log(2) return score
Calculate the information content of one position. Returns ------- score : float Information content.
def get_app_state(device_id, app_id): if not is_valid_app_id(app_id): abort(403) if not is_valid_device_id(device_id): abort(403) if device_id not in devices: abort(404) app_state = devices[device_id].app_state(app_id) return jsonify(state=app_state, status=app_state)
Get the state of the requested app
def strip_non_ascii(s): stripped = (c for c in s if 0 < ord(c) < 127) clean_string = u''.join(stripped) return clean_string
Returns the string without non-ASCII characters. Parameters ---------- string : string A string that may contain non-ASCII characters. Returns ------- clean_string : string A string that does not contain non-ASCII characters.
def get_app(): from bottle import default_app default_app.push() for module in ("mongo_orchestration.apps.servers", "mongo_orchestration.apps.replica_sets", "mongo_orchestration.apps.sharded_clusters"): __import__(module) app = default_app.pop() return a...
return bottle app that includes all sub-apps
def get_event_string(self, evtype, code): if WIN and evtype == 'Key': try: code = self.codes['wincodes'][code] except KeyError: pass try: return self.codes[evtype][code] except KeyError: raise UnknownEventCode("We do...
Get the string name of the event.
def parse(self, requires_cfg=True): self._parse_default() self._parse_config(requires_cfg) self._parse_env()
Parse the configuration sources into `Bison`. Args: requires_cfg (bool): Specify whether or not parsing should fail if a config file is not found. (default: True)
def num_fails(self): n = len(self.failed_phase_list) if self.phase_stack[-1].status in (SolverStatus.failed, SolverStatus.cyclic): n += 1 return n
Return the number of failed solve steps that have been executed. Note that num_solves is inclusive of failures.
def download(self): return self._client.download_object( self._instance, self._bucket, self.name)
Download this object.
def getActiveSegment(self, c, i, timeStep): nSegments = len(self.cells[c][i]) bestActivation = self.activationThreshold which = -1 for j,s in enumerate(self.cells[c][i]): activity = self.getSegmentActivityLevel(s, self.activeState[timeStep], connectedSynapsesOnly = True) if activity >= bestA...
For a given cell, return the segment with the strongest _connected_ activation, i.e. sum up the activations of the connected synapses of the segments only. That is, a segment is active only if it has enough connected synapses.
def replace(self, new): assert self.parent is not None, str(self) assert new is not None if not isinstance(new, list): new = [new] l_children = [] found = False for ch in self.parent.children: if ch is self: assert not found, (self....
Replace this node with a new one in the parent.
def block_offset_bounds(self, namespace): cursor = self.cursor cursor.execute('SELECT MIN("offset"), MAX("offset") ' 'FROM gauged_statistics WHERE namespace = %s', (namespace,)) return cursor.fetchone()
Get the minimum and maximum block offset for the specified namespace
def PostRegistration(method): if not isinstance(method, types.FunctionType): raise TypeError("@PostRegistration can only be applied on functions") validate_method_arity(method, "service_reference") _append_object_entry( method, constants.IPOPO_METHOD_CALLBACKS, constants.IPOP...
The service post-registration callback decorator is called after a service of the component has been registered to the framework. The decorated method must accept the :class:`~pelix.framework.ServiceReference` of the registered service as argument:: @PostRegistration def callback_method(...
def _prepare_statement(sql_statement, parameters): placehoolders = RdbmsConnection._get_placeholders(sql_statement, parameters) for (variable_name, (variable_type, variable_value)) in placehoolders.iteritems(): if isinstance(variable_value, (list, set, tuple)): sql_statement ...
Prepare the specified SQL statement, replacing the placeholders by the value of the given parameters @param sql_statement: the string expression of a SQL statement. @param parameters: a dictionary of parameters where the key represents the name of a parameter and the value represen...
def rsync_upload(): excludes = ["*.pyc", "*.pyo", "*.db", ".DS_Store", ".coverage", "local_settings.py", "/static", "/.git", "/.hg"] local_dir = os.getcwd() + os.sep return rsync_project(remote_dir=env.proj_path, local_dir=local_dir, exclude=excludes)
Uploads the project with rsync excluding some files and folders.
def _dasd_reverse_conversion(cls, val, **kwargs): if val is not None: if val.upper() == 'ADMINISTRATORS': return '0' elif val.upper() == 'ADMINISTRATORS AND POWER USERS': return '1' elif val.upper() == 'ADMINISTRATORS AND INTERACTIVE USERS': ...
converts DASD String values to the reg_sz value
def add_general_report_optgroup(parser): g = parser.add_argument_group("Reporting Options") g.add_argument("--report-dir", action="store", default=None) g.add_argument("--report", action=_opt_cb_report, help="comma-separated list of report formats")
General Reporting Options
def file_list(self, load): if 'env' in load: load.pop('env') ret = set() if 'saltenv' not in load: return [] if not isinstance(load['saltenv'], six.string_types): load['saltenv'] = six.text_type(load['saltenv']) for fsb in self.backends(load.po...
Return a list of files from the dominant environment
def syscall_from_number(self, number, allow_unsupported=True, abi=None): abilist = self.syscall_abis if abi is None else [abi] if self.syscall_library is None: if not allow_unsupported: raise AngrUnsupportedSyscallError("%s does not have a library of syscalls implemented" % s...
Get a syscall SimProcedure from its number. :param number: The syscall number :param allow_unsupported: Whether to return a "stub" syscall for unsupported numbers instead of throwing an error :param abi: The name of the abi to use. If None, will assume that the ab...
def on_batch_end(self, train, **kwargs:Any)->None: "Take one step forward on the annealing schedule for the optim params." if train: if self.idx_s >= len(self.lr_scheds): return {'stop_training': True, 'stop_epoch': True} self.opt.lr = self.lr_scheds[self.idx_s].step() ...
Take one step forward on the annealing schedule for the optim params.
def field_value(key, label, color, padding): if not clr.has_colors and padding > 0: padding = 7 if color == "bright gray" or color == "dark gray": bright_prefix = "" else: bright_prefix = "bright " field = clr.stringc(key, "{0}{1}".format(bright_prefix, color)) field_label = ...
Print a specific field's stats.
def sys_version(version_tuple): old_version = sys.version_info sys.version_info = version_tuple yield sys.version_info = old_version
Set a temporary sys.version_info tuple :param version_tuple: a fake sys.version_info tuple
def _GenerateSection(self, problem_type): if problem_type == transitfeed.TYPE_WARNING: dataset_problems = self._dataset_warnings heading = 'Warnings' else: dataset_problems = self._dataset_errors heading = 'Errors' if not dataset_problems: return '' prefix = '<h2 class="iss...
Generate a listing of the given type of problems. Args: problem_type: The type of problem. This is one of the problem type constants from transitfeed. Returns: The generated HTML as a string.
def is_link_inline(cls, tag, attribute): if tag in cls.TAG_ATTRIBUTES \ and attribute in cls.TAG_ATTRIBUTES[tag]: attr_flags = cls.TAG_ATTRIBUTES[tag][attribute] return attr_flags & cls.ATTR_INLINE return attribute != 'href'
Return whether the link is likely to be inline object.
def infer_doy_max(arr): cal = arr.time.encoding.get('calendar', None) if cal in calendars: doy_max = calendars[cal] else: doy_max = arr.time.dt.dayofyear.max().data if len(arr.time) < 360: raise ValueError("Cannot infer the calendar from a series less than a year long.") ...
Return the largest doy allowed by calendar. Parameters ---------- arr : xarray.DataArray Array with `time` coordinate. Returns ------- int The largest day of the year found in calendar.
def manager(self, value): "Set the manager object in the global _managers dict." pid = current_process().ident if _managers is None: raise RuntimeError("Can not set the manager following a system exit.") if pid not in _managers: _managers[pid] = value else...
Set the manager object in the global _managers dict.
def read_json(self, xblock): self._warn_deprecated_outside_JSONField() return self.to_json(self.read_from(xblock))
Retrieve the serialized value for this field from the specified xblock
def privmsg_many(self, targets, text): target = ','.join(targets) return self.privmsg(target, text)
Send a PRIVMSG command to multiple targets.
def ncores_allocated(self): return sum(task.manager.num_cores for task in self if task.status in [task.S_SUB, task.S_RUN])
Returns the number of CPUs allocated in this moment. A core is allocated if it's running a task or if we have submitted a task to the queue manager but the job is still pending.
def search(self, query, pagination, result_field): result = [] url = "/".join((self.url, query)) while url: log.debug("Pagure query: {0}".format(url)) try: response = requests.get(url, headers=self.headers) log.data("Response headers:\n{0}"...
Perform Pagure query
def get_requires(): requirements = open("requirements.txt", "r").read() return list(filter(lambda x: x != "", requirements.split()))
Read requirements.txt.
def is_image(file): match = re.match(r'\.(png|jpe?g)', _get_extension(file), re.IGNORECASE) if match: return True else: return isinstance(resolve_bot_file_id(file), types.Photo)
Returns ``True`` if the file extension looks like an image file to Telegram.
def profile_list(default_only=False): profiles = {} default_profiles = ['All'] with salt.utils.files.fopen('/etc/security/policy.conf', 'r') as policy_conf: for policy in policy_conf: policy = salt.utils.stringutils.to_unicode(policy) policy = policy.split('=') if...
List all available profiles default_only : boolean return only default profile CLI Example: .. code-block:: bash salt '*' rbac.profile_list
def connect(self, receiver): if not callable(receiver): raise ValueError('Invalid receiver: %s' % receiver) self.receivers.append(receiver)
Append receiver.
def compute_grouped_sigma(ungrouped_sigma, group_matrix): group_matrix = np.array(group_matrix, dtype=np.bool) sigma_masked = np.ma.masked_array(ungrouped_sigma * group_matrix.T, mask=(group_matrix ^ 1).T) sigma_agg = np.ma.mean(sigma_masked, axis=1) sigma = np.zero...
Returns sigma for the groups of parameter values in the argument ungrouped_metric where the group consists of no more than one parameter
def version_info(self): package = pkg.get_distribution('git-up') local_version_str = package.version local_version = package.parsed_version print('GitUp version is: ' + colored('v' + local_version_str, 'green')) if not self.settings['updates.check']: return ...
Tell, what version we're running at and if it's up to date.
def create_environment(self, **kwargs): environment = super().create_environment(**kwargs) environment.tests.update({ 'type': self.test_type, 'kind': self.test_kind, 'opposite_before_self': self.test_opposite_before_self, }) environment.filters.update(...
Return a new Jinja environment. Derived classes may override method to pass additional parameters or to change the template loader type.
def files_type(fs0, fs1, files): for file_meta in files['deleted_files']: file_meta['type'] = fs0.file(file_meta['path']) for file_meta in files['created_files'] + files['modified_files']: file_meta['type'] = fs1.file(file_meta['path']) return files
Inspects the file type of the given files.