code
stringlengths
52
7.75k
docs
stringlengths
1
5.85k
def connectShell(connection, protocol): deferred = connectSession(connection, protocol) @deferred.addCallback def requestSubsystem(session): return session.requestShell() return deferred
Connect a Protocol to a ssh shell session
def connectSubsystem(connection, protocol, subsystem): deferred = connectSession(connection, protocol) @deferred.addCallback def requestSubsystem(session): return session.requestSubsystem(subsystem) return deferred
Connect a Protocol to a ssh subsystem channel
def connectSession(connection, protocol, sessionFactory=None, *args, **kwargs): factory = sessionFactory or defaultSessionFactory session = factory(*args, **kwargs) session.dataReceived = protocol.dataReceived session.closed = lambda: protocol.connectionLost(connectionDone) deferred = defer.De...
Open a SSHSession channel and connect a Protocol to it @param connection: the SSH Connection to open the session channel on @param protocol: the Protocol instance to connect to the session @param sessionFactory: factory method to generate a SSHSession instance @note: :args: and :kwargs: are passed to t...
def defaultSessionFactory(env={}, usePTY=False, *args, **kwargs): return SSHSession(env, usePTY, *args, **kwargs)
Create a SSHChannel of the given :channelType: type
def requestExec(self, commandLine): data = common.NS(commandLine) return self.sendRequest('exec', data, wantReply=True)
Request execution of :commandLine: and return a deferred reply.
def requestSubsystem(self, subsystem): data = common.NS(subsystem) return self.sendRequest('subsystem', data, wantReply=True)
Request a subsystem and return a deferred reply.
def requestPty(self, term=None, rows=0, cols=0, xpixel=0, ypixel=0, modes=''): #TODO: Needs testing! term = term or os.environ.get('TERM', '') data = packRequest_pty_req(term, (rows, cols, xpixel, ypixel), modes) return self.sendRequest('pty-req', data)
Request allocation of a pseudo-terminal for a channel @param term: TERM environment variable value (e.g., vt100) @param columns: terminal width, characters (e.g., 80) @param rows: terminal height, rows (e.g., 24) @param width: terminal width, pixels (e.g., 640) @param height: te...
def requestEnv(self, env={}): for variable, value in env.items(): data = common.NS(variable) + common.NS(value) self.sendRequest('env', data)
Send requests to set the environment variables for the channel
def commandstr(command): if command == CMD_MESSAGE_ERROR: msg = "CMD_MESSAGE_ERROR" elif command == CMD_MESSAGE_LIST: msg = "CMD_MESSAGE_LIST" elif command == CMD_MESSAGE_PASSWORD: msg = "CMD_MESSAGE_PASSWORD" elif command == CMD_MESSAGE_MP3: msg = "CMD_MESSAGE_MP3" ...
Convert command into string.
def run(): parser = OptionParser( version=__version__, description=__doc__, ) parser.add_option( '-u', '--url', dest='url', help='Database URL (connection string)', ) parser.add_option( '-r', '--render', dest='render', default='dot', choices=['plantuml'...
Command for reflection database objects
def get_poll(poll_id): return StrawPoll(requests.get('{api_url}/{poll_id}'.format(api_url=api_url, poll_id=poll_id)))
Get a strawpoll. Example: poll = strawpy.get_poll('11682852') :param poll_id: :return: strawpy.Strawpoll object
def create_poll(title, options, multi=True, permissive=True, captcha=False, dupcheck='normal'): query = { 'title': title, 'options': options, 'multi': multi, 'permissive': permissive, 'captcha': captcha, 'dupcheck': dupcheck } return StrawPoll(requests.po...
Create a strawpoll. Example: new_poll = strawpy.create_poll('Is Python the best?', ['Yes', 'No']) :param title: :param options: :param multi: :param permissive: :param captcha: :param dupcheck: :return: strawpy.Strawpoll object
def raise_status(response): if response.status_code != 200: if response.status_code == 401: raise StrawPollException('Unauthorized', response) elif response.status_code == 403: raise StrawPollException('Forbidden', response) elif response.status_code == 404: ...
Raise an exception if the request did not return a status code of 200. :param response: Request response body
def refresh(self): strawpoll_response = requests.get('{api_url}/{poll_id}'.format(api_url=api_url, poll_id=self.id)) raise_status(strawpoll_response) self.status_code = strawpoll_response.status_code self.response_json = strawpoll_response.json() self.id = self.response_...
Refresh all class attributes.
def write_json_file(self, path): with open(path, "w") as f: f.write(self.to_json())
Serialize this VariantCollection to a JSON representation and write it out to a text file.
def read_json_file(cls, path): with open(path, 'r') as f: json_string = f.read() return cls.from_json(json_string)
Construct a VariantCollection from a JSON file.
def dumps(data, escape=False, **kwargs): if 'sort_keys' not in kwargs: kwargs['sort_keys'] = True converted = json.dumps(data, default=_converter, **kwargs) if escape: # We're escaping the whole dumped string here cause there's no (easy) # way to hook into the native json libra...
A wrapper around `json.dumps` that can handle objects that json module is not aware. This function is aware of a list of custom serializers that can be registered by the API user, making it possible to convert any kind of object to types that the json library can handle.
def deserialize(klass, data): handler = DESERIALIZE_REGISTRY.get(klass) if handler: return handler(data) raise TypeError("There is no deserializer registered to handle " "instances of '{}'".format(klass.__name__))
Helper function to access a method that creates objects of a given `klass` with the received `data`.
def _convert_from(data): try: module, klass_name = data['__class__'].rsplit('.', 1) klass = getattr(import_module(module), klass_name) except (ImportError, AttributeError, KeyError): # But I still haven't found what I'm looking for # # Waiting for three different exc...
Internal function that will be hooked to the native `json.loads` Find the right deserializer for a given value, taking into account the internal deserializer registry.
def _converter(data): handler = REGISTRY.get(data.__class__) if handler: full_name = '{}.{}'.format( data.__class__.__module__, data.__class__.__name__) return { '__class__': full_name, '__value__': handler(data), } raise TypeError...
Internal function that will be passed to the native `json.dumps`. This function uses the `REGISTRY` of serializers and try to convert a given instance to an object that json.dumps can understand.
def start(self): logging.info('ResponseBot started') handler_classes = handler_utils.discover_handler_classes(self.config.get('handlers_package')) if len(handler_classes) == 0: logging.warning('No handler found. Did you forget to extend BaseTweethandler? Check --handlers-mo...
Try to init the main sub-components (:func:`~responsebot.utils.handler_utils.discover_handler_classes`, \ :func:`~responsebot.utils.auth_utils.auth`, :class:`~responsebot.responsebot_stream.ResponseBotStream`, etc.)
def handle_error(self, error): logging.exception("try to sleep if there are repeating errors.") error_desc = str(error) now = datetime.datetime.now() if error_desc not in self.error_time_log: self.error_time_log[error_desc] = now return time_of_l...
Try to detect repetitive errors and sleep for a while to avoid being marked as spam
def parse_isodate(datestr): m = isodate_rx.search(datestr) assert m, 'unrecognized date format: ' + datestr year, month, day = m.group('year', 'month', 'day') hour, minute, second, fraction = m.group('hour', 'minute', 'second', 'fraction') tz, tzhh, tzmm = m.group('tz', 'tzhh', 'tzmm') dt =...
Parse a string that loosely fits ISO 8601 formatted date-time string
def ls( self, rev, path, recursive=False, recursive_dirs=False, directory=False, report=() ): raise NotImplementedError
List directory or file :param rev: The revision to use. :param path: The path to list. May start with a '/' or not. Directories may end with a '/' or not. :param recursive: Recursively list files in subdirectories. :param recursive_dirs: Used when recursive=True, al...
def log( self, revrange=None, limit=None, firstparent=False, merges=None, path=None, follow=False ): raise NotImplementedError
Get commit logs :param revrange: Either a single revision or a range of revisions as a 2-element list or tuple. :param int limit: Limit the number of log entries. :param bool firstparent: Only follow the first parent of merges. :param bool merges: True means onl...
def user_create(self, cloudflare_email, cloudflare_pass, unique_id=None): params = { 'act': 'user_create', 'cloudflare_email': cloudflare_email, 'cloudflare_pass': cloudflare_pass } if unique_id: params['unique_id'] = unique_id ret...
Create new cloudflare user with selected email and id. Optionally also select unique_id which can be then used to get user information. :param cloudflare_email: new user cloudflare email :type cloudflare_email: str :param cloudflare_pass: new user cloudflare password ...
def zone_set(self, user_key, zone_name, resolve_to, subdomains): params = { 'act': 'zone_set', 'user_key': user_key, 'zone_name': zone_name, 'resolve_to': resolve_to, 'subdomains': subdomains, } return self._request(params)
Create new zone for user associated with this user_key. :param user_key: The unique 3auth string,identifying the user's CloudFlare Account. Generated from a user_create or user_auth :type user_key: str :param zone_name: The zone you'd like to run CNAMES through CloudFlare...
def full_zone_set(self, user_key, zone_name): params = { 'act': 'full_zone_set', 'user_key': user_key, 'zone_name': zone_name, } return self._request(params)
Create new zone and all subdomains for user associated with this user_key. :param user_key: The unique 3auth string,identifying the user's CloudFlare Account. Generated from a user_create or user_auth :type user_key: str :param zone_name: The zone you'd like to ru...
def user_lookup(self, cloudflare_email=None, unique_id=None): if not cloudflare_email and not unique_id: raise KeyError( 'Either cloudflare_email or unique_id must be present') params = {'act': 'user_lookup'} if cloudflare_email: params['cloudfla...
Lookup user data based on either his cloudflare_email or his unique_id. :param cloudflare_email: email associated with user :type cloudflare_email: str :param unique_id: unique id associated with user :type unique_id: str :returns: :r...
def user_auth( self, cloudflare_email=None, cloudflare_pass=None, unique_id=None ): if not (cloudflare_email and cloudflare_pass) and not unique_id: raise KeyError( 'Either cloudflare_email and cloudflare_pass or unique_id must be ...
Get user_key based on either his email and password or unique_id. :param cloudflare_email: email associated with user :type cloudflare_email: str :param cloudflare_pass: pass associated with user :type cloudflare_pass: str :param unique_id: unique id asso...
def zone_list( self, user_key, limit=100, offset=0, zone_name=None, sub_id=None, zone_status='ALL', sub_status='ALL', ): if zone_status not in ['V', 'D', 'ALL']: raise ValueError('zone_status has to be V, D or ALL')...
List zones for a user. :param user_key: key for authentication of user :type user_key: str :param limit: limit of zones shown :type limit: int :param offset: offset of zones to be shown :type offset: int :param zone_name: name of zone to...
def attr_exists(self, attr): gen = self.attr_gen(attr) n_instances = len(list(gen)) if n_instances > 0: return True else: return False
Returns True if at least on instance of the attribute is found
def datasets(self): HiisiHDF._clear_cache() self.visititems(HiisiHDF._is_dataset) return HiisiHDF.CACHE['dataset_paths']
Method returns a list of dataset paths. Examples -------- >>> for dataset in h5f.datasets(): print(dataset) '/dataset1/data1/data' '/dataset1/data2/data' '/dataset2/data1/data' '/dataset2/data2/data'
def groups(self): HiisiHDF._clear_cache() self.CACHE['group_paths'].append('/') self.visititems(HiisiHDF._is_group) return HiisiHDF.CACHE['group_paths']
Method returns a list of all goup paths Examples -------- >>> for group in h5f.groups(): print(group) '/' '/dataset1' '/dataset1/data1' '/dataset1/data2'
def attr_gen(self, attr): HiisiHDF._clear_cache() HiisiHDF.CACHE['search_attribute'] = attr HiisiHDF._find_attr_paths('/', self['/']) # Check root attributes self.visititems(HiisiHDF._find_attr_paths) path_attr_gen = (PathValue(attr_path, self[attr_path].attrs.get(attr))...
Returns attribute generator that yields namedtuples containing path value pairs Parameters ---------- attr : str Name of the search attribute Returns ------- attr_generator : generator Returns a generator that yields named tuples ...
def create_from_filedict(self, filedict): if self.mode in ['r+','w', 'w-', 'x', 'a']: for h5path, path_content in filedict.iteritems(): if path_content.has_key('DATASET'): # If path exist, write only metadata if h5path in self: ...
Creates h5 file from dictionary containing the file structure. Filedict is a regular dictinary whose keys are hdf5 paths and whose values are dictinaries containing the metadata and datasets. Metadata is given as normal key-value -pairs and dataset arrays are given using 'DATASE...
def search(self, attr, value, tolerance=0): found_paths = [] gen = self.attr_gen(attr) for path_attr_pair in gen: # if attribute is numerical use numerical_value_tolerance in # value comparison. If attribute is string require exact match if isinstance...
Find paths with a key value match Parameters ---------- attr : str name of the attribute value : str or numerical value value of the searched attribute Keywords -------- tolerance : float tolerance used when searching ...
def _correctIsotopeImpurities(matrix, intensities): correctedIntensities, _ = scipy.optimize.nnls(matrix, intensities) return correctedIntensities
Corrects observed reporter ion intensities for isotope impurities. :params matrix: a matrix (2d nested list) containing numbers, each isobaric channel must be present as a COLUMN. Use maspy.isobar._transposeMatrix() if channels are written in rows. :param intensities: numpy array of observed re...
def _normalizeImpurityMatrix(matrix): newMatrix = list() for line in matrix: total = sum(line) if total != 0: newMatrix.append([i / total for i in line]) else: newMatrix.append(line) return newMatrix
Normalize each row of the matrix that the sum of the row equals 1. :params matrix: a matrix (2d nested list) containing numbers, each isobaric channel must be present as a row. :returns: a matrix containing normalized values
def _padImpurityMatrix(matrix, preChannels, postChannels): extendedMatrix = list() lastMatrixI = len(matrix)-1 for i, line in enumerate(matrix): prePadding = itertools.repeat(0., i) postPadding = itertools.repeat(0., lastMatrixI-i) newLine = list(itertools.chain(prePadding, line...
Align the values of an isotope impurity matrix and fill up with 0. NOTE: The length of the rows in the "matrix" must be the sum of "preChannels" and "postChannels" + 1. :params matrix: a matrix (2d nested list) containing numbers, each isobaric channel must be present as a row. :pa...
def _processImpurityMatrix(self): processedMatrix = _normalizeImpurityMatrix(self.impurityMatrix) processedMatrix = _padImpurityMatrix( processedMatrix, self.matrixPreChannels, self.matrixPostChannels ) processedMatrix = _transposeMatrix(processedMatrix) ...
Process the impurity matrix so that it can be used to correct observed reporter intensities.
def exception(message): def decorator(method): """Inner decorator so we can accept arguments.""" @wraps(method) def wrapper(self, *args, **kwargs): """Innermost decorator wrapper - this is confusing.""" if self.messages: kwargs['message'] = args...
Exception method convenience wrapper.
def to_dict(self): val = dict(self.payload or ()) if self.message: val['message'] = self.message return val
Convert Exception class to a Python dictionary.
def init_app(self, app, config=None, statsd=None): if config is not None: self.config = config elif self.config is None: self.config = app.config self.messages = self.config.get('EXCEPTION_MESSAGE', True) self.prefix = self.config.get('EXCEPTION_PREFIX',...
Init Flask Extension.
def program(self): statements = [] if self.cur_token.type == TokenTypes.NEW_LINE: self.eat(TokenTypes.NEW_LINE) while self.cur_token.type != TokenTypes.EOF: statements += [self.statement()] return Block(statements)
program : (newline) statement | program statement
def statement(self): if self.cur_token.type == TokenTypes.VAR: self.tokenizer.start_saving(self.cur_token) self.variable() peek_var = self.cur_token self.tokenizer.replay() self.eat() if peek_var.type == TokenTypes.ASSIGN: ...
statement : assign_statement | expression | control | empty Feature For Loop adds: | loop Feature Func adds: | func | return statement
def assign_statement(self): left = self.variable() op = self.cur_token self.eat(TokenTypes.ASSIGN) right = self.expression() smt = None if Features.TYPE_ARRAY in self.features and isinstance(left, GetArrayItem): # Remake this as a setitem. ...
assign smt : variable ASSIGN expression(;) Feature Type Array adds: | variable SETITEM expression(;)
def control(self): self.eat(TokenTypes.IF) ctrl = self.expression() block = self.block() ifs = [If(ctrl, block)] else_block = Block() while self.cur_token.type == TokenTypes.ELIF: self.eat(TokenTypes.ELIF) ctrl = self.expression() ...
control : 'if' ctrl_exp block ('elif' ctrl_exp block)* ('else' block)
def loop(self): self.eat(TokenTypes.FOR_LOOP) init = NoOp() if self.cur_token.type != TokenTypes.SEMI_COLON: init = self.assign_statement() else: self.eat(TokenTypes.SEMI_COLON) ctrl = NoOp() if self.cur_token.type != TokenTypes.SEMI_COLO...
loop : 'for' init; ctrl; inc block
def func(self): self.eat(TokenTypes.FUNC) name = Var(self.cur_token) self.eat(TokenTypes.VAR) self.eat(TokenTypes.LPAREN) sig = self.param_list() self.eat(TokenTypes.RPAREN) block = self.block() return FunctionDef(name, Function(sig, block))
func : func name(paramlist) block
def param_list(self): params = [] while self.cur_token.type == TokenTypes.VAR: params.append(Var(self.cur_token)) self.eat(TokenTypes.VAR) if self.cur_token.type == TokenTypes.COMMA: self.eat(TokenTypes.COMMA) return FunctionSig(param...
paramlist : var, paramlist paramlist : var paramlist :
def arg_list(self, ending_char=TokenTypes.RPAREN): args = [] while not self.cur_token.type == ending_char: args.append(self.expression()) if self.cur_token.type == TokenTypes.COMMA: self.eat(TokenTypes.COMMA) return args
arglist : expression, arglist arglist : expression arglist :
def array_const(self): self.eat(TokenTypes.LBRACKET) node = Array(self.arg_list(TokenTypes.RBRACKET)) self.eat(TokenTypes.RBRACKET) return node
Feature Type Array adds: array : [ arglist ]
def block(self): statements = [] self.eat(TokenTypes.LBRACE) if self.cur_token.type == TokenTypes.NEW_LINE: self.eat(TokenTypes.NEW_LINE) while self.cur_token.type != TokenTypes.RBRACE: statements.append(self.statement()) self.eat(TokenTypes.RBRAC...
block : { (newline) statements } (newline)
def variable(self): var = Var(self.cur_token) self.eat(TokenTypes.VAR) if Features.TYPE_ARRAY in self.features: while self.cur_token.type == TokenTypes.LBRACKET: self.eat(TokenTypes.LBRACKET) # Start passed the logical ops. exp...
variable : variable Feature Type Array adds: variable : variable[expression] Feature Type Func adds: variable : variable(arg_list)
def wrap_node(self, node, options): '''\ celery registers tasks by decorating them, and so do we, so the user can pass a celery task and we'll wrap our code with theirs in a nice package celery can execute. ''' if 'celery_task' in options: return options['cele...
\ celery registers tasks by decorating them, and so do we, so the user can pass a celery task and we'll wrap our code with theirs in a nice package celery can execute.
def bfs(graph, start): # maintain a queue of paths queue = [] visited = [] # maintain a queue of nodes # push the first path into the queue queue.append([['', start]]) while queue: # get the first path from the queue path = queue.pop(0) # get the last node from t...
Finds the shortest string using BFS Args: graph (DFA): The DFA states start (DFA state): The DFA initial state Returns: str: The shortest string
def run(): # We override the program name to reflect that this script must be run with # the python executable. parser = argparse.ArgumentParser( prog='python -m braillegraph', description='Print a braille bar graph of the given integers.' ) # This flag sets the end string tha...
Display the arguments as a braille graph on standard output.
def _rnd_date(start, end): return date.fromordinal(random.randint(start.toordinal(), end.toordinal()))
Internal random date generator.
def rnd_date(start=date(1970, 1, 1), end=None, **kwargs): if end is None: end = date.today() start = parser.parse_date(start) end = parser.parse_date(end) _assert_correct_start_end(start, end) return _rnd_date(start, end)
Generate a random date between ``start`` to ``end``. :param start: Left bound :type start: string or datetime.date, (default date(1970, 1, 1)) :param end: Right bound :type end: string or datetime.date, (default date.today()) :return: a datetime.date object **中文文档** 随机生成一个位于 ``start`` 和 `...
def rnd_date_array(size, start=date(1970, 1, 1), end=None, **kwargs): if end is None: end = date.today() start = parser.parse_date(start) end = parser.parse_date(end) _assert_correct_start_end(start, end) return _randn(size, _rnd_date, start, end)
Array or Matrix of random date generator. :returns: 1d or 2d array of datetime.date
def rnd_date_list_high_performance(size, start=date(1970, 1, 1), end=None, **kwargs): if end is None: end = date.today() start_days = to_ordinal(parser.parse_datetime(start)) end_days = to_ordinal(parser.parse_datetime(end)) _assert_correct_start_end(start_days, end_days) if has_np: # ...
Generate mass random date. :param size: int, number of :param start: date similar object, int / str / date / datetime :param end: date similar object, int / str / date / datetime, default today's date :param kwargs: args placeholder :return: list of datetime.date
def rnd_datetime(start=datetime(1970, 1, 1), end=datetime.now()): start = parser.parse_datetime(start) end = parser.parse_datetime(end) _assert_correct_start_end(start, end) return _rnd_datetime(start, end)
Generate a random datetime between ``start`` to ``end``. :param start: Left bound :type start: string or datetime.datetime, (default datetime(1970, 1, 1)) :param end: Right bound :type end: string or datetime.datetime, (default datetime.now()) :return: a datetime.datetime object **中文文档** ...
def rnd_datetime_array(size, start=datetime(1970, 1, 1), end=None): if end is None: end = datetime.now() start = parser.parse_datetime(start) end = parser.parse_datetime(end) _assert_correct_start_end(start, end) return _randn(size, _rnd_datetime, start, end)
Array or Matrix of random datetime generator. :returns: 1d or 2d array of datetime.date
def day_interval(year, month, day, milliseconds=False, return_string=False): if milliseconds: # pragma: no cover delta = timedelta(milliseconds=1) else: delta = timedelta(seconds=1) start = datetime(year, month, day) end = datetime(year, month, day) + timedelta(days=1) - delta ...
Return a start datetime and end datetime of a day. :param milliseconds: Minimum time resolution. :param return_string: If you want string instead of datetime, set True Usage Example:: >>> start, end = rolex.day_interval(2014, 6, 17) >>> start datetime(2014, 6, 17, 0, 0, 0) ...
def month_interval(year, month, milliseconds=False, return_string=False): if milliseconds: # pragma: no cover delta = timedelta(milliseconds=1) else: delta = timedelta(seconds=1) if month == 12: start = datetime(year, month, 1) end = datetime(year + 1, 1, 1) - delta ...
Return a start datetime and end datetime of a month. :param milliseconds: Minimum time resolution. :param return_string: If you want string instead of datetime, set True Usage Example:: >>> start, end = rolex.month_interval(2000, 2) >>> start datetime(2000, 2, 1, 0, 0, 0) ...
def year_interval(year, milliseconds=False, return_string=False): if milliseconds: # pragma: no cover delta = timedelta(milliseconds=1) else: delta = timedelta(seconds=1) start = datetime(year, 1, 1) end = datetime(year + 1, 1, 1) - delta if not return_string: return ...
Return a start datetime and end datetime of a year. :param milliseconds: Minimum time resolution. :param return_string: If you want string instead of datetime, set True Usage Example:: >>> start, end = rolex.year_interval(2007) >>> start datetime(2007, 1, 1, 0, 0, 0) >>> ...
def renderfile(filename, options=None, templatePaths=None, default='', silent=False): if not mako: logger.debug('mako is not installed') return default if not mako: logger.debug('mako is not installed.') return def...
Renders a file to text using the mako template system. To learn more about mako and its usage, see [[www.makotemplates.org]] :return <str> formatted text
def collectfiles(path, filt=None): if not os.path.isdir(path): path = os.path.dirname(path) output = [] for name in sorted(os.listdir(path)): filepath = os.path.join(path, name) if os.path.isfile(filepath): if not filt or filt(name): output.append((n...
Collects some files based on the given filename. :param path | <str> filt | <method> :return [(<str> name, <str> filepath), ..]
def get_milestone(self, title): if not title: return GithubObject.NotSet if not hasattr(self, '_milestones'): self._milestones = {m.title: m for m in self.repo.get_milestones()} milestone = self._milestones.get(title) if not milestone: milest...
given the title as str, looks for an existing milestone or create a new one, and return the object
def get_assignee(self, login): if not login: return GithubObject.NotSet if not hasattr(self, '_assignees'): self._assignees = {c.login: c for c in self.repo.get_assignees()} if login not in self._assignees: # warning print("{} doesn't belo...
given the user login, looks for a user in assignee list of the repo and return it if was found.
def sender(self, issues): for issue in issues: state = self.get_state(issue.state) if issue.number: try: gh_issue = self.repo.get_issue(issue.number) original_state = gh_issue.state if original_state ==...
push a list of issues to github
def define(self, key, value): skey = nstr(key) self._defaults[skey] = value self[skey] = value
Defines the value for the inputted key by setting both its default and \ value to the inputted value. :param key | <str> value | <variant>
def toXml(self, xparent): for key, value in self.items(): elem = ElementTree.SubElement(xparent, 'entry') typ = type(elem).__name__ elem.set('key', key) elem.set('type', typ) if typ in DataSet._xmlTypes: DataSet._xmlTypes[typ...
Saves the settings for this dataset to the inputted parent xml. :param xparent | <xml.etree.ElementTree.Element>
def fromXml(cls, xparent): output = cls() for xentry in xparent: key = xentry.get('key') if not key: continue typ = xentry.get('type', 'str') if typ in DataSet._xmlTypes: value = DataSet._xmlTypes[typ][1](xentry)...
Loads the settings for this dataset to the inputted parent xml. :param xparent | <xml.etree.ElementTree.Element>
def registerXmlType(typ, encoder, decoder): DataSet._xmlTypes[nstr(typ)] = (encoder, decoder)
Registers a data type to encode/decode for xml settings. :param typ | <object> encoder | <method> decoder | <method>
def wrap_node(self, node, options): ''' we have the option to construct nodes here, so we can use different queues for nodes without having to have different queue objects. ''' job_kwargs = { 'queue': options.get('queue', 'default'), 'connection': options....
we have the option to construct nodes here, so we can use different queues for nodes without having to have different queue objects.
def _writeMzmlIndexList(xmlWriter, spectrumIndexList, chromatogramIndexList): counts = 0 if spectrumIndexList: counts += 1 if chromatogramIndexList: counts += 1 if counts == 0: return None #Create indexList node xmlIndexList = xmlWriter.element('indexList', {'count':...
#TODO: docstring :param xmlWriter: #TODO: docstring :param spectrumIndexList: #TODO: docstring :param chromatogramIndexList: #TODO: docstring
def _writeIndexListElement(xmlWriter, elementName, indexList): if indexList: xmlIndex = xmlWriter.element('index', {'name': elementName}) xmlIndex.__enter__() xmlWriter.write('\n') for offset, indexId in indexList: offsetElement = ETREE.Element('offset', {'idRef': in...
#TODO: docstring :param xmlWriter: #TODO: docstring :param elementName: #TODO: docstring :param indexList: #TODO: docstring
def _writeMzmlChecksum(xmlWriter, outputFile): sha = hashlib.sha1(outputFile.getvalue()) sha.update('<fileChecksum>') xmlChecksumElement = ETREE.Element('fileChecksum') xmlChecksumElement.text = sha.hexdigest() xmlWriter.write(xmlChecksumElement, pretty_print=True)
#TODO: docstring :param xmlWriter: #TODO: docstring :param outputFile: #TODO: docstring
def _writeIndexListOffset(xmlWriter, offset): xmlIndexListOffset = ETREE.Element('indexListOffset') xmlIndexListOffset.text = str(offset) xmlWriter.write(xmlIndexListOffset, pretty_print=True)
#TODO: docstring :param xmlWriter: #TODO: docstring :param offset: #TODO: docstring
def xmlGenScanList(scanList, scanListParams): numEntries = len(scanList) xmlScanList = ETREE.Element('scanList', {'count': str(numEntries)}) maspy.xml.xmlAddParams(xmlScanList, scanListParams) for scan in scanList: #Note: no attributes supported xmlScan = ETREE.Element('scan', {}) ...
#TODO: docstring :params scanList: #TODO: docstring :params scanListParams: #TODO: docstring :returns: #TODO: docstring
def xmlGenPrecursorList(precursorList): numEntries = len(precursorList) xmlPrecursorList = ETREE.Element('precursorList', {'count': str(numEntries)} ) for precursor in precursorList: #Note: no attributes for external refe...
#TODO: docstring :params precursorList: #TODO: docstring :returns: #TODO: docstring
def xmlSpectrumFromSmi(index, smi, sai=None, compression='zlib'): if sai is not None: arrayLength = [array.size for array in viewvalues(sai.arrays)] if len(set(arrayLength)) != 1: raise Exception('Unequal size for different array in sai.arrays') else: arrayLength...
#TODO: docstring :param index: The zero-based, consecutive index of the spectrum in the SpectrumList. (mzML specification) :param smi: a SpectrumMetadataItem instance :param sai: a SpectrumArrayItem instance, if none is specified no binaryDataArrayList is written :param compression: #TO...
def xmlChromatogramFromCi(index, ci, compression='zlib'): arrayLength = [array.size for array in viewvalues(ci.arrays)] if len(set(arrayLength)) != 1: raise Exception('Unequal size for different array in sai.arrays') else: arrayLength = arrayLength[0] chromatogramAttrib = {'index':...
#TODO: docstring :param index: #TODO: docstring :param ci: #TODO: docstring :param compression: #TODO: docstring :returns: #TODO: docstring
def uninstall_pgpm_from_db(self): drop_schema_cascade_script = 'DROP SCHEMA {schema_name} CASCADE;' if self._conn.closed: self._conn = psycopg2.connect(self._connection_string, connection_factory=pgpm.lib.utils.db.MegaConnection) cur = self._conn.cursor() # get cu...
Removes pgpm from db and all related metadata (_pgpm schema). Install packages are left as they are :return: 0 if successful and error otherwise
def save(self, *args, **kwargs): if self.pk is None: if hasattr(self, 'product'): if not self.description: self.description = self.product self.price_recommended = self.product.price_base elif hasattr(self, 'line_order'): ...
si al guardar una linea asociada a un documento bloqueado (lock==True), duplicar el documento en una nueva versión
def create_albaran_automatic(pk, list_lines): line_bd = SalesLineAlbaran.objects.filter(line_order__pk__in=list_lines).values_list('line_order__pk') if line_bd.count() == 0 or len(list_lines) != len(line_bd[0]): # solo aquellas lineas de pedidos que no estan ya albarandas ...
creamos de forma automatica el albaran
def create_invoice_from_albaran(pk, list_lines): context = {} if list_lines: new_list_lines = [x[0] for x in SalesLineAlbaran.objects.values_list('line_order__pk').filter( pk__in=[int(x) for x in list_lines] ).exclude(invoiced=True)] if new_li...
la pk y list_lines son de albaranes, necesitamos la info de las lineas de pedidos
def create_invoice_from_ticket(pk, list_lines): context = {} if list_lines: new_list_lines = [x[0] for x in SalesLineTicket.objects.values_list('line_order__pk').filter(pk__in=[int(x) for x in list_lines])] if new_list_lines: lo = SalesLineOrder.objects.v...
la pk y list_lines son de ticket, necesitamos la info de las lineas de pedidos
def set_options(self, options): with transaction.atomic(): for option in options: opt = self.line_basket_option_sales.filter( product_option=option['product_option'] ).first() if opt: # edit change = Fa...
options = [{ 'product_option': instance of ProductFinalOption, 'product_final': instance of ProductFinal, 'quantity': Float }, ]
def findmodules(path, recurse=False): output = set() roots = set() for root, folders, files in os.walk(path): # add packages for folder in folders: pkgpath = os.path.join(root, folder, '__init__.py') if os.path.exists(pkgpath): output.add(packageF...
Looks up the modules for the given path and returns a list of the packages. If the recurse flag is set to True, then it will look through the package recursively. :param path | <str> recurse | <bool> :return ([<str>, ..] modules, [<str>, ..] paths)
def importfile(filename): pkg = packageFromPath(filename, includeModule=True) root = packageRootPath(filename) if root not in sys.path: sys.path.insert(0, root) __import__(pkg) return sys.modules[pkg]
Imports a module specifically from a file. :param filename | <str> :return <module> || None
def importobject(module_name, object_name): if module_name not in sys.modules: try: __import__(module_name) except ImportError: logger.debug(traceback.print_exc()) logger.error('Could not import module: %s', module_name) return None module = ...
Imports the object with the given name from the inputted module. :param module_name | <str> object_name | <str> :usage |>>> import projex |>>> modname = 'projex.envmanager' |>>> attr = 'EnvManager' |>>> EnvManager = projex.impor...
def packageRootPath(path): path = nstr(path) if os.path.isfile(path): path = os.path.dirname(path) parts = os.path.normpath(path).split(os.path.sep) package_parts = [] for i in range(len(parts), 0, -1): filename = os.path.sep.join(parts[:i] + ['__init__.py']) if not o...
Returns the root file path that defines a Python package from the inputted path. :param path | <str> :return <str>
def packageFromPath(path, includeModule=False): path = nstr(path) module = '' if os.path.isfile(path): path, fname = os.path.split(path) if fname.endswith('.py') and fname != '__init__.py': module = fname.split('.')[0] parts = os.path.normpath(path).split(os.path.sep) ...
Determines the python package path based on the inputted path. :param path | <str> :return <str>
def website(app=None, mode='home', subcontext='UserGuide'): base_url = WEBSITES.get(mode, '') if app and base_url: opts = {'app': app, 'base_url': base_url} base_url = SUBCONTEXT_MAP.get((mode, subcontext), base_url) base_url %= opts return base_url
Returns the website location for projex software. :param app | <str> || None mode | <str> (home, docs, blog, dev) :return <str>
def _check_values(in_values): out_values = [] for value in in_values: # if isinstance(value, (dict, list)): # out_values.append(json.dumps(value)) # else: out_values.append(value) return tuple(out_values)
Check if values need to be converted before they get mogrify'd
def clone(srcpath, destpath, vcs=None): vcs = vcs or probe(srcpath) cls = _get_repo_class(vcs) return cls.clone(srcpath, destpath)
Clone an existing repository. :param str srcpath: Path to an existing repository :param str destpath: Desired path of new repository :param str vcs: Either ``git``, ``hg``, or ``svn`` :returns VCSRepo: The newly cloned repository If ``vcs`` is not given, then the repository type is discovered from...
def probe(path): import os from .common import UnknownVCSType if os.path.isdir(os.path.join(path, '.git')): return 'git' elif os.path.isdir(os.path.join(path, '.hg')): return 'hg' elif ( os.path.isfile(os.path.join(path, 'config')) and os.path.isdir(os.path.join(...
Probe a repository for its type. :param str path: The path of the repository :raises UnknownVCSType: if the repository type couldn't be inferred :returns str: either ``git``, ``hg``, or ``svn`` This function employs some heuristics to guess the type of the repository.