code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def stop(context): config = context.obj["config"] pidfile = select(config, "application.pidfile", DEFAULT_PIDFILE) daemon_stop(pidfile)
Stop application server.
def post(self, request, key): email = request.POST.get('email') user_id = request.POST.get('user') if not email: return http.HttpResponseBadRequest() try: EmailAddressValidation.objects.create(address=email, user_i...
Create new email address that will wait for validation
def keypair_field_data(request, include_empty_option=False): keypair_list = [] try: keypairs = api.nova.keypair_list(request) keypair_list = [(kp.name, kp.name) for kp in keypairs] except Exception: exceptions.handle(request, _('Unable to retrieve key pairs.')) if not keypair_lis...
Returns a list of tuples of all keypairs. Generates a list of keypairs available to the user (request). And returns a list of (id, name) tuples. :param request: django http request object :param include_empty_option: flag to include a empty tuple in the front of the list :return: list of (...
def _merge_bee(self, bee): random_dimension = randint(0, len(self._value_ranges) - 1) second_bee = randint(0, self._num_employers - 1) while (bee.id == self._employers[second_bee].id): second_bee = randint(0, self._num_employers - 1) new_bee = deepcopy(bee) new_bee.va...
Shifts a random value for a supplied bee with in accordance with another random bee's value Args: bee (EmployerBee): supplied bee to merge Returns: tuple: (score of new position, values of new position, fitness function return value of new position)
def breakpoints_by_caller(bed_files): merged = concat(bed_files) if not merged: return [] grouped_start = merged.groupby(g=[1, 2, 2], c=4, o=["distinct"]).filter(lambda r: r.end > r.start).saveas() grouped_end = merged.groupby(g=[1, 3, 3], c=4, o=["distinct"]).filter(lambda r: r.end > r.start).s...
given a list of BED files of the form chrom start end caller return a BedTool of breakpoints as each line with the fourth column the caller with evidence for the breakpoint chr1 1 10 caller1 -> chr1 1 1 caller1 chr1 1 20 caller2 chr1 1 1 caller2 chr1 10 10 caller1 ...
def skip(): if not settings.platformCompatible(): return False (output, error) = subprocess.Popen(["osascript", "-e", SKIP], stdout=subprocess.PIPE).communicate()
Tell iTunes to skip a song
def _overlay_for_saml_metadata(self, config, co_name): for co in self.config[self.KEY_CO]: if co[self.KEY_ENCODEABLE_NAME] == co_name: break key = self.KEY_ORGANIZATION if key in co: if key not in config: config[key] = {} for or...
Overlay configuration details like organization and contact person from the front end configuration onto the IdP configuration to support SAML metadata generation. :type config: satosa.satosa_config.SATOSAConfig :type co_name: str :rtype: satosa.satosa_config.SATOSAConfig ...
def _approximate_unkown_bond_lengths(self): dataset = self.lengths[BOND_SINGLE] for n1 in periodic.iter_numbers(): for n2 in periodic.iter_numbers(): if n1 <= n2: pair = frozenset([n1, n2]) atom1 = periodic[n1] atom2...
Completes the bond length database with approximations based on VDW radii
def getRoutes(self): routes = [] try: out = subprocess.Popen([routeCmd, "-n"], stdout=subprocess.PIPE).communicate()[0] except: raise Exception('Execution of command %s failed.' % ipCmd) lines = out.splitlines() if len(l...
Get routing table. @return: List of routes.
def iso8601interval(value, argument='argument'): try: start, end = _parse_interval(value) if end is None: end = _expand_datetime(start, value) start, end = _normalize_interval(start, end, value) except ValueError: raise ValueError( "Invalid {arg}: {value}....
Parses ISO 8601-formatted datetime intervals into tuples of datetimes. Accepts both a single date(time) or a full interval using either start/end or start/duration notation, with the following behavior: - Intervals are defined as inclusive start, exclusive end - Single datetimes are translated into th...
def transform_pip_requirement_set(self, requirement_set): filtered_requirements = [] for requirement in requirement_set.requirements.values(): if requirement.satisfied_by: continue if requirement.constraint: continue filtered_requiremen...
Transform pip's requirement set into one that `pip-accel` can work with. :param requirement_set: The :class:`pip.req.RequirementSet` object reported by pip. :returns: A list of :class:`pip_accel.req.Requirement` objects. This function converts the :class:`pip.re...
def clear_instance_cache(cls, func): @functools.wraps(func) def func_wrapper(*args, **kwargs): if not args: raise ValueError('`self` is not available.') else: the_self = args[0] cls.clear_self_cache(the_self) return func(*ar...
clear the instance cache Decorate a method of a class, the first parameter is supposed to be `self`. It clear all items cached by the `instance_cache` decorator. :param func: function to decorate
def _HostPrefix(client_id): if not client_id: return "" hostname = None if data_store.RelationalDBEnabled(): client_snapshot = data_store.REL_DB.ReadClientSnapshot(client_id) if client_snapshot: hostname = client_snapshot.knowledge_base.fqdn else: client_fd = aff4.FACTORY.Open(client_id, m...
Build a host prefix for a notification message based on a client id.
def _get_appoptics(options): conn = appoptics_metrics.connect( options.get('api_token'), sanitizer=appoptics_metrics.sanitize_metric_name, hostname=options.get('api_url')) log.info("Connected to appoptics.") return conn
Return an appoptics connection object.
def get_output_fields(self): emit_fields = list(i.lower() for i in re.sub(r"[^_A-Z]+", ' ', self.format_item(None)).split()) result = [] for name in emit_fields[:]: if name not in engine.FieldDefinition.FIELDS: self.LOG.warn("Omitted unknown name '%s' from statistics ...
Get field names from output template.
def _check_algorithm_values(item): problems = [] for k, v in item.get("algorithm", {}).items(): if v is True and k not in ALG_ALLOW_BOOLEANS: problems.append("%s set as true" % k) elif v is False and (k not in ALG_ALLOW_BOOLEANS and k not in ALG_ALLOW_FALSE): problems.app...
Check for misplaced inputs in the algorithms. - Identify incorrect boolean values where a choice is required.
def set(self, hue): x = hue / 360. * self.winfo_width() self.coords('cursor', x, 0, x, self.winfo_height()) self._variable.set(hue)
Set cursor position on the color corresponding to the hue value.
def read_time(self, content): if get_class_name(content) in self.content_type_supported: if hasattr(content, 'readtime'): return None default_lang_conf = self.lang_settings['default'] lang_conf = self.lang_settings.get(content.lang, default_lang_conf) ...
Core function used to generate the read_time for content. Parameters: :param content: Instance of pelican.content.Content Returns: None
def to_unicode_string(string): if string is None: return None if is_unicode_string(string): return string if PY2: return unicode(string, encoding="utf-8") return string.decode(encoding="utf-8")
Return a Unicode string out of the given string. On Python 2, it calls ``unicode`` with ``utf-8`` encoding. On Python 3, it just returns the given string. Return ``None`` if ``string`` is ``None``. :param str string: the string to convert to Unicode :rtype: (Unicode) str
def request_video_count(blink): url = "{}/api/v2/videos/count".format(blink.urls.base_url) return http_get(blink, url)
Request total video count.
def repackage_var(h): if IS_TORCH_04: return h.detach() if type(h) == torch.Tensor else tuple(repackage_var(v) for v in h) else: return Variable(h.data) if type(h) == Variable else tuple(repackage_var(v) for v in h)
Wraps h in new Variables, to detach them from their history.
def limit(self, limit): if limit is None: raise ValueError("Invalid value for `limit`, must not be `None`") if limit > 200: raise ValueError("Invalid value for `limit`, must be a value less than or equal to `200`") if limit < 1: raise ValueError("Invalid value...
Sets the limit of this ListEmployeeWagesRequest. Maximum number of Employee Wages to return per page. Can range between 1 and 200. The default is the maximum at 200. :param limit: The limit of this ListEmployeeWagesRequest. :type: int
def close(self, cancelled=False): self._on_close(cancelled) self._scene.remove_effect(self)
Close this temporary pop-up. :param cancelled: Whether the pop-up was cancelled (e.g. by pressing Esc).
def push_pv(self, tokens): logger.debug("Pushing PV data: %s" % tokens) bus = self.case.buses[tokens["bus_no"]-1] g = Generator(bus) g.p = tokens["p"] g.q_max = tokens["q_max"] g.q_min = tokens["q_min"] self.case.generators.append(g)
Creates and Generator object, populates it with data, finds its Bus and adds it.
def save(self, file, contents, name=None, overwrite=False): if name is None: name = self.format_from_extension(op.splitext(file)[1]) file_format = self.file_type(name) if file_format == 'text': _write_text(file, contents) elif file_format == 'json': _w...
Save contents into a file. The format name can be specified explicitly or inferred from the file extension.
def re_normalize_flux(self, kwargs_ps, norm_factor): for i, model in enumerate(self.point_source_type_list): if model == 'UNLENSED': kwargs_ps[i]['point_amp'] *= norm_factor elif model in ['LENSED_POSITION', 'SOURCE_POSITION']: if self._fixed_magnification...
renormalizes the point source amplitude keywords by a factor :param kwargs_ps_updated: :param norm_factor: :return:
def vecs_to_datmesh(x, y): x, y = meshgrid(x, y) out = zeros(x.shape + (2,), dtype=float) out[:, :, 0] = x out[:, :, 1] = y return out
Converts input arguments x and y to a 2d meshgrid, suitable for calling Means, Covariances and Realizations.
def get_success_url(self): slugs = '+'.join(self.metric_slugs) url = reverse('redis_metric_aggregate_detail', args=[slugs]) return url.replace("%2B", "+")
Reverses the ``redis_metric_aggregate_detail`` URL using ``self.metric_slugs`` as an argument.
def _symlink_or_copy_grabix(in_file, out_file, data): if cwlutils.is_cwl_run(data): if utils.file_exists(in_file + ".gbi"): out_file = in_file else: utils.copy_plus(in_file, out_file) else: utils.symlink_plus(in_file, out_file) return out_file
We cannot symlink in CWL, but may be able to use inputs or copy
def _format_count_file(count_file, data): COUNT_COLUMN = 5 out_file = os.path.splitext(count_file)[0] + ".fixed.counts" if file_exists(out_file): return out_file df = pd.io.parsers.read_table(count_file, sep="\t", index_col=0, header=1) df_sub = df.ix[:, COUNT_COLUMN] with file_transacti...
this cuts the count file produced from featureCounts down to a two column file of gene ids and number of reads mapping to each gene
def filter_by_transcript_expression( self, transcript_expression_dict, min_expression_value=0.0): return self.filter_above_threshold( key_fn=lambda effect: effect.transcript_id, value_dict=transcript_expression_dict, threshold=min_expressio...
Filters effects to those which have an associated transcript whose expression value in the transcript_expression_dict argument is greater than min_expression_value. Parameters ---------- transcript_expression_dict : dict Dictionary mapping Ensembl transcript IDs to e...
def back_bfs(self, start, end=None): return [node for node, step in self._iterbfs(start, end, forward=False)]
Returns a list of nodes in some backward BFS order. Starting from the start node the breadth first search proceeds along incoming edges.
def drop_dims(self, drop_dims): if utils.is_scalar(drop_dims): drop_dims = [drop_dims] missing_dimensions = [d for d in drop_dims if d not in self.dims] if missing_dimensions: raise ValueError('Dataset does not contain the dimensions: %s' % mi...
Drop dimensions and associated variables from this dataset. Parameters ---------- drop_dims : str or list Dimension or dimensions to drop. Returns ------- obj : Dataset The dataset without the given dimensions (or any variables contai...
def save_sequence_rule_enabler(self, sequence_rule_enabler_form, *args, **kwargs): if sequence_rule_enabler_form.is_for_update(): return self.update_sequence_rule_enabler(sequence_rule_enabler_form, *args, **kwargs) else: return self.create_sequence_rule_enabler(sequence_rule_ena...
Pass through to provider SequenceRuleEnablerAdminSession.update_sequence_rule_enabler
def _check_periodic(periodic): periodic = np.array(periodic) if len(periodic.shape) == 2: assert periodic.shape[0] == periodic.shape[1], 'periodic shoud be a square matrix or a flat array' return np.diag(periodic) elif len(periodic.shape) == 1: return periodic else: raise...
Validate periodic input
def get_ip_Minv_B(self): if not isinstance(self.M, utils.IdentityLinearOperator): if isinstance(self.Minv, utils.IdentityLinearOperator): raise utils.ArgumentError( 'Minv has to be provided for the evaluation of the inner ' 'product that is imp...
Returns the inner product that is implicitly used with the positive definite preconditioner ``M``.
def replace_route_table_association(association_id, route_table_id, region=None, key=None, keyid=None, profile=None): try: conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile) association_id = conn.replace_route_table_association_with_assoc(association_id, route_table_id) l...
Replaces a route table association. CLI Example: .. code-block:: bash salt myminion boto_vpc.replace_route_table_association 'rtbassoc-d8ccddba' 'rtb-1f382e7d'
def super_terms(self): if self.doc and self.doc.super_terms: return self.doc.super_terms return {k.lower(): v['inheritsfrom'].lower() for k, v in self._declared_terms.items() if 'inheritsfrom' in v}
Return a dictionary mapping term names to their super terms
def delete(self, uri): try: self.connect(uri, method='DELETE') return True except urllib.error.HTTPError: return False
Method deletes a Fedora Object in the repository Args: uri(str): URI of Fedora Object
def _do_watch_progress(filename, sock, handler): connection, client_address = sock.accept() data = b'' try: while True: more_data = connection.recv(16) if not more_data: break data += more_data lines = data.split(b'\n') for ...
Function to run in a separate gevent greenlet to read progress events from a unix-domain socket.
def _assemble_and_send_validation_request(self): return self.client.service.validateShipment( WebAuthenticationDetail=self.WebAuthenticationDetail, ClientDetail=self.ClientDetail, TransactionDetail=self.TransactionDetail, Version=self.VersionId, ...
Fires off the Fedex shipment validation request. @warning: NEVER CALL THIS METHOD DIRECTLY. CALL send_validation_request(), WHICH RESIDES ON FedexBaseService AND IS INHERITED.
def query_file(self, path, fetchall=False, **params): if not os.path.exists(path): raise IOError("File '{}' not found!".format(path)) if os.path.isdir(path): raise IOError("'{}' is a directory!".format(path)) with open(path) as f: query = f.read() retu...
Like Connection.query, but takes a filename to load a query from.
def _report_lint_error(error, file_path): line = error[1].line code = error[0] description = error[1].description sys.stdout.write("{0}:{1} [{2}] {3}\n".format(file_path, line, code, ...
Report a linter error.
def get_minimum_span(low, high, span): if is_number(low) and low == high: if isinstance(low, np.datetime64): span = span * np.timedelta64(1, 's') low, high = low-span, high+span return low, high
If lower and high values are equal ensures they are separated by the defined span.
def checkMarkovInputs(self): StateCount = self.MrkvArray[0].shape[0] assert self.Rfree.shape == (StateCount,),'Rfree not the right shape!' for MrkvArray_t in self.MrkvArray: assert MrkvArray_t.shape == (StateCount,StateCount),'MrkvArray not the right shape!' for LivPrb_...
Many parameters used by MarkovConsumerType are arrays. Make sure those arrays are the right shape. Parameters ---------- None Returns ------- None
def add_history(self, line): u if not hasattr(line, "get_line_text"): line = lineobj.ReadLineTextBuffer(line) if not line.get_line_text(): pass elif len(self.history) > 0 and self.history[-1].get_line_text() == line.get_line_text(): pass ...
u'''Append a line to the history buffer, as if it was the last line typed.
def fill_rect(self, rect): check_int_err(lib.SDL_RenderFillRect(self._ptr, rect._ptr))
Fill a rectangle on the current rendering target with the drawing color. Args: rect (Rect): The destination rectangle, or None to fill the entire rendering target. Raises: SDLError: If an error is encountered.
def insert(python_data: LdapObject, database: Optional[Database] = None) -> LdapObject: assert isinstance(python_data, LdapObject) table: LdapObjectClass = type(python_data) empty_data = table() changes = changeset(empty_data, python_data.to_dict()) return save(changes, database)
Insert a new python_data object in the database.
def usingCurl(): fetcher = getDefaultFetcher() if isinstance(fetcher, ExceptionWrappingFetcher): fetcher = fetcher.fetcher return isinstance(fetcher, CurlHTTPFetcher)
Whether the currently set HTTP fetcher is a Curl HTTP fetcher.
def command_gen(self, *names): if not names: sys.exit('Please provide generator names') for name in names: name, count = name, 0 if ':' in name: name, count = name.split(':', 1) count = int(count) create = self.generators[name] ...
Runs generator functions. Run `docs` generator function:: ./manage.py sqla:gen docs Run `docs` generator function with `count=10`:: ./manage.py sqla:gen docs:10
def add_parser(self, *args, **kwargs): command_name = args[0] new_kwargs = kwargs.copy() new_kwargs['configman_subparsers_option'] = self._configman_option new_kwargs['subparser_name'] = command_name subparsers = self._configman_option.foreign_data.argparse.subparsers a_s...
each time a subparser action is used to create a new parser object we must save the original args & kwargs. In a later phase of configman, we'll need to reproduce the subparsers exactly without resorting to copying. We save the args & kwargs in the 'foreign_data' section of the configm...
def add_field(self, name, label, field_type, *args, **kwargs): if name in self._dyn_fields: raise AttributeError('Field already added to the form.') else: self._dyn_fields[name] = {'label': label, 'type': field_type, 'args': args, 'kwargs': k...
Add the field to the internal configuration dictionary.
def start(self, on_exit_callback=None): for service in self.services.keys(): self.services[service] = self.services[service]() self.server.start(on_exit_callback)
Start the Engel application by initializing all registered services and starting an Autobahn IOLoop. :param on_exit_callback: Callback triggered on application exit
def revision(self, message): alembic.command.revision(self.alembic_config(), message=message)
Create a new revision file :param message:
def _bulk_op(self, record_id_iterator, op_type, index=None, doc_type=None): with self.create_producer() as producer: for rec in record_id_iterator: producer.publish(dict( id=str(rec), op=op_type, index=index, ...
Index record in Elasticsearch asynchronously. :param record_id_iterator: Iterator that yields record UUIDs. :param op_type: Indexing operation (one of ``index``, ``create``, ``delete`` or ``update``). :param index: The Elasticsearch index. (Default: ``None``) :param doc_type...
def create_initial(self, address_values): with self._lock: for add, val in address_values: self._state[add] = _ContextFuture(address=add, result=val)
Create futures from inputs with the current value for that address at the start of that context. Args: address_values (list of tuple): The tuple is string, bytes of the address and value.
def asdict(self): return { "methods": {m.name: m.asdict() for m in self.methods}, "protocols": self.protocols, "notifications": {n.name: n.asdict() for n in self.notifications}, }
Return dict presentation of this service. Useful for dumping the device information into JSON.
def _setup_master(self): self.broker = mitogen.master.Broker(install_watcher=False) self.router = mitogen.master.Router( broker=self.broker, max_message_size=4096 * 1048576, ) self._setup_responder(self.router.responder) mitogen.core.listen(self.broker, 's...
Construct a Router, Broker, and mitogen.unix listener
def combine_last_two_dimensions(x): x_shape = common_layers.shape_list(x) a, b = x_shape[-2:] return tf.reshape(x, x_shape[:-2] + [a * b])
Reshape x so that the last two dimension become one. Args: x: a Tensor with shape [..., a, b] Returns: a Tensor with shape [..., ab]
def _build_con_add_cmd(ssid: str, security_type: SECURITY_TYPES, psk: Optional[str], hidden: bool, eap_args: Optional[Dict[str, Any]]) -> List[str]: configure_cmd = ['connection', 'add', 'save', 'yes', 'autoconnect', 'yes', ...
Build the nmcli connection add command to configure the new network. The parameters are the same as configure but without the defaults; this should be called only by configure.
def relevant_part(self, original, pos, sep=' '): start = original.rfind(sep, 0, pos) + 1 end = original.find(sep, pos - 1) if end == -1: end = len(original) return original[start:end], start, end, pos - start
calculates the subword in a `sep`-splitted list of substrings of `original` that `pos` is ia.n
def pad_position_l(self, i): if i >= self.n_pads_l: raise ModelError("pad index out-of-bounds") return (self.length - self.pad_length) / (self.n_pads_l - 1) * i + self.pad_length / 2
Determines the position of the ith pad in the length direction. Assumes equally spaced pads. :param i: ith number of pad in length direction (0-indexed) :return:
def _handle_command(self, connection, sender, target, command, payload): try: handler = getattr(self, "cmd_{0}".format(command)) except AttributeError: self.safe_send(connection, target, "Unknown command: %s", command) else: try: ...
Handles a command, if any
def lifetimes(self, dates, include_start_date, country_codes): if isinstance(country_codes, string_types): raise TypeError( "Got string {!r} instead of an iterable of strings in " "AssetFinder.lifetimes.".format(country_codes), ) country_codes = fr...
Compute a DataFrame representing asset lifetimes for the specified date range. Parameters ---------- dates : pd.DatetimeIndex The dates for which to compute lifetimes. include_start_date : bool Whether or not to count the asset as alive on its start_date....
def add_external_reference(self,ext_ref): ext_refs_node = self.node.find('externalReferences') if ext_refs_node is None: ext_refs_obj = CexternalReferences() self.node.append(ext_refs_obj.get_node()) else: ext_refs_obj = CexternalReferences(ext_refs_node) ...
Adds an external reference object to the markable @type ext_ref: L{CexternalReference} @param ext_ref: an external reference object
def _check_array(self, X): if isinstance(X, da.Array): if X.ndim == 2 and X.numblocks[1] > 1: logger.debug("auto-rechunking 'X'") if not np.isnan(X.chunks[0]).any(): X = X.rechunk({0: "auto", 1: -1}) else: X = X....
Validate an array for post-fit tasks. Parameters ---------- X : Union[Array, DataFrame] Returns ------- same type as 'X' Notes ----- The following checks are applied. - Ensure that the array is blocked only along the samples.
def new_product(self, name): n = self._product_cls(self, name, summary_cls=self._summary_cls) self.graph.add_node(n) self.products.append(n) return n
Create a new product. Args: name: name of the new product. Returns: A new product instance.
def delete(network): try: network.destroy() except libvirt.libvirtError as error: raise RuntimeError("Unable to destroy network: {}".format(error))
libvirt network cleanup. @raise: libvirt.libvirtError.
def pull(path, service_names=None): project = __load_project(path) if isinstance(project, dict): return project else: try: project.pull(service_names) except Exception as inst: return __handle_except(inst) return __standardize_result(True, 'Pulling contain...
Pull image for containers in the docker-compose file, service_names is a python list, if omitted pull all images path Path where the docker-compose file is stored on the server service_names If specified will pull only the image for the specified services CLI Example: .. code-bloc...
def load_from_file(module_path): from imp import load_module, PY_SOURCE imported = None if module_path: with open(module_path, 'r') as openfile: imported = load_module('mod', openfile, module_path, ('imported', 'r', PY_SOURCE)) return imported
Load a python module from its absolute filesystem path Borrowed from django-cms
def _get_thumbnail_url(image): lhs, rhs = splitext(image.url) lhs += THUMB_EXT thumb_url = f'{lhs}{rhs}' return thumb_url
Given a large image, return the thumbnail url
def number_of_states(dtrajs): r nmax = 0 for dtraj in dtrajs: nmax = max(nmax, np.max(dtraj)) return nmax + 1
r""" Determine the number of states from a set of discrete trajectories Parameters ---------- dtrajs : list of int-arrays discrete trajectories
def community(self): return _community.Community(url=self._url + "/community", securityHandler=self._securityHandler, proxy_url=self._proxy_url, proxy_port=self._proxy_port)
The portal community root covers user and group resources and operations.
def wrap_options(self, data, renderer_context): request = renderer_context.get("request", None) method = request and getattr(request, 'method') if method != 'OPTIONS': raise WrapperNotApplicable("Request method must be OPTIONS") wrapper = self.dict_class() wrapper["me...
Wrap OPTIONS data as JSON API meta value
def TRUE(classical_reg): warn("`TRUE a` has been deprecated. Use `MOVE a 1` instead.") if isinstance(classical_reg, int): classical_reg = Addr(classical_reg) return MOVE(classical_reg, 1)
Produce a TRUE instruction. :param classical_reg: A classical register to modify. :return: An instruction object representing the equivalent MOVE.
def connect(self, event_handler): context = ssl.create_default_context(purpose=ssl.Purpose.CLIENT_AUTH) if not self.options['verify']: context.verify_mode = ssl.CERT_NONE scheme = 'wss://' if self.options['scheme'] != 'https': scheme = 'ws://' context = None url = '{scheme:s}{url:s}:{port:s}{basepath...
Connect to the websocket and authenticate it. When the authentication has finished, start the loop listening for messages, sending a ping to the server to keep the connection alive. :param event_handler: Every websocket event will be passed there. Takes one argument. :type event_handler: Function(message) :r...
def run_job(args): jm = setup(args) job_id = int(os.environ['JOB_ID']) array_id = int(os.environ['SGE_TASK_ID']) if os.environ['SGE_TASK_ID'] != 'undefined' else None jm.run_job(job_id, array_id)
Starts the wrapper script to execute a job, interpreting the JOB_ID and SGE_TASK_ID keywords that are set by the grid or by us.
def watch_statuses(self, observer, batch_ids): with self._lock: statuses = self.get_statuses(batch_ids) if self._has_no_pendings(statuses): observer.notify_batches_finished(statuses) else: self._observers[observer] = statuses
Allows a component to register to be notified when a set of batches is no longer PENDING. Expects to be able to call the "notify_batches_finished" method on the registered component, sending the statuses of the batches. Args: observer (object): Must implement "notify_batches...
def results_from_cli(opts, load_samples=True, **kwargs): fp_all = [] samples_all = [] input_files = opts.input_file if isinstance(input_files, str): input_files = [input_files] for input_file in input_files: logging.info("Reading input file %s", input_file) fp = loadfile(inpu...
Loads an inference result file along with any labels associated with it from the command line options. Parameters ---------- opts : ArgumentParser options The options from the command line. load_samples : bool, optional Load the samples from the file. Returns ------- fp...
def set_cookie_prefix(self, cookie_prefix=None): if (cookie_prefix is None): self.cookie_prefix = "%06d_" % int(random.random() * 1000000) else: self.cookie_prefix = cookie_prefix
Set a random cookie prefix unless one is specified. In order to run multiple demonstration auth services on the same server we need to have different cookie names for each auth domain. Unless cookie_prefix is set, generate a random one.
def get_linked_properties(cli_ctx, app, resource_group, read_properties=None, write_properties=None): roles = { "ReadTelemetry": "api", "WriteAnnotations": "annotations", "AuthenticateSDKControlChannel": "agentconfig" } sub_id = get_subscription_id(cli_ctx) tmpl = '/subscriptions...
Maps user-facing role names to strings used to identify them on resources.
def new_log_filepath(self): lastlog_filename = os.path.join(self.dataflash_dir,'LASTLOG.TXT') if os.path.exists(lastlog_filename) and os.stat(lastlog_filename).st_size != 0: fh = open(lastlog_filename,'rb') log_cnt = int(fh.read()) + 1 fh.close() else: ...
returns a filepath to a log which does not currently exist and is suitable for DF logging
def get_victoria_day(self, year): may_24th = date(year, 5, 24) shift = may_24th.weekday() or 7 victoria_day = may_24th - timedelta(days=shift) return (victoria_day, "Victoria Day")
Return Victoria Day for Edinburgh. Set to the Monday strictly before May 24th. It means that if May 24th is a Monday, it's shifted to the week before.
def OnMerge(self, event): with undo.group(_("Merge cells")): self.grid.actions.merge_selected_cells(self.grid.selection) self.grid.ForceRefresh() self.grid.update_attribute_toolbar()
Merge cells event handler
def setOverlayDualAnalogTransform(self, ulOverlay, eWhich, fRadius): fn = self.function_table.setOverlayDualAnalogTransform pvCenter = HmdVector2_t() result = fn(ulOverlay, eWhich, byref(pvCenter), fRadius) return result, pvCenter
Sets the analog input to Dual Analog coordinate scale for the specified overlay.
def asDict( self ): if PY_3: item_fn = self.items else: item_fn = self.iteritems def toItem(obj): if isinstance(obj, ParseResults): if obj.haskeys(): return obj.asDict() else: return [toIt...
Returns the named parse results as a nested dictionary. Example:: integer = Word(nums) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") result = date_str.parseString('12/31/1999') print(type(result), repr(result)) # -> <class 'pyparsin...
def status(self): try: pf = file(self.pidfile,'r') pid = int(pf.read().strip()) pf.close() except IOError: pid = None if not pid: return False try: return os.path.exists("/proc/{0}".format(pid)) except OSError: return False
Check if the daemon is currently running. Requires procfs, so it will only work on POSIX compliant OS'.
def run_bafRegress(filenames, out_prefix, extract_filename, freq_filename, options): command = [ "bafRegress.py", "estimate", "--freqfile", freq_filename, "--freqcol", "2,5", "--extract", extract_filename, "--colsample", options.colsample, "...
Runs the bafRegress function. :param filenames: the set of all sample files. :param out_prefix: the output prefix. :param extract_filename: the name of the markers to extract. :param freq_filename: the name of the file containing the frequency. :param options: the other options. :type filename...
def next_frame_savp(): hparams = sv2p_params.next_frame_sv2p() hparams.add_hparam("z_dim", 8) hparams.add_hparam("num_discriminator_filters", 32) hparams.add_hparam("use_vae", True) hparams.add_hparam("use_gan", False) hparams.add_hparam("use_spectral_norm", True) hparams.add_hparam("gan_loss", "cross_ent...
SAVP model hparams.
def _open_ds_from_store(fname, store_mod=None, store_cls=None, **kwargs): if isinstance(fname, xr.Dataset): return fname if not isstring(fname): try: fname[0] except TypeError: pass else: if store_mod is not None and store_cls is not None: ...
Open a dataset and return it
def _ParsePage(self, parser_mediator, file_offset, page_data): page_header_map = self._GetDataTypeMap('binarycookies_page_header') try: page_header = self._ReadStructureFromByteStream( page_data, file_offset, page_header_map) except (ValueError, errors.ParseError) as exception: raise e...
Parses a page. Args: parser_mediator (ParserMediator): parser mediator. file_offset (int): offset of the data relative from the start of the file-like object. page_data (bytes): page data. Raises: ParseError: when the page cannot be parsed.
def make_action(self, fn, schema_parser, meta): validate_input = validate_output = None if "$input" in meta: with MarkKey("$input"): validate_input = schema_parser.parse(meta["$input"]) if "$output" in meta: with MarkKey("$output"): validat...
Make resource's method an action Validate input, output by schema in meta. If no input schema, call fn without params. If no output schema, will not validate return value. Args: fn: resource's method schema_parser: for parsing schema in meta meta: me...
def _tag_ec2(self, conn, role): tags = {'Role': role} conn.create_tags([self.instance_id], tags)
tag the current EC2 instance with a cluster role
def set_plain_text_font(self, font, color_scheme=None): self.plain_text.set_font(font, color_scheme=color_scheme)
Set plain text mode font
def ngram_count(self, ngram): query = "SELECT count FROM _{0}_gram".format(len(ngram)) query += self._build_where_clause(ngram) query += ";" result = self.execute_sql(query) return self._extract_first_integer(result)
Gets the count for a given ngram from the database. Parameters ---------- ngram : iterable of str A list, set or tuple of strings. Returns ------- count : int The count of the ngram.
def detectIphoneOrIpod(self): return UAgentInfo.deviceIphone in self.__userAgent \ or UAgentInfo.deviceIpod in self.__userAgent
Return detection of an iPhone or iPod Touch Detects if the current device is an iPhone or iPod Touch.
def _encode_regex(name, value, dummy0, dummy1): flags = value.flags if flags == 0: return b"\x0B" + name + _make_c_string_check(value.pattern) + b"\x00" elif flags == re.UNICODE: return b"\x0B" + name + _make_c_string_check(value.pattern) + b"u\x00" else: sflags = b"" if ...
Encode a python regex or bson.regex.Regex.
def get_camera_imageseries(self, number_of_imageseries=10, offset=0): response = None try: response = requests.get( urls.get_imageseries(self._giid), headers={ 'Accept': 'application/json, text/javascript, */*; q=0.01', ...
Get smartcam image series Args: number_of_imageseries (int): number of image series to get offset (int): skip offset amount of image series
def json_requested(): best = request.accept_mimetypes.best_match( ['application/json', 'text/html']) return (best == 'application/json' and request.accept_mimetypes[best] > request.accept_mimetypes['text/html'])
Check if json is the preferred output format for the request.
def to_ubyte_array(barray): bs = (ctypes.c_ubyte * len(barray))() pack_into('%ds' % len(barray), bs, 0, barray) return bs
Returns a c_ubyte_array filled with the given data of a bytearray or bytes