code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def _reduce(self, op, name, axis=0, skipna=True, numeric_only=None, filter_type=None, **kwds): delegate = self._values if axis is not None: self._get_axis_number(axis) if isinstance(delegate, Categorical): return delegate._reduce(name, numeric_only=numeric...
Perform a reduction operation. If we have an ndarray as a value, then simply perform the operation, otherwise delegate to the object.
def distance(self, method='haversine'): distances = [] for segment in self: if len(segment) < 2: distances.append([]) else: distances.append(segment.distance(method)) return distances
Calculate distances between locations in segments. Args: method (str): Method used to calculate distance Returns: list of list of float: Groups of distance between points in segments
def verifyUniqueWcsname(fname,wcsname): uniq = True numsci,extname = count_sci_extensions(fname) wnames = altwcs.wcsnames(fname,ext=(extname,1)) if wcsname in wnames.values(): uniq = False return uniq
Report whether or not the specified WCSNAME already exists in the file
def fastq_convert_pipe_cl(in_file, data): cmd = _seqtk_fastq_prep_cl(data, in_file) if not cmd: cat_cmd = "zcat" if in_file.endswith(".gz") else "cat" cmd = cat_cmd + " " + in_file return "<(%s)" % cmd
Create an anonymous pipe converting Illumina 1.3-1.7 to Sanger. Uses seqtk: https://github.com/lh3/seqt
def safe_temp_edit(filename): with temporary_file() as tmp_file: try: shutil.copyfile(filename, tmp_file.name) yield filename finally: shutil.copyfile(tmp_file.name, filename)
Safely modify a file within context that automatically reverts any changes afterwards The file mutatation occurs in place. The file is backed up in a temporary file before edits occur and when the context is closed, the mutated file is discarded and replaced with the backup. WARNING: There may be a chance that ...
def ylogydu(y, u): mask = (np.atleast_1d(y)!=0.) out = np.zeros_like(u) out[mask] = y[mask] * np.log(y[mask] / u[mask]) return out
tool to give desired output for the limit as y -> 0, which is 0 Parameters ---------- y : array-like of len(n) u : array-like of len(n) Returns ------- np.array len(n)
def steal(self, instr): instr._stolen_by = self for jmp in instr._target_of: jmp.arg = self self._target_of = instr._target_of instr._target_of = set() return self
Steal the jump index off of `instr`. This makes anything that would have jumped to `instr` jump to this Instruction instead. Parameters ---------- instr : Instruction The instruction to steal the jump sources from. Returns ------- self : Ins...
def _runOPF(self): if self.decommit: solver = UDOPF(self.case, dc=(self.locationalAdjustment == "dc")) elif self.locationalAdjustment == "dc": solver = OPF(self.case, dc=True) else: solver = OPF(self.case, dc=False, opt={"verbose": True}) self._solutio...
Computes dispatch points and LMPs using OPF.
def rectangle(self): if self.start_point is None or self.end_point is None: return QgsRectangle() elif self.start_point.x() == self.end_point.x() or \ self.start_point.y() == self.end_point.y(): return QgsRectangle() return QgsRectangle(self.start_point, s...
Accessor for the rectangle. :return: A rectangle showing the designed extent. :rtype: QgsRectangle
def contains_container(self, path): path = make_path(path) try: self.get_container(path) return True except KeyError: return False
Returns True if a container exists at the specified path, otherwise False. :param path: str or Path instance :return: :rtype: bool :raises ValueError: A component of path is a field name.
def abi_splitext(filename): filename = os.path.basename(filename) is_ncfile = False if filename.endswith(".nc"): is_ncfile = True filename = filename[:-3] known_extensions = abi_extensions() for i in range(len(filename)-1, -1, -1): ext = filename[i:] if ext in known_e...
Split the ABINIT extension from a filename. "Extension" are found by searching in an internal database. Returns "(root, ext)" where ext is the registered ABINIT extension The final ".nc" is included (if any) >>> assert abi_splitext("foo_WFK") == ('foo_', 'WFK') >>> assert abi_splitext("/home/guido...
def setup(): global _displayhooks, _excepthooks if _displayhooks is not None: return _displayhooks = [] _excepthooks = [] if sys.displayhook != sys.__displayhook__: _displayhooks.append(weakref.ref(sys.displayhook)) if sys.excepthook != sys.__excepthook__: _excepthooks.ap...
Initializes the hook queues for the sys module. This method will automatically be called on the first registration for a hook to the system by either the registerDisplay or registerExcept functions.
def _add_edge(self, source, target, **kwargs): edge_properties = self.edge_properties for k, v in kwargs.items(): edge_properties[k] = v self.graph.add_edge(source, target, **edge_properties)
Add an edge to the graph.
def getDayStart(self, dateTime): return ensure_localtime(dateTime).replace(hour=0,minute=0,second=0,microsecond=0)
Ensure local time and get the beginning of the day
def configure(self, settings_module=None, **kwargs): default_settings.reload() environment_var = self._kwargs.get( "ENVVAR_FOR_DYNACONF", default_settings.ENVVAR_FOR_DYNACONF ) settings_module = settings_module or os.environ.get(environment_var) compat_kwargs(kwargs) ...
Allows user to reconfigure settings object passing a new settings module or separated kwargs :param settings_module: defines the setttings file :param kwargs: override default settings
def fetch_alien(self, ): parent = self.get_parent() if parent: parentelement = parent.get_element() else: parentelement = self.get_refobjinter().get_current_element() if not parentelement: self._alien = True return self._alien ...
Set and return, if the reftrack element is linked to the current scene. Askes the refobj interface for the current scene. If there is no current scene then True is returned. :returns: whether the element is linked to the current scene :rtype: bool :raises: None
def get(self, instance_name): url = self._url + instance_name + '/' response = requests.get(url, **self._default_request_kwargs) data = self._get_response_data(response) return self._concrete_instance(data)
Get an ObjectRocket instance by name. :param str instance_name: The name of the instance to retrieve. :returns: A subclass of :py:class:`bases.BaseInstance`, or None if instance does not exist. :rtype: :py:class:`bases.BaseInstance`
def encrypt(self, pubkey: str, nonce: Union[str, bytes], text: Union[str, bytes]) -> str: text_bytes = ensure_bytes(text) nonce_bytes = ensure_bytes(nonce) recipient_pubkey = PublicKey(pubkey) crypt_bytes = libnacl.public.Box(self, recipient_pubkey).encrypt(text_bytes, nonce_bytes) ...
Encrypt message text with the public key of the recipient and a nonce The nonce must be a 24 character string (you can use libnacl.utils.rand_nonce() to get one) and unique for each encrypted message. Return base58 encoded encrypted message :param pubkey: Base58 encoded public key of ...
def reverse_point(self, latitude, longitude, **kwargs): fields = ",".join(kwargs.pop("fields", [])) point_param = "{0},{1}".format(latitude, longitude) response = self._req( verb="reverse", params={"q": point_param, "fields": fields} ) if response.status_code != 200: ...
Method for identifying an address from a geographic point
def count_relations(graph) -> Counter: return Counter( data[RELATION] for _, _, data in graph.edges(data=True) )
Return a histogram over all relationships in a graph. :param pybel.BELGraph graph: A BEL graph :return: A Counter from {relation type: frequency}
def lookup_deleted_folder(event, filesystem, journal): folder_events = (e for e in journal[event.parent_inode] if 'DIRECTORY' in e.attributes and 'FILE_DELETE' in e.changes) for folder_event in folder_events: path = lookup_deleted_folder(folder_event, filesystem...
Lookup the parent folder in the journal content.
def _attributeStr(self, name): return "{}={}".format( _encodeAttr(name), ",".join([_encodeAttr(v) for v in self.attributes[name]]))
Return name=value for a single attribute
def play(cls, file_path, on_done=None, logger=None): pygame.mixer.init() try: pygame.mixer.music.load(file_path) except pygame.error as e: if logger is not None: logger.warning(str(e)) return pygame.mixer.music.play() while pyga...
Play an audio file. :param file_path: the path to the file to play. :param on_done: callback when audio playback completes.
def dAbr_dV(dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, Sf, St): dAf_dPf = spdiag(2 * Sf.real()) dAf_dQf = spdiag(2 * Sf.imag()) dAt_dPt = spdiag(2 * St.real()) dAt_dQt = spdiag(2 * St.imag()) dAf_dVa = dAf_dPf * dSf_dVa.real() + dAf_dQf * dSf_dVa.imag() dAt_dVa = dAt_dPt * dSt_dVa.real() + dAt_dQt * dS...
Partial derivatives of squared flow magnitudes w.r.t voltage. Computes partial derivatives of apparent power w.r.t active and reactive power flows. Partial derivative must equal 1 for lines with zero flow to avoid division by zero errors (1 comes from L'Hopital).
def get(self, path, params=None): r = requests.get(url=self.url + path, params=params, timeout=self.timeout) r.raise_for_status() return r.json()
Perform GET request
def block(self): if (self.is_actinoid or self.is_lanthanoid) and self.Z not in [71, 103]: return "f" elif self.is_actinoid or self.is_lanthanoid: return "d" elif self.group in [1, 2]: return "s" elif self.group in range(13, 19): return "p" ...
Return the block character "s,p,d,f"
def detect_timezone(): if sys.platform == "win32": tz = _detect_timezone_windows() if tz is not None: return tz tz = _detect_timezone_environ() if tz is not None: return tz tz = _detect_timezone_etc_timezone() if tz is not None: return tz tz = _detect_timezone_etc_localtime() if tz i...
Try and detect the timezone that Python is currently running in. We have a bunch of different methods for trying to figure this out (listed in order they are attempted). * In windows, use win32timezone.TimeZoneInfo.local() * Try TZ environment variable. * Try and find /etc/timezone file (with timezone ...
def loadImageData(filename, spacing=()): if not os.path.isfile(filename): colors.printc("~noentry File not found:", filename, c=1) return None if ".tif" in filename.lower(): reader = vtk.vtkTIFFReader() elif ".slc" in filename.lower(): reader = vtk.vtkSLCReader() if n...
Read and return a ``vtkImageData`` object from file.
def get_avatar_metadata(self, jid, *, require_fresh=False, disable_pep=False): if require_fresh: self._metadata_cache.pop(jid, None) else: try: return self._metadata_cache[jid] except KeyError: pass i...
Retrieve a list of avatar descriptors. :param jid: the JID for which to retrieve the avatar metadata. :type jid: :class:`aioxmpp.JID` :param require_fresh: if true, do not return results from the avatar metadata chache, but retrieve them again from the server. :type require_...
def is_unclaimed(work): if work['is_completed']: return False cutoff_time = time.time() - MAX_PROCESSING_TIME if (work['claimed_worker_id'] and work['claimed_worker_start_time'] is not None and work['claimed_worker_start_time'] >= cutoff_time): return False return True
Returns True if work piece is unclaimed.
def smart_reroot(treefile, outgroupfile, outfile, format=0): tree = Tree(treefile, format=format) leaves = [t.name for t in tree.get_leaves()][::-1] outgroup = [] for o in must_open(outgroupfile): o = o.strip() for leaf in leaves: if leaf[:len(o)] == o: outgro...
simple function to reroot Newick format tree using ete2 Tree reading format options see here: http://packages.python.org/ete2/tutorial/tutorial_trees.html#reading-newick-trees
def start_cluster_server(self, num_gpus=1, rdma=False): return TFNode.start_cluster_server(self, num_gpus, rdma)
Convenience function to access ``TFNode.start_cluster_server`` directly from this object instance.
def tkvrsn(item): item = stypes.stringToCharP(item) return stypes.toPythonString(libspice.tkvrsn_c(item))
Given an item such as the Toolkit or an entry point name, return the latest version string. http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/tkvrsn_c.html :param item: Item for which a version string is desired. :type item: str :return: the latest version string. :rtype: str
def _load_image(cls, rkey): v = cls._stock[rkey] img = None itype = v['type'] if itype in ('stock', 'data'): img = tk.PhotoImage(format=v['format'], data=v['data']) elif itype == 'created': img = v['image'] else: img = tk.PhotoImage(fil...
Load image from file or return the cached instance.
def get_data(self): "Return one SNMP response list for all status OIDs, and one list for all metric OIDs." alarm_oids = [netsnmp.Varbind(status_mib[alarm_id]['oid']) for alarm_id in self.models[self.modem_type]['alarms']] metric_oids = [netsnmp.Varbind(metric_mib[metric_id]['oid']) for metric_id...
Return one SNMP response list for all status OIDs, and one list for all metric OIDs.
def get_bookmarks(self, folder='unread', limit=25, have=None): path = 'bookmarks/list' params = {'folder_id': folder, 'limit': limit} if have: have_concat = ','.join(str(id_) for id_ in have) params['have'] = have_concat response = self.request(path, params) ...
Return list of user's bookmarks. :param str folder: Optional. Possible values are unread (default), starred, archive, or a folder_id value. :param int limit: Optional. A number between 1 and 500, default 25. :param list have: Optional. A list of IDs to exclude from results :...
def exists(name, region=None, key=None, keyid=None, profile=None): conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile) try: exists = conn.describe_stacks(name) log.debug('Stack %s exists.', name) return True except BotoServerError as e: log.debug('boto_cfn....
Check to see if a stack exists. CLI Example: .. code-block:: bash salt myminion boto_cfn.exists mystack region=us-east-1
def build_groups(self, tokens): groups = {} for token in tokens: match_type = MatchType.start if token.group_end else MatchType.single groups[token.group_start] = (token, match_type) if token.group_end: groups[token.group_end] = (token, MatchType.end) ...
Build dict of groups from list of tokens
def find_files(self): all_files = self._invoke('locate', '-I', '.').splitlines() from_root = os.path.relpath(self.location, self.find_root()) loc_rel_paths = [ os.path.relpath(path, from_root) for path in all_files] return loc_rel_paths
Find versioned files in self.location
def parse_magmoms(self, data, lattice=None): if lattice is None: raise Exception( 'Magmoms given in terms of crystal axes in magCIF spec.') try: magmoms = { data["_atom_site_moment_label"][i]: np.array( [...
Parse atomic magnetic moments from data dictionary
def data_url(self, image_format='png', add_quiet_zone=True): memory_file = io.BytesIO() pil_image = self.image(add_quiet_zone=add_quiet_zone) if image_format == 'png': pil_image.save(memory_file, format='png', compress_level=1) elif image_format == 'bmp': pil_imag...
Get a data URL representing the barcode. >>> barcode = Code128('Hello!', charset='B') >>> barcode.data_url() # doctest: +ELLIPSIS 'data:image/png;base64,...' :param image_format: Either 'png' or 'bmp'. :param add_quiet_zone: Add a 10 white pixels on either side of the barcode....
def app_score(self): precisions, pct_pred_pos, taus = self.precision_pct_pred_pos_curve(interval=False) app = 0 total = 0 for k in range(len(precisions)-1): cur_prec = precisions[k] cur_pp = pct_pred_pos[k] cur_tau = taus[k] next_prec = pre...
Computes the area under the app curve.
def load_all_yamls(cls, directories): yaml_files = [] loaded_yamls = {} for d in directories: if d.startswith('/home') and not os.path.exists(d): os.makedirs(d) for dirname, subdirs, files in os.walk(d): yaml_files.extend(map(lambda x: os.p...
Loads yaml files from all given directories. Args: directories: list of directories to search Returns: dict of {fullpath: loaded_yaml_structure}
def is_client(self): return (self.args.client or self.args.browser) and not self.args.server
Return True if Glances is running in client mode.
def count_lines(fname, mode='rU'): with open(fname, mode) as f: for i, l in enumerate(f): pass return i + 1
Count the number of lines in a file Only faster way would be to utilize multiple processor cores to perform parallel reads. http://stackoverflow.com/q/845058/623735
def timeit(method): import datetime @functools.wraps(method) def timed_method(self, rinput): time_start = datetime.datetime.utcnow() result = method(self, rinput) time_end = datetime.datetime.utcnow() result.time_it(time_start, time_end) self.logger.info('total time m...
Decorator to measure the time used by the recipe
def all(): return [goal for _, goal in sorted(Goal._goal_by_name.items()) if goal.active]
Returns all active registered goals, sorted alphabetically by name. :API: public
def url_to_image(url, flag=cv2.IMREAD_COLOR): resp = urlopen(url) image = np.asarray(bytearray(resp.read()), dtype="uint8") image = cv2.imdecode(image, flag) return image
download the image, convert it to a NumPy array, and then read it into OpenCV format
def _reset_suffix_links(self): self._suffix_links_set = False for current, _parent in self.dfs(): current.suffix = None current.dict_suffix = None current.longest_prefix = None
Reset all suffix links in all nodes in this trie.
def edit_dataset_metadata(request, dataset_id=None): if request.method == 'POST': return add_dataset(request, dataset_id) elif request.method == 'GET': if dataset_id: metadata_form = DatasetUploadForm( instance=get_object_or_404(Dataset, pk=dataset_id) ) ...
Renders a template to upload or edit a Dataset. Most of the heavy lifting is done by add_dataset(...).
def rssi_bars(self) -> int: rssi_db = self.rssi_db if rssi_db < 45: return 0 elif rssi_db < 60: return 1 elif rssi_db < 75: return 2 elif rssi_db < 90: return 3 return 4
Received Signal Strength Indication, from 0 to 4 bars.
def add_feature(feature, package=None, source=None, limit_access=False, enable_parent=False, image=None, restart=False): cmd = ['DISM', '/Quiet', '/Image:{0}'.format(image) if image else '/Online', ...
Install a feature using DISM Args: feature (str): The feature to install package (Optional[str]): The parent package for the feature. You do not have to specify the package if it is the Windows Foundation Package. Otherwise, use package to specify the parent package of the f...
def sort(self, key, reverse=False, none_greater=False): for i in range(0, len(self.table)): min = i for j in range(i + 1, len(self.table)): if internal.is_first_lessor(self.table[j], self.table[min], key, none_greater=none_greater, reverse=reverse): mi...
Sort the list in the order of the dictionary key. Example of use: >>> test = [ ... {"name": "Jim", "age": 18, "income": 93000, "wigs": 68 }, ... {"name": "Larry", "age": 18, "wigs": [3, 2, 9]}, ... {"name": "Joe", "age": 20, "income": 15000, ...
def gammaVectorRDD(sc, shape, scale, numRows, numCols, numPartitions=None, seed=None): return callMLlibFunc("gammaVectorRDD", sc._jsc, float(shape), float(scale), numRows, numCols, numPartitions, seed)
Generates an RDD comprised of vectors containing i.i.d. samples drawn from the Gamma distribution. :param sc: SparkContext used to create the RDD. :param shape: Shape (> 0) of the Gamma distribution :param scale: Scale (> 0) of the Gamma distribution :param numRows: Number of Ve...
def unicode_urlencode(query, doseq=True): pairs = [] for key, value in query.items(): if isinstance(value, list): value = list(map(to_utf8, value)) else: value = to_utf8(value) pairs.append((to_utf8(key), value)) encoded_query = dict(pairs) xx = urlencode(...
Custom wrapper around urlencode to support unicode Python urlencode doesn't handle unicode well so we need to convert to bytestrings before using it: http://stackoverflow.com/questions/6480723/urllib-urlencode-doesnt-like-unicode-values-how-about-this-workaround
def append_sint32(self, value): zigzag_value = wire_format.zig_zag_encode(value) self._stream.append_var_uint32(zigzag_value)
Appends a 32-bit integer to our buffer, zigzag-encoded and then varint-encoded.
def describe_cache_parameters(name=None, conn=None, region=None, key=None, keyid=None, profile=None, **args): ret = {} generic = _describe_resource(name=name, name_param='CacheParameterGroupName', res_type='cache_parameter', info_node='Parameters',...
Returns the detailed parameter list for a particular cache parameter group. name The name of a specific cache parameter group to return details for. CacheParameterGroupName The name of a specific cache parameter group to return details for. Generally not required, as `name` will be us...
def fetch_data(self): choices = self.available_data choices.insert(0, 'All') selected_data_type = utils.select_item( choices, 'Please select what data to fetch:', 'Available data:', ) if selected_data_type == 'All': selected_data_ty...
Prompt for a data type choice and execute the `fetch_data` task. The results are saved to a file in json format.
def Unequal(*xs, simplify=True): xs = [Expression.box(x).node for x in xs] y = exprnode.not_(exprnode.eq(*xs)) if simplify: y = y.simplify() return _expr(y)
Expression inequality operator If *simplify* is ``True``, return a simplified expression.
def _encode_dict_as_string(value): if value.startswith("{\n"): value = "{" + value[2:] if value.endswith("\n}"): value = value[:-2] + "}" return value.replace('"', '\\"').replace("\\n", "\\\\n").replace("\n", "\\n")
Takes the PLIST string of a dict, and returns the same string encoded such that it can be included in the string representation of a GSNode.
def handle_login_failure(self, provider, reason): logger.error('Authenication Failure: {0}'.format(reason)) messages.error(self.request, 'Authenication Failed. Please try again') return redirect(self.get_error_redirect(provider, reason))
Message user and redirect on error.
def update(self, cont): self.max_time = max(self.max_time, cont.max_time) if cont.items is not None: if self.items is None: self.items = cont.items else: self.items.update(cont.items)
Update this instance with the contextualize passed.
def reverse_iter(self, start=None, stop=None, count=2000): cursor = '0' count = 1000 start = start if start is not None else (-1 * count) stop = stop if stop is not None else -1 _loads = self._loads while cursor: cursor = self._client.lrange(self.key_prefix, s...
-> yields items of the list in reverse
def make_query(self, **kw): query = kw.pop("query", {}) query.update(self.get_request_query()) query.update(self.get_custom_query()) query.update(self.get_keyword_query(**kw)) sort_on, sort_order = self.get_sort_spec() if sort_on and "sort_on" not in query: qu...
create a query suitable for the catalog
def load_config_from_cli_arguments(self, *args, **kwargs): self._load_config_from_cli_argument(key='handlers_package', **kwargs) self._load_config_from_cli_argument(key='auth', **kwargs) self._load_config_from_cli_argument(key='user_stream', **kwargs) self._load_config_from_cli_argument(...
Get config values of passed in CLI options. :param dict kwargs: CLI options
def _save(self, name, content): name = self.clean_name(name) if not self._exists_with_etag(name, content): content.seek(0) super(StaticCloudinaryStorage, self)._save(name, content) return self._prepend_prefix(name)
Saves only when a file with a name and a content is not already uploaded to Cloudinary.
def list_clusters(kwargs=None, call=None): if call != 'function': raise SaltCloudSystemExit( 'The list_clusters function must be called with ' '-f or --function.' ) return {'Clusters': salt.utils.vmware.list_clusters(_get_si())}
List all the clusters for this VMware environment CLI Example: .. code-block:: bash salt-cloud -f list_clusters my-vmware-config
def numeric(self, code, padded=False): code = self.alpha2(code) try: num = self.alt_codes[code][1] except KeyError: return None if padded: return "%03d" % num return num
Return the ISO 3166-1 numeric country code matching the provided country code. If no match is found, returns ``None``. :param padded: Pass ``True`` to return a 0-padded three character string, otherwise an integer will be returned.
def contracts_source_path_with_stem(stem): return { 'lib': _BASE.joinpath(stem, 'lib'), 'raiden': _BASE.joinpath(stem, 'raiden'), 'test': _BASE.joinpath(stem, 'test'), 'services': _BASE.joinpath(stem, 'services'), }
The directory remapping given to the Solidity compiler.
def load_image(name): image = pyglet.image.load(name).texture verify_dimensions(image) return image
Load an image
def get_mapping_format(self): if self.format == DataFormat.json or self.format == DataFormat.avro: return self.format.name else: return DataFormat.csv.name
Dictating the corresponding mapping to the format.
def get_farthest_node(self, topology_only=False): farthest_node, farthest_dist = self.get_farthest_leaf( topology_only=topology_only) prev = self cdist = 0.0 if topology_only else prev.dist current = prev.up while current is not None: for ch in current.chi...
Returns the node's farthest descendant or ancestor node, and the distance to it. :argument False topology_only: If set to True, distance between nodes will be referred to the number of nodes between them. In other words, topological distance will be used instead of branch ...
def start(context, mip_config, email, priority, dryrun, command, start_with, family): mip_cli = MipCli(context.obj['script']) mip_config = mip_config or context.obj['mip_config'] email = email or environ_email() kwargs = dict(config=mip_config, family=family, priority=priority, email=email, dryrun=dryru...
Start a new analysis.
def weed(self): _ext = [k for k in self._dict.keys() if k not in self.c_param] for k in _ext: del self._dict[k]
Get rid of key value pairs that are not standard
def run(self): self._wake_up() while not self._q.empty(): self._config = self._q.get() while not self.exit.is_set(): settings = self._read_settings() settings['valid'] = self._valid_config(settings) self._cb(settings) if self.cooldown.i...
Run the core loop of reading and writing configurations. This is where all the roaster magic occurs. On the initial run, we prime the roaster with some data to wake it up. Once awoke, we check our shared queue to identify if the user has passed any updated configuration. Once checked, s...
def simple_separated_format(separator): return TableFormat(None, None, None, None, headerrow=DataRow('', separator, ''), datarow=DataRow('', separator, ''), padding=0, with_header_hide=None)
Construct a simple TableFormat with columns separated by a separator. >>> tsv = simple_separated_format("\\t") ; \ tabulate([["foo", 1], ["spam", 23]], tablefmt=tsv) == 'foo \\t 1\\nspam\\t23' True
def _has_tag(version, debug=False): cmd = sh.git.bake('show-ref', '--verify', '--quiet', "refs/tags/{}".format(version)) try: util.run_command(cmd, debug=debug) return True except sh.ErrorReturnCode: return False
Determine a version is a local git tag name or not. :param version: A string containing the branch/tag/sha to be determined. :param debug: An optional bool to toggle debug output. :return: bool
def create_db(name, **client_args): if db_exists(name, **client_args): log.info('DB \'%s\' already exists', name) return False client = _client(**client_args) client.create_database(name) return True
Create a database. name Name of the database to create. CLI Example: .. code-block:: bash salt '*' influxdb.create_db <name>
def _get_filesystem_path(self, url_path, basedir=settings.MEDIA_ROOT): if url_path.startswith(settings.MEDIA_URL): url_path = url_path[len(settings.MEDIA_URL):] return os.path.normpath(os.path.join(basedir, url2pathname(url_path)))
Makes a filesystem path from the specified URL path
def _write_plain_json(file_path, js): if file_path.endswith('.bz2'): with bz2.open(file_path, 'wt', encoding=_default_encoding) as f: json.dump(js, f, indent=2, ensure_ascii=False) else: with open(file_path, 'w', encoding=_default_encoding) as f: json.dump(js, f, indent=2...
Write information to a JSON file This makes sure files are created with the proper encoding and consistent indenting Parameters ---------- file_path : str Full path to the file to write to. It will be overwritten if it exists js : dict JSON information to write
def GetCompressedStreamTypeIndicators(cls, path_spec, resolver_context=None): if (cls._compressed_stream_remainder_list is None or cls._compressed_stream_store is None): specification_store, remainder_list = cls._GetSpecificationStore( definitions.FORMAT_CATEGORY_COMPRESSED_STREAM) cls...
Determines if a file contains a supported compressed stream types. Args: path_spec (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built-in context which is not multi process safe. Returns: list[str]: supported forma...
def allow_pgcodes(cr, *codes): try: with cr.savepoint(): with core.tools.mute_logger('odoo.sql_db'): yield except (ProgrammingError, IntegrityError) as error: msg = "Code: {code}. Class: {class_}. Error: {error}.".format( code=error.pgcode, cla...
Context manager that will omit specified error codes. E.g., suppose you expect a migration to produce unique constraint violations and you want to ignore them. Then you could just do:: with allow_pgcodes(cr, psycopg2.errorcodes.UNIQUE_VIOLATION): cr.execute("INSERT INTO me (name) SELECT na...
def delete_api_stage(restApiId, stageName, region=None, key=None, keyid=None, profile=None): try: conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile) conn.delete_stage(restApiId=restApiId, stageName=stageName) return {'deleted': True} except ClientError as e: r...
Deletes stage identified by stageName from API identified by restApiId CLI Example: .. code-block:: bash salt myminion boto_apigateway.delete_api_stage restApiId stageName
def show_bgp_speaker(self, bgp_speaker_id, **_params): return self.get(self.bgp_speaker_path % (bgp_speaker_id), params=_params)
Fetches information of a certain BGP speaker.
async def render_template(template_name_or_list: Union[str, List[str]], **context: Any) -> str: await current_app.update_template_context(context) template = current_app.jinja_env.get_or_select_template(template_name_or_list) return await _render(template, context)
Render the template with the context given. Arguments: template_name_or_list: Template name to render of a list of possible template names. context: The variables to pass to the template.
def title_has_tag(page, lang, tag): from .models import TitleTags if hasattr(tag, 'slug'): slug = tag.slug else: slug = tag try: return page.get_title_obj( language=lang, fallback=False ).titletags.tags.filter(slug=slug).exists() except TitleTags.DoesNotEx...
Check if a Title object is associated with the given tag. This function does not use fallbacks to retrieve title object. :param page: a Page instance :param lang: a language code :param tag: a Tag instance or a slug string. :return: whether the Title instance has the given tag attached (False if n...
def stop_capture(self): if self._capture_node: yield from self._capture_node["node"].post("/adapters/{adapter_number}/ports/{port_number}/stop_capture".format(adapter_number=self._capture_node["adapter_number"], port_number=self._capture_node["port_number"])) self._capture_node = None ...
Stop capture on a link
def get_mate_center(self, angle=0): return Mate(self, CoordSystem.from_plane( cadquery.Plane( origin=(0, 0, self.width / 2), xDir=(1, 0, 0), normal=(0, 0, 1), ).rotated((0, 0, angle)) ))
Mate at ring's center rotated ``angle`` degrees. :param angle: rotation around z-axis (unit: deg) :type angle: :class:`float` :return: mate in ring's center rotated about z-axis :rtype: :class:`Mate <cqparts.constraint.Mate>`
def get_incidents(self): resp = requests.get(CRIME_URL, params=self._get_params(), headers=self.headers) incidents = [] data = resp.json() if ATTR_CRIMES not in data: return incidents for incident in data.get(ATTR_CRIMES): if _validate_incident_date_range(...
Get incidents.
def update_user_label(self): self._user_label = _uniqueid_to_uniquetwig(self._bundle, self.unique_label) self._set_curly_label()
finds this parameter and gets the least_unique_twig from the bundle
def update_frequency(shell_ctx): frequency_path = os.path.join(shell_ctx.config.get_config_dir(), shell_ctx.config.get_frequency()) if os.path.exists(frequency_path): with open(frequency_path, 'r') as freq: try: frequency = json.load(freq) except ValueError: ...
updates the frequency from files
def add(self, *args, **kwargs): if self.start and self.start.state == 'done' and kwargs.get('log_action') != 'done': raise ProgressLoggingError("Can't add -- process section is done") self.augment_args(args, kwargs) kwargs['log_action'] = kwargs.get('log_action', 'add') rec =...
Add a new record to the section
def FilterArgsFromSemanticProtobuf(protobuf, kwargs): for descriptor in protobuf.type_infos: value = kwargs.pop(descriptor.name, None) if value is not None: setattr(protobuf, descriptor.name, value)
Assign kwargs to the protobuf, and remove them from the kwargs dict.
def clistream(reporter, *args, **kwargs): files = kwargs.get('files') encoding = kwargs.get('input_encoding', DEFAULT_ENCODING) processes = kwargs.get('processes') chunksize = kwargs.get('chunksize') from clitool.processor import CliHandler, Streamer Handler = kwargs.get('Handler') if Handle...
Handle stream data on command line interface, and returns statistics of success, error, and total amount. More detailed information is available on underlying feature, :mod:`clitool.processor`. :param Handler: [DEPRECATED] Handler for file-like streams. (default: :class:`clitool.processor....
def kill_all(self): logger.info('Job {0} killing all currently running tasks'.format(self.name)) for task in self.tasks.itervalues(): if task.started_at and not task.completed_at: task.kill()
Kill all currently running jobs.
def SensorMetatagsGet(self, sensor_id, namespace = None): ns = "default" if namespace is None else namespace if self.__SenseApiCall__('/sensors/{0}/metatags.json'.format(sensor_id), 'GET', parameters = {'namespace': ns}): return True else: self.__error__ = "api call ...
Retrieve the metatags of a sensor. @param sensor_id (int) - Id of the sensor to retrieve metatags from @param namespace (stirng) - Namespace for which to retrieve metatags. @return (bool) - Boolean indicating whether SensorMetatagsGet was successful
def output_notebook( d3js_url="//d3js.org/d3.v3.min", requirejs_url="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js", html_template=None ): if html_template is None: html_template = read_lib('html', 'setup') setup_html = populate_template( html_template...
Import required Javascript libraries to Jupyter Notebook.
def make_message(subject="", body="", from_email=None, to=None, bcc=None, attachments=None, headers=None, priority=None): to = filter_recipient_list(to) bcc = filter_recipient_list(bcc) core_msg = EmailMessage( subject=subject, body=body, from_email=from_email, ...
Creates a simple message for the email parameters supplied. The 'to' and 'bcc' lists are filtered using DontSendEntry. If needed, the 'email' attribute can be set to any instance of EmailMessage if e-mails with attachments etc. need to be supported. Call 'save()' on the result when it is ready to be s...
def _indent(x): lines = x.splitlines() for i, line in enumerate(lines): lines[i] = ' ' + line return '\n'.join(lines)
Indent a string by 4 characters.
def next(self): while True: self.cur_idx += 1 if self.__datasource.populate_iteration(self): return self raise StopIteration
Move to the next valid locus. Will only return valid loci or exit via StopIteration exception