code
stringlengths
52
7.75k
docs
stringlengths
1
5.85k
def jenkins(self): job_name = self.format['jenkins_job_name'].format(**self.data) job = {'name': job_name} return job
Generate jenkins job details.
def gitlab(self): main_name = self.format['git_repo'].format(**self.data) qe_name = self.format['git_repo_qe'].format(**self.data) config_name = self.format['git_repo_configs'].format(**self.data) git = { 'config': config_name, 'main': main_name, ...
Generate gitlab details.
def get_value_matched_by_regex(field_name, regex_matches, string): try: value = regex_matches.group(field_name) if value is not None: return value except IndexError: pass raise MissingFieldError(string, field_name)
Ensure value stored in regex group exists.
def positive_int(val): if isinstance(val, float): raise ValueError('"{}" must not be a float'.format(val)) val = int(val) if val >= 0: return val raise ValueError('"{}" must be positive'.format(val))
Parse `val` into a positive integer.
def strictly_positive_int_or_none(val): val = positive_int_or_none(val) if val is None or val > 0: return val raise ValueError('"{}" must be strictly positive'.format(val))
Parse `val` into either `None` or a strictly positive integer.
def oboTermParser(filepath): with io.open(filepath) as openfile: lineIter = iter([i.rstrip() for i in openfile.readlines()]) #Iterate through lines until the first obo "[Term]" is encountered try: line = next(lineIter) while line != '[Term]': line = next(lineIter) ...
Read a obo file and yield '[Term]' entries. :param filepath: file path of the .obo file :yields: lists containing all lines from a obo '[Term]' entry. Lines are not processed and still contain the newline character.
def _attributeLinesToDict(attributeLines): attributes = dict() for line in attributeLines: attributeId, attributeValue = line.split(':', 1) attributes[attributeId.strip()] = attributeValue.strip() return attributes
Converts a list of obo 'Term' lines to a dictionary. :param attributeLines: a list of obo 'Term' lines. Each line contains a key and a value part which are separated by a ':'. :return: a dictionary containing the attributes of an obo 'Term' entry. NOTE: Some attributes can occur multiple times in...
def _termIsObsolete(oboTerm): isObsolete = False if u'is_obsolete' in oboTerm: if oboTerm[u'is_obsolete'].lower() == u'true': isObsolete = True return isObsolete
Determine wheter an obo 'Term' entry is marked as obsolete. :param oboTerm: a dictionary as return by :func:`maspy.ontology._attributeLinesToDict()` :return: bool
def load(self, filepath): for attributeLines in oboTermParser(filepath): oboTerm = _attributeLinesToDict(attributeLines) if oboTerm['id'] not in self.oboTerms: self.oboTerms[oboTerm['id']] = oboTerm else: oldOboTerm = self....
Import '[Term]' entries from an .obo file.
def discover_handler_classes(handlers_package): if handlers_package is None: return # Add working directory into PYTHONPATH to import developer packages sys.path.insert(0, os.getcwd()) package = import_module(handlers_package) # Continue searching for module if package is not a modul...
Looks for handler classes within handler path module. Currently it's not looking deep into nested module. :param handlers_package: module path to handlers :type handlers_package: string :return: list of handler classes
def request(self, method, path, query=None, content=None): if not path.startswith("/"): raise ClientError("Implementation error: Called with bad path %s" % path) body = None if content is not None: data = self._json_encoder.encode...
Sends an HTTP request. This constructs a full URL, encodes and decodes HTTP bodies, and handles invalid responses in a pythonic way. @type method: string @param method: HTTP method to use @type path: string @param path: HTTP URL path @type query: list of two-tup...
def start(self): version = yield self.request("get", "/version") if version != 2: raise GanetiApiError("Can't work with Ganeti RAPI version %d" % version) log.msg("Accessing Ganeti RAPI, version %d" % version, system="Gentl...
Confirm that we may access the target cluster.
def get_multi_word_keywords(features): keys = { 'is not': Token(TokenTypes.NOT_EQUAL, 'is not'), } return OrderedDict(sorted(list(keys.items()), key=lambda t: len(t[0]), reverse=True))
This returns an OrderedDict containing the multi word keywords in order of length. This is so the tokenizer will match the longer matches before the shorter matches
def start(self): Server().start(self.options,self.handler_function, self.__class__.component_type)
Start the server and run forever.
def get_reverse(self): if self.sort in FLOAT_ATTRIBUTES: return True elif self.sort in NONFLOAT_ATTRIBUTES: return False else: raise InvalidSortError(self.sort)
By default, Cable entries are sorted by rating and Broadcast ratings are sorted by time. By default, float attributes are sorted from highest to lowest and non-float attributes are sorted alphabetically (show, net) or chronologically (time).
def sort_func(self, entry): key = entry[self.sort] if self.sort in FLOAT_ATTRIBUTES and not isinstance(key, float): return 0 # If value is 'n/a' string elif self.sort == 'time': return convert_time(key) elif self.sort == 'date': return conve...
Return the key attribute to determine how data is sorted. Time will need to be converted to 24 hour time. In instances when float attributes will have an 'n/a' string, return 0.
def sort_entries(self): return sorted(self.data, key=self.sort_func, reverse=self.get_reverse())
Get whether reverse is True or False. Return the sorted data.
def visible_fields(self): form_visible_fields = self.form.visible_fields() if self.render_fields: fields = self.render_fields else: fields = [field.name for field in form_visible_fields] filtered_fields = [field for field in fields if field not in self...
Returns the reduced set of visible fields to output from the form. This method respects the provided ``fields`` configuration _and_ exlcudes all fields from the ``exclude`` configuration. If no ``fields`` where provided when configuring this fieldset, all visible fields minus the exclu...
def get_fieldsets(self, fieldsets=None): fieldsets = fieldsets or self.fieldsets if not fieldsets: raise StopIteration # Search for primary marker in at least one of the fieldset kwargs. has_primary = any(fieldset.get('primary') for fieldset in fieldsets) ...
This method returns a generator which yields fieldset instances. The method uses the optional fieldsets argument to generate fieldsets for. If no fieldsets argument is passed, the class property ``fieldsets`` is used. When generating the fieldsets, the method ensures that at least one fielset ...
def generate_binding_credentials(self, binding): uri = self.clusters.get(binding.instance.get_cluster(), None) if not uri: raise ErrClusterConfig(binding.instance.get_cluster()) # partial credentials creds = {"username" : self.generate_binding_usern...
Generate binding credentials This function will permit to define the configuration to connect to the instance. Those credentials will be stored on a secret and exposed to a a Pod. We should at least returns the 'username' and 'password'. Args: ...
def generate_binding_permissions(self, binding, permissions): permissions.add_roles(binding.instance.get_dbname(), [RoleSpecs.dbAdmin, RoleSpecs.readWrite]) return permissions
Generate Users pemissions on the database Defining roles to the database for the users. We can pass extra information into parameters of the binding if needed (see binding.parameters). Args: binding (AtlasServiceBinding.Binding): A binding permissions (a...
def get_chunks(Array, Chunksize): for i in range(0, len(Array), Chunksize): yield Array[i:i + Chunksize]
Generator that yields chunks of size ChunkSize
def read_data_from_bin_file(fileName): with open(fileName, mode='rb') as file: # b is important -> binary fileContent = file.read() (ChannelData, LenOf1Channel, NumOfChannels, SampleTime) = read_data_from_bytes(fileContent) return ChannelData, LenOf1Channel, NumOfChannels, SampleTime
Loads the binary data stored in the a binary file and extracts the data for each channel that was saved, along with the sample rate and length of the data array. Parameters ---------- fileContent : bytes bytes object containing the data from a .bin file exported from the saleae da...
def read_data_from_bytes(fileContent): TotalDataLen = struct.unpack('Q', fileContent[:8])[0] # Unsigned long long NumOfChannels = struct.unpack('I', fileContent[8:12])[0] # unsigned Long SampleTime = struct.unpack('d', fileContent[12:20])[0] AllChannelData = struct.unpack("f" * ((len(fileContent)...
Takes the binary data stored in the binary string provided and extracts the data for each channel that was saved, along with the sample rate and length of the data array. Parameters ---------- fileContent : bytes bytes object containing the data from a .bin file exported from the ...
def interpret_waveform(fileContent, RelativeChannelNo): (ChannelData, LenOf1Channel, NumOfChannels, SampleTime) = read_data_from_bytes(fileContent) if RelativeChannelNo > NumOfChannels-1: raise ValueError("There are {} channels saved, you attempted to read relative channel number {}. Pick a r...
Extracts the data for just 1 channel and computes the corresponding time array (in seconds) starting from 0. Important Note: RelativeChannelNo is NOT the channel number on the Saleae data logger it is the relative number of the channel that was saved. E.g. if you save channels 3, 7 and 10, the co...
def getApi(): api = Blueprint('health', __name__, url_prefix='/') @api.route('health', methods=['GET']) def health(): '''Health check''' return jsonify({ "status" : True}) return api
Get Api for /health Returns: Blueprint: section for healt check
def get_coord_box(centre_x, centre_y, distance): """Todo: return coordinates inside a circle, rather than a square""" return { 'top_left': (centre_x - distance, centre_y + distance), 'top_right': (centre_x + distance, centre_y + distance), 'bottom_left': (centre_x - distance, centre...
Get the square boundary coordinates for a given centre and distance
def fleet_ttb(unit_type, quantity, factories, is_techno=False, is_dict=False, stasis_enabled=False): unit_weights = { UNIT_SCOUT: 1, UNIT_DESTROYER: 13, UNIT_BOMBER: 10, UNIT_CRUISER: 85, UNIT_STARBASE: 1, } govt_weight = 80 if is_dict else 100 prod_weight ...
Calculate the time taken to construct a given fleet
def parse_fasta(data): # pragma: no cover name, seq = None, [] for line in data: line = line.rstrip() if line.startswith('>'): if name: yield Sequence(name, ''.join(seq)) name, seq = line, [] else: seq.append(line) if name: ...
Load sequences in Fasta format. This generator function yields a Sequence object for each sequence record in a GFF3 file. Implementation stolen shamelessly from http://stackoverflow.com/a/7655072/459780.
def _resolve_features(self): for parentid in self.featsbyparent: parent = self.featsbyid[parentid] for child in self.featsbyparent[parentid]: parent.add_child(child, rangecheck=self.strict) # Replace top-level multi-feature reps with a pseudo-feature ...
Resolve Parent/ID relationships and yield all top-level features.
def _reset(self): self.records = list() self.featsbyid = dict() self.featsbyparent = dict() self.countsbytype = dict()
Clear internal data structure.
def get_by_label(self, label): return next((x for x in self if x.label == label), None)
Return the first item with a specific label, or None.
def getGenericAnswers(self, name, instruction, prompts): responses = [] for prompt, _echo in prompts: password = self.getPassword(prompt) responses.append(password) return defer.succeed(responses)
Called when the server requests keyboard interactive authentication
def pairwise(iterable): iterator = iter(iterable) try: first = next(iterator) except StopIteration: return for element in iterator: yield first, element first = element
Generate consecutive pairs of elements from the given iterable.
def pick_cert_for_twisted(netloc, possible): try: creds = possible[netloc] except KeyError: return (None, ()) key = ssl.KeyPair.load(creds.key.as_bytes(), FILETYPE_PEM) return ( ssl.PrivateCertificate.load( creds.chain.certificates[0].as_bytes(), key, FILETYPE_P...
Pick the right client key/certificate to use for the given server and return it in the form Twisted wants. :param NetLocation netloc: The location of the server to consider. :param dict[TLSCredentials] possible: The available credentials from which to choose. :return: A two-tuple. If no crede...
def pick_trust_for_twisted(netloc, possible): try: trust_cert = possible[netloc] except KeyError: return None cert = ssl.Certificate.load(trust_cert.as_bytes(), FILETYPE_PEM) return ssl.trustRootFromCertificates([cert])
Pick the right "trust roots" (certificate authority certificates) for the given server and return it in the form Twisted wants. Kubernetes certificates are often self-signed or otherwise exist outside of the typical certificate authority cartel system common for normal websites. This function tries to...
def https_policy_from_config(config): server = config.cluster["server"] base_url = URL.fromText(native_string_to_unicode(server)) ca_certs = pem.parse(config.cluster["certificate-authority"].bytes()) if not ca_certs: raise ValueError("No certificate authority certificate found.") ca_ce...
Create an ``IPolicyForHTTPS`` which can authenticate a Kubernetes API server. :param KubeConfig config: A Kubernetes configuration containing an active context identifying a cluster. The resulting ``IPolicyForHTTPS`` will authenticate the API server for that cluster. :return IPolicyForHTT...
def authenticate_with_certificate_chain(reactor, base_url, client_chain, client_key, ca_cert): if base_url.scheme != u"https": raise ValueError( "authenticate_with_certificate() makes sense for HTTPS, not {!r}".format( base_url.scheme ), ) netloc = N...
Create an ``IAgent`` which can issue authenticated requests to a particular Kubernetes server using a client certificate. :param reactor: The reactor with which to configure the resulting agent. :param twisted.python.url.URL base_url: The base location of the Kubernetes API. :param list[pem.C...
def authenticate_with_certificate(reactor, base_url, client_cert, client_key, ca_cert): return authenticate_with_certificate_chain( reactor, base_url, [client_cert], client_key, ca_cert, )
See ``authenticate_with_certificate_chain``. :param pem.Certificate client_cert: The client certificate to use.
def authenticate_with_serviceaccount(reactor, **kw): config = KubeConfig.from_service_account(**kw) policy = https_policy_from_config(config) token = config.user["token"] agent = HeaderInjectingAgent( _to_inject=Headers({u"authorization": [u"Bearer {}".format(token)]}), _agent=Agent...
Create an ``IAgent`` which can issue authenticated requests to a particular Kubernetes server using a service account token. :param reactor: The reactor with which to configure the resulting agent. :param bytes path: The location of the service account directory. The default should work fine for ...
def first_time_setup(self): if not self._auto_unlock_key_position(): pw = password.create_passwords()[0] attrs = {'application': self.keyring} gkr.item_create_sync(self.default_keyring ,gkr.ITEM_GENERIC_SECRET ...
First time running Open Sesame? Create keyring and an auto-unlock key in default keyring. Make sure these things don't already exist.
def _auto_unlock_key_position(self): found_pos = None default_keyring_ids = gkr.list_item_ids_sync(self.default_keyring) for pos in default_keyring_ids: item_attrs = gkr.item_get_attributes_sync(self.default_keyring, pos) app = 'application' if item_a...
Find the open sesame password in the default keyring
def get_position_searchable(self): ids = gkr.list_item_ids_sync(self.keyring) position_searchable = {} for i in ids: item_attrs = gkr.item_get_attributes_sync(self.keyring, i) position_searchable[i] = item_attrs['searchable'] return position_searchable
Return dict of the position and corrasponding searchable str
def _match_exists(self, searchable): position_searchable = self.get_position_searchable() for pos,val in position_searchable.iteritems(): if val == searchable: return pos return False
Make sure the searchable description doesn't already exist
def save_password(self, password, **attrs): pos_of_match = self._match_exists(attrs['searchable']) if pos_of_match: old_password = self.get_password(pos_of_match).get_secret() gkr.item_delete_sync(self.keyring, pos_of_match) desc = str(int(time.time())) + "_"...
Save the new password, save the old password with the date prepended
def parse_url(self): url = urlparse(self.url).path # handle git url = url.split('.git')[0] if ':' in url: url = url.split(':')[1] # Ony capture last two list items try: project, repo = url.split('/')[-2:] except ValueError: ...
Parse a git/ssh/http(s) url.
def _fetch_dimensions(self, dataset): yield Dimension(u"school") yield Dimension(u"year", datatype="year") yield Dimension(u"semester", datatype="academic_term", dialect="swedish") # HT/VT yield Dimension(u...
Iterate through semesters, counties and municipalities.
def _merge_configs(configs): result = { u"contexts": [], u"users": [], u"clusters": [], u"current-context": None, } for config in configs: for k in {u"contexts", u"users", u"clusters"}: try: values = config.doc[k] except Ke...
Merge one or more ``KubeConfig`` objects. :param list[KubeConfig] configs: The configurations to merge. :return KubeConfig: A single configuration object with the merged configuration.
def _merge_configs_from_env(kubeconfigs): paths = list( FilePath(p) for p in kubeconfigs.split(pathsep) if p ) config = _merge_configs(list( KubeConfig.from_file(p.path) for p in paths )) return config
Merge configuration files from a ``KUBECONFIG`` environment variable. :param bytes kubeconfigs: A value like the one given to ``KUBECONFIG`` to specify multiple configuration files. :return KubeConfig: A configuration object which has merged all of the configuration from the specified configur...
def network_kubernetes_from_context( reactor, context=None, path=None, environ=None, default_config_path=FilePath(expanduser(u"~/.kube/config")), ): if path is None: if environ is None: from os import environ try: kubeconfigs = environ[u"KUBECONFIG"] ...
Create a new ``IKubernetes`` provider based on a kube config file. :param reactor: A Twisted reactor which will be used for I/O and scheduling. :param unicode context: The name of the kube config context from which to load configuration details. Or, ``None`` to respect the current con...
def collection_location(obj): # TODO kind is not part of IObjectLoader and we should really be loading # apiVersion off of this object too. kind = obj.kind apiVersion = obj.apiVersion prefix = version_to_segments[apiVersion] collection = kind.lower() + u"s" if IObject.providedBy(obj)...
Get the URL for the collection of objects like ``obj``. :param obj: Either a type representing a Kubernetes object kind or an instance of such a type. :return tuple[unicode]: Some path segments to stick on to a base URL to construct the location of the collection of objects like the one ...
def enter_new_scope(ctx): ctx = ctx.clone() ctx.waiting_for = ctx.compiled_story().children_matcher() return ctx
we inside new scope with it onw :param ctx: :return:
def iterate_storyline(ctx): logger.debug('# start iterate') compiled_story = ctx.compiled_story() if not compiled_story: return for step in range(ctx.current_step(), len(compiled_story.story_line)): ctx = ctx.clone() tail = ctx.stack_tail() ctx...
iterate the last storyline from the last visited story part :param ctx: :return:
def scope_in(ctx): logger.debug('# scope_in') logger.debug(ctx) ctx = ctx.clone() compiled_story = None if not ctx.is_empty_stack(): compiled_story = ctx.get_child_story() logger.debug('# child') logger.debug(compiled_story) # we match child story loop once by m...
- build new scope on the top of stack - and current scope will wait for it result :param ctx: :return:
def scope_out(ctx): logger.debug('# scope_out') logger.debug(ctx) # we reach the end of story line # so we could collapse previous scope and related stack item if ctx.is_tail_of_story() and ctx.could_scope_out(): logger.debug('# [<] return') ctx = ctx.clone() ctx.message...
drop last stack item if: - we have reach the end of stack - and don't wait any input :param ctx: :return:
def str2date(self, date_str): # try default date template try: a_datetime = datetime.strptime( date_str, self._default_date_template) return a_datetime.date() except: pass # try every date templates for template in dat...
Parse date from string. If there's no template matches your string, Please go https://github.com/MacHu-GWU/rolex-project/issues submit your datetime string. I 'll update templates ASAP. This method is faster than :meth:`dateutil.parser.parse`. :param date_str: a string represe...
def _str2datetime(self, datetime_str): # try default datetime template try: a_datetime = datetime.strptime( datetime_str, self._default_datetime_template) return a_datetime except: pass # try every datetime templates f...
Parse datetime from string. If there's no template matches your string, Please go https://github.com/MacHu-GWU/rolex-project/issues submit your datetime string. I 'll update templates ASAP. This method is faster than :meth:`dateutil.parser.parse`. :param datetime_str: a string...
def parse_date(self, value): if isinstance(value, sixmini.string_types): return self.str2date(value) elif value is None: raise TypeError("Unable to parse date from %r" % value) elif isinstance(value, sixmini.integer_types): return date.fromordinal(val...
A lazy method to parse anything to date. If input data type is: - string: parse date from it - integer: use from ordinal - datetime: use date part - date: just return it
def parse_datetime(self, value): if isinstance(value, sixmini.string_types): return self.str2datetime(value) elif value is None: raise TypeError("Unable to parse datetime from %r" % value) elif isinstance(value, sixmini.integer_types): return from_utc...
A lazy method to parse anything to datetime. If input data type is: - string: parse datetime from it - integer: use from ordinal - date: use date part and set hour, minute, second to zero - datetime: just return it
def define(self): if len(self.states) == 0: for char in self.alphabet: self.add_arc(0, 0, char) self[0].final = False
If DFA is empty, create a sink state
def add_state(self): sid = len(self.states) self.states.append(DFAState(sid)) return sid
Adds a new state
def add_arc(self, src, dst, char): # assert type(src) == type(int()) and type(dst) == type(int()), \ # "State type should be integer." # assert char in self.I # #print self.states #print src for s_idx in [src, dst]: if s_idx >= len(self.st...
Adds a new Arc Args: src (int): The source state identifier dst (int): The destination state identifier char (str): The character for the transition Returns: None
def complement(self, alphabet): states = sorted(self.states, key=attrgetter('initial'), reverse=True) for state in states: if state.final: state.final = False else: state.final = True
Returns the complement of DFA Args: alphabet (list): The input alphabet Returns: None
def init_from_acceptor(self, acceptor): self.states = copy.deepcopy(acceptor.states) self.alphabet = copy.deepcopy(acceptor.alphabet) self.osyms = copy.deepcopy(acceptor.osyms) self.isyms = copy.deepcopy(acceptor.isyms)
Adds a sink state Args: alphabet (list): The input alphabet Returns: None
def load(self, txt_fst_file_name): with open(txt_fst_file_name, 'r') as input_filename: for line in input_filename: line = line.strip() split_line = line.split() if len(split_line) == 1: self[int(split_line[0])].final = Tru...
Save the transducer in the text file format of OpenFST. The format is specified as follows: arc format: src dest ilabel olabel [weight] final state format: state [weight] lines may occur in any order except initial state must be first line Args: txt_fst_file_n...
def intersect(self, other): operation = bool.__and__ self.cross_product(other, operation) return self
Constructs an unminimized DFA recognizing the intersection of the languages of two given DFAs. Args: other (DFA): The other DFA that will be used for the intersect operation Returns: Returns: DFA: The resulting DFA
def symmetric_difference(self, other): operation = bool.__xor__ self.cross_product(other, operation) return self
Constructs an unminimized DFA recognizing the symmetric difference of the languages of two given DFAs. Args: other (DFA): The other DFA that will be used for the symmetric difference operation Returns: DFA: The resulting DFA
def union(self, other): operation = bool.__or__ self.cross_product(other, operation) return self
Constructs an unminimized DFA recognizing the union of the languages of two given DFAs. Args: other (DFA): The other DFA that will be used for the union operation Returns: DFA: The resulting DFA
def _epsilon_closure(self, state): closure = set([state.stateid]) stack = [state] while True: if not stack: break s = stack.pop() for arc in s: if self.isyms.find(arc.ilabel) != EPSILON or \ arc....
Returns the \epsilon-closure for the state given as input.
def invert(self): for state in self.states: if state.final: state.final = False else: state.final = True
Inverts the DFA final states
def as_list(self): if hasattr(self, 'cust_list'): return self.cust_list if hasattr(self, 'attr_check'): self.attr_check() cls_bltns = set(dir(self.__class__)) ret = [a for a in dir(self) if a not in cls_bltns and getattr(self, a)] return r...
returns a list version of the object, based on it's attributes
def as_dict(self): if hasattr(self, 'cust_dict'): return self.cust_dict if hasattr(self, 'attr_check'): self.attr_check() cls_bltns = set(dir(self.__class__)) return {a: getattr(self, a) for a in dir(self) if a not in cls_bltns}
returns an dict version of the object, based on it's attributes
def as_odict(self): if hasattr(self, 'cust_odict'): return self.cust_odict if hasattr(self, 'attr_check'): self.attr_check() odc = odict() for attr in self.attrorder: odc[attr] = getattr(self, attr) return odc
returns an odict version of the object, based on it's attributes
def fetch_and_parse(url, bodyLines): pageHtml = fetch_page(url) return parse(url, pageHtml, bodyLines)
Takes a url, and returns a dictionary of data with 'bodyLines' lines
def copy_rec(source, dest): if os.path.isdir(source): for child in os.listdir(source): new_dest = os.path.join(dest, child) os.makedirs(new_dest, exist_ok=True) copy_rec(os.path.join(source, child), new_dest) elif os.path.isfile(source): logging.info(' ...
Copy files between diferent directories. Copy one or more files to an existing directory. This function is recursive, if the source is a directory, all its subdirectories are created in the destination. Existing files in destination are overwrited without any warning. Args: source (str): F...
def build(self): signed = bool(self.options() & Builder.Options.Signed) # remove previous build information buildpath = self.buildPath() if not buildpath: raise errors.InvalidBuildPath(buildpath) # setup the environment for key, value in self.enviro...
Builds this object into the desired output information.
def generateRevision(self): revpath = self.sourcePath() if not os.path.exists(revpath): return # determine the revision location revfile = os.path.join(revpath, self.revisionFilename()) mode = '' # test for svn revision try: args ...
Generates the revision file for this builder.
def generateZipFile(self, outpath='.'): fname = self.installName() + '.zip' outfile = os.path.abspath(os.path.join(outpath, fname)) # clears out the exiting archive if os.path.exists(outfile): try: os.remove(outfile) except OSError: ...
Generates the zip file for this builder.
def installName(self): opts = {'name': self.name(), 'version': self.version()} if self.revision(): opts['revision'] = '.{0}'.format(self.revision()) else: opts['revision'] = '' if self._installName: return self._installName.format(**opts) ...
Returns the name for the installer this builder will generate. :return <str>
def licenseFile(self): if self._licenseFile: return self._licenseFile elif self._license: f = projex.resources.find('licenses/{0}.txt'.format(self.license())) return f else: return ''
Returns the license file for this builder. :return <str>
def sign(self, filename): sign = self.signcmd() certificate = self.certificate() if not sign: log.error('No signcmd defined.') return False elif not certificate and '{cert}' in sign: log.error('No sign certificated defined.') retur...
Signs the filename with the certificate associated with this builder. :param filename | <str> :return <bool> | success
def plugin(name, module=''): if module: mod = projex.importfile(module) if mod: return getattr(mod, nstr(name), None) return Builder._plugins.get(nstr(name))
Returns the plugin for the given name. By default, the base Builder instance will be returned. :param name | <str>
def register(plugin, name=None): if name is None: name = plugin.__name__ Builder._plugins[nstr(name)] = plugin
Registers the given builder as a plugin to the system. :param plugin | <subclass of PackageBuilder> name | <str> || None
def fromXml(cls, xdata, filepath=''): builder = cls() builder.loadXml(xdata, filepath=filepath) return builder
Generates a new builder from the given xml data and then loads its information. :param xdata | <xml.etree.ElementTree.Element> :return <Builder> || None
def fromYaml(cls, ydata, filepath=''): builder = cls() builder.loadYaml(ydata, filepath=filepath) return builder
Generates a new builder from the given yaml data and then loads its information. :param ydata | <dict> :return <Builder> || None
def fromFile(filename): xdata = None ydata = None # try parsing an XML file try: xdata = ElementTree.parse(filename).getroot() except StandardError: xdata = None if xdata is None: # try parsing a yaml file if yaml...
Parses the inputted xml file information and generates a builder for it. :param filename | <str> :return <Builder> || None
def fromXml(cls, xdata, filepath=''): module = None pkg_data = xdata.find('package') if pkg_data is not None: path = pkg_data.find('path').text name = pkg_data.find('name').text if filepath: path = os.path.join(filepath, path) ...
Generates a new builder from the given xml data and then loads its information. :param xdata | <xml.etree.ElementTree.Element> :return <Builder> || None
def fromYaml(cls, ydata, filepath=''): module = None pkg_data = ydata.get('package') if pkg_data is not None: path = pkg_data.get('path', '') name = pkg_data.get('name', '') if filepath: path = os.path.join(filepath, path) ...
Generates a new builder from the given xml data and then loads its information. :param ydata | <xml.etree.ElementTree.Element> :return <Builder> || None
def to_object(item): def convert(item): if isinstance(item, dict): return IterableObject({k: convert(v) for k, v in item.items()}) if isinstance(item, list): def yield_convert(item): for index, value in enumerate(item): ...
Convert a dictionary to an object (recursive).
def to_dict(item): def convert(item): if isinstance(item, IterableObject): if isinstance(item.source, dict): return {k: convert(v.source) if hasattr(v, 'source') else convert(v) for k, v in item} else: return convert(it...
Convert an object to a dictionary (recursive).
def step_undefined_step_snippet_should_exist_for(context, step): undefined_step_snippet = make_undefined_step_snippet(step) context.execute_steps(u'''\ Then the command output should contain: """ {undefined_step_snippet} """ '''.format(undefined_step_snippet=text_indent(undefined_step_snipp...
Checks if an undefined-step snippet is provided for a step in behave command output (last command). EXAMPLE: Then an undefined-step snippet should exist for "Given an undefined step"
def step_undefined_step_snippet_should_not_exist_for(context, step): undefined_step_snippet = make_undefined_step_snippet(step) context.execute_steps(u'''\ Then the command output should not contain: """ {undefined_step_snippet} """ '''.format(undefined_step_snippet=text_indent(undefined_st...
Checks if an undefined-step snippet is provided for a step in behave command output (last command).
def step_undefined_step_snippets_should_exist_for_table(context): assert context.table, "REQUIRES: table" for row in context.table.rows: step = row["Step"] step_undefined_step_snippet_should_exist_for(context, step)
Checks if undefined-step snippets are provided. EXAMPLE: Then undefined-step snippets should exist for: | Step | | When an undefined step is used | | Then another undefined step is used |
def step_undefined_step_snippets_should_not_exist_for_table(context): assert context.table, "REQUIRES: table" for row in context.table.rows: step = row["Step"] step_undefined_step_snippet_should_not_exist_for(context, step)
Checks if undefined-step snippets are not provided. EXAMPLE: Then undefined-step snippets should not exist for: | Step | | When an known step is used | | Then another known step is used |
async def create_connection( host, port, *, loop=None, secure=True, ssl_context=None, **kwargs, ): loop = loop or asyncio.get_event_loop() secure = True if port == 443 else secure connection = HTTP2ClientConnection(host, loop=loop, secure=secure) if not isinstance(ssl_c...
Open an HTTP/2 connection to the specified host/port.
def mixin (cls): cls._events = {} cls.bind = Pyevent.bind.__func__ cls.unbind = Pyevent.unbind.__func__ cls.trigger = Pyevent.trigger.__func__ return cls
A decorator which adds event methods to a class giving it the ability to bind to and trigger events :param cls: the class to add the event logic to :type cls: class :return: the modified class :rtype: class
def bind (self, event, callback): if self._events.has_key(event): self._events[event].append(callback) else: self._events[event] = [callback]
Bind an event to a call function and ensure that it is called for the specified event :param event: the event that should trigger the callback :type event: str :param callback: the function that should be called :rtype callback: function
def unbind (self, event, callback): if self._events.has_key(event) and len(self._events[event]) > 0: for _callback in self._events[event]: if _callback == callback: self._events[event].remove(callback) if len(self._events[event]) == 0: ...
Unbind the callback from the event and ensure that it is never called :param event: the event that should be unbound :type event: str :param callback: the function that should be unbound :rtype callback: function
def trigger (self, event, *args, **kwargs): if self._events.has_key(event): for _callback in self._events[event]: try: _callback(args, kwargs) except TypeError: _callback()
Cause the callbacks associated with the event to be called :param event: the event that occurred :type event: str :param data: optional data to pass to the callback :type data: anything that should be passed to the callback
def get_wordlist(lang, wl_dir, po_path): #print("Looking for Wordlist in:\nlang {}\nwl_dir {}\npo_path {}".format(lang, wl_dir, po_path)) po_path = os.path.abspath(po_path) if wl_dir is not None: wl_path = os.path.join(wl_dir, lang + '.txt') if os.path.isfile(wl...
If wl_dir is given, there may be a file called "<lang>.txt". If this is the case, this should be the wordlist we are looking for.