code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
for line in re.split(r'\n+', s): if line != '': self._logger.log(self._level, line)
def write(self, s)
Write message to logger.
5.203104
4.66709
1.11485
if not attrs: attrs = {} bases = base_type if isinstance(base_type, tuple) else (base_type,) self_type = [] if not trait_name: global trait_num trait_num += 1 trait_name = "trait%d" % trait_num def __init__(self, **kwargs): for arg, val in default_kwarg...
def make_property_type(name, base_type=Property, attrs=None, trait_name=None, **default_kwargs)
Makes a new ``Property`` type, which supplies the given arguments as defaults to the ``Property()`` constructor. The typical use of this function is to make types for the API you are mapping so that, for instance, any time they use a date you can convert it in a consistent way to a ``datetime.date``. ...
2.45505
2.48272
0.988855
if not self.bound: if self.name is not None: return "(unbound).%s" % self.name else: return "(unbound)" elif not self.class_(): classname = "(GC'd class)" else: classname = self.class_().__name__ ret...
def fullname(self)
Returns the name of the ``Record`` class this ``Property`` is attached to, and attribute name it is attached as.
4.319139
4.312448
1.001552
reaction = self._get_objective() if not self._mm.has_reaction(reaction): self.fail('Specified biomass reaction is not in model: {}'.format( reaction)) varying_reaction = self._args.varying if not self._mm.has_reaction(varying_reaction): ...
def run(self)
Run robustness command.
3.30809
3.244694
1.019538
names = tuple(names) for name in names: if name in self._variables: raise ValueError('Variable already defined: {!r}'.format(name)) lower = kwargs.get('lower', None) upper = kwargs.get('upper', None) vartype = kwargs.get('types', None) ...
def define(self, *names, **kwargs)
Define a variable in the problem. Variables must be defined before they can be accessed by var() or set(). This function takes keyword arguments lower and upper to define the bounds of the variable (default: -inf to inf). The keyword argument types can be used to select the type of the ...
2.049875
1.985776
1.032279
expression = relation.expression constr_count = sum(True for _ in expression.value_sets()) if constr_count == 0: return [] row_indices = count(swiglpk.glp_add_rows(self._p, constr_count)) names = [] for i, value_set in zip(row_indices, expression.v...
def _add_constraints(self, relation)
Add the given relation as one or more constraints. Return a list of the names of the constraints added.
2.586999
2.526634
1.023891
if isinstance(expression, numbers.Number): # Allow expressions with no variables as objective, # represented as a number expression = Expression(offset=expression) # Clear previous objective for i in range(swiglpk.glp_get_num_cols(self._p)): ...
def set_objective(self, expression)
Set objective of problem.
3.627645
3.535621
1.026028
if sense not in (ObjectiveSense.Minimize, ObjectiveSense.Maximize): raise ValueError('Invalid objective sense') swiglpk.glp_set_obj_dir(self._p, self.OBJ_SENSE_MAP[sense])
def set_objective_sense(self, sense)
Set type of problem (maximize or minimize).
5.476101
5.814217
0.941847
if sense is not None: self.set_objective_sense(sense) parm = swiglpk.glp_smcp() swiglpk.glp_init_smcp(parm) if self._do_presolve: parm.presolve = swiglpk.GLP_ON self._do_presolve = False else: parm.presolve = swiglpk.GLP_O...
def solve_unchecked(self, sense=None)
Solve problem and return result. The user must manually check the status of the result to determine whether an optimal solution was found. A :class:`SolverError` may still be raised if the underlying solver raises an exception.
2.995773
2.983578
1.004087
self._check_valid() if self._ret_val != 0: return False return swiglpk.glp_get_status(self._problem._p) == swiglpk.GLP_OPT
def success(self)
Return boolean indicating whether a solution was found.
8.22969
7.18105
1.146029
self._check_valid() if self._ret_val != 0: return self._ret_val == swiglpk.GLP_ENODFS return swiglpk.glp_get_status(self._problem._p) == swiglpk.GLP_UNBND
def unbounded(self)
Whether solution is unbounded
8.158327
7.563446
1.078652
self._check_valid() if self._ret_val == swiglpk.GLP_ENOPFS: return 'No primal feasible solution' elif self._ret_val == swiglpk.GLP_ENODFS: return 'No dual feasible solution' return str(swiglpk.glp_get_status(self._problem._p))
def status(self)
Return string indicating the error encountered on failure.
4.922712
4.285749
1.148623
return swiglpk.glp_get_col_prim( self._problem._p, self._problem._variables[variable])
def _get_value(self, variable)
Return value of variable in solution.
14.16309
11.371947
1.245441
return swiglpk.glp_mip_col_val( self._problem._p, self._problem._variables[variable])
def _get_value(self, variable)
Return value of variable in solution.
17.397009
14.89284
1.168146
if element in (Atom.N, Atom.O, Atom.P): return 0.4 elif isinstance(element, Radical): return 40.0 return 1.0
def default_weight(element)
Return weight of formula element. This implements the default weight proposed for MapMaker.
5.684744
6.113574
0.929856
for e, mf in form.items(): if e == Atom.H: continue yield e, mf, weight_func(e)
def _weighted_formula(form, weight_func)
Yield weight of each formula element.
10.588122
8.479464
1.248678
left = set(c for c, _ in reaction.left) right = set(c for c, _ in reaction.right) for c1, c2 in product(left, right): items = {} for e in elements: v = result.get_value(delta[c1, c2, e]) nearest_int = round(v) if abs(v - nearest_int) < epsilon: ...
def _transfers(reaction, delta, elements, result, epsilon)
Yield transfers obtained from result.
3.470467
3.458465
1.00347
def dict_from_iter_sum(it): d = {} for k, v in it: if k not in d: d[k] = 0 d[k] += v return d left = dict_from_iter_sum(reaction.left) right = dict_from_iter_sum(reaction.right) return left, right
def _reaction_to_dicts(reaction)
Convert a reaction to reduced left, right dictionaries.
2.997441
2.632663
1.138558
df = docker_fabric() create_kwargs = create_kwargs.copy() if create_kwargs else dict() start_kwargs = start_kwargs.copy() if start_kwargs else dict() create_kwargs.update(entrypoint=no_op_cmd) start_kwargs.update(restart_policy=None) container = df.create_container(image, **create_kwargs)['...
def temp_container(image, no_op_cmd='/bin/true', create_kwargs=None, start_kwargs=None)
Creates a temporary container, which can be used e.g. for copying resources. The container is removed once it is no longer needed. Note that ``no_op_cmd`` needs to be set appropriately, since the method will wait for the container to finish before copying resources. :param image: Image name or id to create...
2.379015
2.329159
1.021405
assert(issubclass(coll, Collection)) key = (coll.__name__, "%s.%s" % (of.__module__, of.__name__)) if key in GENERIC_TYPES: if GENERIC_TYPES[key].itemtype != of: raise exc.PropertyNotUnique(key=key) else: # oh, we get to name it? Goodie! generic_name = "%s%s" %...
def _make_generic(of, coll)
Used to make a new Collection type, without that type having to be defined explicitly. Generates a new type name using the item type and a 'suffix' Collection class property. args: ``of=``\ *Record type* The type of values of the collection ``coll=``\ *Collection sub-class* ...
4.1777
3.947893
1.05821
if isinstance(v, cls.itemtype): return v else: try: return cls.coerceitem(v) except Exception as e: raise exc.CollectionItemCoerceError( itemtype=cls.itemtype, colltype=cls, ...
def coerce_value(cls, v)
Coerce a value to the right type for the collection, or return it if it is already of the right type.
4.581007
4.136371
1.107494
for k, v in generator: yield k, cls.coerce_value(v)
def coerce_tuples(cls, generator)
This class method converts a generator of ``(K, V)`` tuples (the *tuple protocol*), where ``V`` is not yet of the correct type, to a generator where it is of the correct type (using the ``coerceitem`` class property)
4.830987
6.166481
0.783427
if cls != Collection: raise exc.CollectionDefinitionError( property='tuples_to_coll', coll='Collection', )
def tuples_to_coll(cls, generator, coerce=False)
*required virtual method* This class method, part of the sub-class API, converts a generator of ``(K, V)`` tuples (the *tuple protocol*) to one of the underlying collection type.
13.434743
15.965803
0.84147
if isinstance(coll, basestring): raise exc.CollectionCoerceError( passed=coll, colltype=cls, ) if isinstance(coll, collections.Mapping): i = 0 for k in sorted(coll.keys()): yield (i, coll[k]) ...
def coll_to_tuples(cls, coll)
``coll_to_tuples`` is capable of unpacking its own collection types (`list`), ``collections.Mapping`` objects, as well generators, sequences and iterators. Returns ``(*int*, Value)``. Does not coerce items.
2.682095
2.457194
1.091528
# perhaps: self[len(self):len(self)] = iterable self._values.extend(self.coerce_value(item) for item in iterable)
def extend(self, iterable)
Adds new values to the end of the collection, coercing items.
8.515615
7.33052
1.161666
pool = self.connection_pool command_name = args[0] connection = pool.get_connection(command_name, **options) try: connection.send_command(*args) return self.parse_response(connection, command_name, **options) except ConnectionError: co...
def execute_command(self, *args, **options)
Execute a command and return a parsed response.
2.513605
2.310625
1.087847
response = connection.read_response() if command_name in self.response_callbacks and len(response): status = nativestr(response[0]) if status == RES_STATUS.OK: return self.response_callbacks[command_name](response[1:], ...
def parse_response(self, connection, command_name, **options)
Parses a response from the ssdb server
4.500788
4.335752
1.038064
amount = get_integer('amount', amount) return self.execute_command('incr', name, amount)
def incr(self, name, amount=1)
Increase the value at key ``name`` by ``amount``. If no key exists, the value will be initialized as ``amount`` . Like **Redis.INCR** :param string name: the key name :param int amount: increments :return: the integer value at key ``name`` :rtype: int >>> ssdb....
9.999993
18.370592
0.544348
amount = get_positive_integer('amount', amount) return self.execute_command('decr', name, amount)
def decr(self, name, amount=1)
Decrease the value at key ``name`` by ``amount``. If no key exists, the value will be initialized as 0 - ``amount`` . Like **Redis.DECR** :param string name: the key name :param int amount: decrements :return: the integer value at key ``name`` :rtype: int >>> s...
7.3423
17.696913
0.414892
offset = get_positive_integer('offset', offset) return self.execute_command('getbit', name, offset)
def getbit(self, name, offset)
Returns a boolean indicating the value of ``offset`` in ``name`` Like **Redis.GETBIT** :param string name: the key name :param int offset: the bit position :param bool val: the bit value :return: the bit at the ``offset`` , ``False`` if key doesn't exist or offset exce...
7.804302
17.033466
0.458175
val = int(get_boolean('val', val)) offset = get_positive_integer('offset', offset) return self.execute_command('setbit', name, offset, val)
def setbit(self, name, offset, val)
Flag the ``offset`` in ``name`` as ``value``. Returns a boolean indicating the previous value of ``offset``. Like **Redis.SETBIT** :param string name: the key name :param int offset: the bit position :param bool val: the bit value :return: the previous b...
7.179129
9.80009
0.732557
if start is not None and size is not None: start = get_integer('start', start) size = get_integer('size', size) return self.execute_command('countbit', name, start, size) elif start is not None: start = get_integer('start', start) ...
def countbit(self, name, start=None, size=None)
Returns the count of set bits in the value of ``key``. Optional ``start`` and ``size`` paramaters indicate which bytes to consider. Similiar with **Redis.BITCOUNT** :param string name: the key name :param int start: Optional, if start is negative, count from start'th characte...
2.035408
2.485917
0.818776
if start is not None and size is not None: start = get_integer('start', start) size = get_integer('size', size) return self.execute_command('substr', name, start, size) elif start is not None: start = get_integer('start', start) ...
def substr(self, name, start=None, size=None)
Return a substring of the string at key ``name``. ``start`` and ``size`` are 0-based integers specifying the portion of the string to return. Like **Redis.SUBSTR** :param string name: the key name :param int start: Optional, the offset of first byte returned. If start is negat...
2.026202
2.550575
0.79441
limit = get_positive_integer('limit', limit) return self.execute_command('keys', name_start, name_end, limit)
def keys(self, name_start, name_end, limit=10)
Return a list of the top ``limit`` keys between ``name_start`` and ``name_end`` Similiar with **Redis.KEYS** .. note:: The range is (``name_start``, ``name_end``]. ``name_start`` isn't in the range, but ``name_end`` is. :param string name_start: The lower bound(not ...
4.698857
7.491353
0.627238
limit = get_positive_integer('limit', limit) return self.execute_command('scan', name_start, name_end, limit)
def scan(self, name_start, name_end, limit=10)
Scan and return a dict mapping key/value in the top ``limit`` keys between ``name_start`` and ``name_end`` in ascending order Similiar with **Redis.SCAN** .. note:: The range is (``name_start``, ``name_end``]. ``name_start`` isn't in the range, but ``name_end`` is. ...
5.589395
10.389544
0.537983
limit = get_positive_integer('limit', limit) return self.execute_command('rscan', name_start, name_end, limit)
def rscan(self, name_start, name_end, limit=10)
Scan and return a dict mapping key/value in the top ``limit`` keys between ``name_start`` and ``name_end`` in descending order .. note:: The range is (``name_start``, ``name_end``]. ``name_start`` isn't in the range, but ``name_end`` is. :param string name_start: The upper bound(not...
5.473828
11.411631
0.479671
amount = get_integer('amount', amount) return self.execute_command('hincr', name, key, amount)
def hincr(self, name, key, amount=1)
Increase the value of ``key`` in hash ``name`` by ``amount``. If no key exists, the value will be initialized as ``amount`` Like **Redis.HINCR** :param string name: the hash name :param string key: the key name :param int amount: increments :return: the ...
8.637113
13.611895
0.634527
amount = get_positive_integer('amount', amount) return self.execute_command('hdecr', name, key, amount)
def hdecr(self, name, key, amount=1)
Decrease the value of ``key`` in hash ``name`` by ``amount``. If no key exists, the value will be initialized as 0 - ``amount`` :param string name: the hash name :param string key: the key name :param int amount: increments :return: the integer value of ``key`` in hash ...
6.996498
10.937522
0.639679
limit = get_positive_integer('limit', limit) return self.execute_command('hkeys', name, key_start, key_end, limit)
def hkeys(self, name, key_start, key_end, limit=10)
Return a list of the top ``limit`` keys between ``key_start`` and ``key_end`` in hash ``name`` Similiar with **Redis.HKEYS** .. note:: The range is (``key_start``, ``key_end``]. The ``key_start`` isn't in the range, but ``key_end`` is. :param string name: the hash n...
3.966439
6.548961
0.605659
limit = get_positive_integer('limit', limit) return self.execute_command('hlist', name_start, name_end, limit)
def hlist(self, name_start, name_end, limit=10)
Return a list of the top ``limit`` hash's name between ``name_start`` and ``name_end`` in ascending order .. note:: The range is (``name_start``, ``name_end``]. The ``name_start`` isn't in the range, but ``name_end`` is. :param string name_start: The lower bound(not included) of has...
5.190182
7.848454
0.6613
limit = get_positive_integer('limit', limit) return self.execute_command('hrlist', name_start, name_end, limit)
def hrlist(self, name_start, name_end, limit=10)
Return a list of the top ``limit`` hash's name between ``name_start`` and ``name_end`` in descending order .. note:: The range is (``name_start``, ``name_end``]. The ``name_start`` isn't in the range, but ``name_end`` is. :param string name_start: The lower bound(not included) of ha...
5.267941
8.30824
0.634062
limit = get_positive_integer('limit', limit) return self.execute_command('hscan', name, key_start, key_end, limit)
def hscan(self, name, key_start, key_end, limit=10)
Return a dict mapping key/value in the top ``limit`` keys between ``key_start`` and ``key_end`` within hash ``name`` in ascending order Similiar with **Redis.HSCAN** .. note:: The range is (``key_start``, ``key_end``]. The ``key_start`` isn't in the range, but ``key_end`` is. ...
4.629068
7.65106
0.605023
limit = get_positive_integer('limit', limit) return self.execute_command('hrscan', name, key_start, key_end, limit)
def hrscan(self, name, key_start, key_end, limit=10)
Return a dict mapping key/value in the top ``limit`` keys between ``key_start`` and ``key_end`` within hash ``name`` in descending order .. note:: The range is (``key_start``, ``key_end``]. The ``key_start`` isn't in the range, but ``key_end`` is. :param string name: the hash name ...
4.559481
6.617145
0.689041
score = get_integer('score', score) return self.execute_command('zset', name, key, score)
def zset(self, name, key, score=1)
Set the score of ``key`` from the zset ``name`` to ``score`` Like **Redis.ZADD** :param string name: the zset name :param string key: the key name :param int score: the score for ranking :return: ``True`` if ``zset`` created a new score, otherwise ``False`` :rtype: bool...
5.807113
16.895021
0.343717
amount = get_integer('amount', amount) return self.execute_command('zincr', name, key, amount)
def zincr(self, name, key, amount=1)
Increase the score of ``key`` in zset ``name`` by ``amount``. If no key exists, the value will be initialized as ``amount`` Like **Redis.ZINCR** :param string name: the zset name :param string key: the key name :param int amount: increments :return: the integer ...
7.852611
13.962231
0.562418
amount = get_positive_integer('amount', amount) return self.execute_command('zdecr', name, key, amount)
def zdecr(self, name, key, amount=1)
Decrease the value of ``key`` in zset ``name`` by ``amount``. If no key exists, the value will be initialized as 0 - ``amount`` :param string name: the zset name :param string key: the key name :param int amount: increments :return: the integer value of ``key`` in zset ...
6.231215
10.458537
0.595802
for k,v in kvs.items(): kvs[k] = get_integer(k, int(v)) return self.execute_command('multi_zset', name, *dict_to_list(kvs))
def multi_zset(self, name, **kvs)
Return a dictionary mapping key/value by ``keys`` from zset ``names`` :param string name: the zset name :param list keys: a list of keys :return: the number of successful creation :rtype: int >>> ssdb.multi_zset('zset_4', a=100, b=80, c=90, d=70) 4 >>> s...
4.949935
5.912177
0.837244
limit = get_positive_integer('limit', limit) return self.execute_command('zlist', name_start, name_end, limit)
def zlist(self, name_start, name_end, limit=10)
Return a list of the top ``limit`` zset's name between ``name_start`` and ``name_end`` in ascending order .. note:: The range is (``name_start``, ``name_end``]. The ``name_start`` isn't in the range, but ``name_end`` is. :param string name_start: The lower bound(not included) of zse...
4.838526
8.15842
0.593072
limit = get_positive_integer('limit', limit) return self.execute_command('zrlist', name_start, name_end, limit)
def zrlist(self, name_start, name_end, limit=10)
Return a list of the top ``limit`` zset's name between ``name_start`` and ``name_end`` in descending order .. note:: The range is (``name_start``, ``name_end``]. The ``name_start`` isn't in the range, but ``name_end`` is. :param string name_start: The lower bound(not included) of zs...
4.899745
8.827537
0.555052
score_start = get_integer_or_emptystring('score_start', score_start) score_end = get_integer_or_emptystring('score_end', score_end) limit = get_positive_integer('limit', limit) return self.execute_command('zkeys', name, key_start, score_start, ...
def zkeys(self, name, key_start, score_start, score_end, limit=10)
Return a list of the top ``limit`` keys after ``key_start`` from zset ``name`` with scores between ``score_start`` and ``score_end`` .. note:: The range is (``key_start``+``score_start``, ``key_end``]. That means (key.score == score_start && key > key_start || key.score > score_s...
2.566931
3.321413
0.772843
offset = get_nonnegative_integer('offset', offset) limit = get_positive_integer('limit', limit) return self.execute_command('zrange', name, offset, limit)
def zrange(self, name, offset, limit)
Return a dict mapping key/score in a range of score from zset ``name`` between ``offset`` and ``offset+limit`` sorted in ascending order. Like **Redis.ZRANGE** .. warning:: This method is SLOW for large offset! :param string name: the zset name ...
3.828839
5.697499
0.672021
offset = get_nonnegative_integer('offset', offset) limit = get_positive_integer('limit', limit) return self.execute_command('zrrange', name, offset, limit)
def zrrange(self, name, offset, limit)
Return a dict mapping key/score in a range of score from zset ``name`` between ``offset`` and ``offset+limit`` sorted in descending order. .. warning:: This method is SLOW for large offset! :param string name: the zset name :param int offset: zero or positive...
4.170491
5.701943
0.731416
score_start = get_integer_or_emptystring('score_start', score_start) score_end = get_integer_or_emptystring('score_end', score_end) return self.execute_command('zcount', name, score_start, score_end)
def zcount(self, name, score_start, score_end)
Returns the number of elements in the sorted set at key ``name`` with a score between ``score_start`` and ``score_end``. Like **Redis.ZCOUNT** .. note:: The range is [``score_start``, ``score_end``] :param string name: the zset name :param int score_start: The minimum score re...
2.490213
3.55708
0.700072
score_start = get_integer_or_emptystring('score_start', score_start) score_end = get_integer_or_emptystring('score_end', score_end) return self.execute_command('zsum', name, score_start, score_end)
def zsum(self, name, score_start, score_end)
Returns the sum of elements of the sorted set stored at the specified key which have scores in the range [score_start,score_end]. .. note:: The range is [``score_start``, ``score_end``] :param string name: the zset name :param int score_start: The minimum score related to keys(...
2.638098
3.523144
0.748791
score_start = get_integer_or_emptystring('score_start', score_start) score_end = get_integer_or_emptystring('score_end', score_end) return self.execute_command('zavg', name, score_start, score_end)
def zavg(self, name, score_start, score_end)
Returns the average of elements of the sorted set stored at the specified key which have scores in the range [score_start,score_end]. .. note:: The range is [``score_start``, ``score_end``] :param string name: the zset name :param int score_start: The minimum score rela...
2.664558
3.44942
0.772466
rank_start = get_nonnegative_integer('rank_start', rank_start) rank_end = get_nonnegative_integer('rank_end', rank_end) return self.execute_command('zremrangebyrank', name, rank_start, rank_end)
def zremrangebyrank(self, name, rank_start, rank_end)
Remove the elements of the zset which have rank in the range [rank_start,rank_end]. .. note:: The range is [``rank_start``, ``rank_end``] :param string name: the zset name :param int rank_start: zero or positive,the start position :param int rank_end: zero or positive,t...
2.478261
3.77629
0.656269
score_start = get_integer_or_emptystring('score_start', score_start) score_end = get_integer_or_emptystring('score_end', score_end) return self.execute_command('zremrangebyscore', name, score_start, score_end)
def zremrangebyscore(self, name, score_start, score_end)
Delete the elements of the zset which have rank in the range [score_start,score_end]. .. note:: The range is [``score_start``, ``score_end``] :param string name: the zset name :param int score_start: The minimum score related to keys(included), empty string ``''`` mean...
2.532571
3.230421
0.783976
index = get_integer('index', index) return self.execute_command('qget', name, index)
def qget(self, name, index)
Get the element of ``index`` within the queue ``name`` :param string name: the queue name :param int index: the specified index, can < 0 :return: the value at ``index`` within queue ``name`` , or ``None`` if the element doesn't exist :rtype: string
7.138902
13.45685
0.530503
index = get_integer('index', index) return self.execute_command('qset', name, index, value)
def qset(self, name, index, value)
Set the list element at ``index`` to ``value``. :param string name: the queue name :param int index: the specified index, can < 0 :param string value: the element value :return: Unknown :rtype: True
6.636759
10.675834
0.621662
size = get_positive_integer("size", size) return self.execute_command('qpop_front', name, size)
def qpop_front(self, name, size=1)
Remove and return the first ``size`` item of the list ``name`` Like **Redis.LPOP** :param string name: the queue name :param int size: the length of result :return: the list of pop elements :rtype: list
5.674357
8.446221
0.671822
size = get_positive_integer("size", size) return self.execute_command('qpop_back', name, size)
def qpop_back(self, name, size=1)
Remove and return the last ``size`` item of the list ``name`` Like **Redis.RPOP** :param string name: the queue name :param int size: the length of result :return: the list of pop elements :rtype: list
5.642401
10.170583
0.554777
limit = get_positive_integer("limit", limit) return self.execute_command('qlist', name_start, name_end, limit)
def qlist(self, name_start, name_end, limit)
Return a list of the top ``limit`` keys between ``name_start`` and ``name_end`` in ascending order .. note:: The range is (``name_start``, ``name_end``]. ``name_start`` isn't in the range, but ``name_end`` is. :param string name_start: The lower bound(not included) of keys to be ...
4.75801
8.016243
0.593546
limit = get_positive_integer("limit", limit) return self.execute_command('qrlist', name_start, name_end, limit)
def qrlist(self, name_start, name_end, limit)
Return a list of the top ``limit`` keys between ``name_start`` and ``name_end`` in descending order .. note:: The range is (``name_start``, ``name_end``]. ``name_start`` isn't in the range, but ``name_end`` is. :param string name_start: The lower bound(not included) of keys to be ...
4.620597
7.854791
0.588252
offset = get_integer('offset', offset) limit = get_positive_integer('limit', limit) return self.execute_command('qrange', name, offset, limit)
def qrange(self, name, offset, limit)
Return a ``limit`` slice of the list ``name`` at position ``offset`` ``offset`` can be negative numbers just like Python slicing notation Similiar with **Redis.LRANGE** :param string name: the queue name :param int offset: the returned list will start at this offset :param int...
4.343047
6.770882
0.64143
start = get_integer('start', start) end = get_integer('end', end) return self.execute_command('qslice', name, start, end)
def qslice(self, name, start, end)
Return a slice of the list ``name`` between position ``start`` and ``end`` ``start`` and ``end`` can be negative numbers just like Python slicing notation Like **Redis.LRANGE** :param string name: the queue name :param int start: the returned list will start at this of...
3.677476
4.823005
0.762486
size = get_positive_integer("size", size) return self.execute_command('qtrim_front', name, size)
def qtrim_front(self, name, size=1)
Sets the list element at ``index`` to ``value``. An error is returned for out of range indexes. :param string name: the queue name :param int size: the max length of removed elements :return: the length of removed elements :rtype: int
6.331305
9.675284
0.654379
size = get_positive_integer("size", size) return self.execute_command('qtrim_back', name, size)
def qtrim_back(self, name, size=1)
Sets the list element at ``index`` to ``value``. An error is returned for out of range indexes. :param string name: the queue name :param int size: the max length of removed elements :return: the length of removed elements :rtype: int
5.983509
8.230494
0.726993
if isinstance(ttl, datetime.timedelta): ttl = ttl.seconds + ttl.days * 24 * 3600 ttl = get_positive_integer('ttl', ttl) return self.execute_command('setx', name, value, ttl)
def setx(self, name, value, ttl)
Set the value of key ``name`` to ``value`` that expires in ``ttl`` seconds. ``ttl`` can be represented by an integer or a Python timedelta object. Like **Redis.SETEX** :param string name: the key name :param string value: a string or an object can be converted to string ...
3.085786
4.138669
0.745599
address = _get_address(interface_name, IP6_PATTERN) if address and expand: return ':'.join(_expand_groups(address)) return address
def get_ip6_address(interface_name, expand=False)
Extracts the IPv6 address for a particular interface from `ifconfig`. :param interface_name: Name of the network interface (e.g. ``eth0``). :type interface_name: unicode :param expand: If set to ``True``, an abbreviated address is expanded to the full address. :type expand: bool :return: IPv6 addre...
5.754443
9.908932
0.580733
current_host = env.host_string roledefs = env.get('roledefs') if roledefs: return [role for role, hosts in six.iteritems(roledefs) if current_host in hosts] return []
def get_current_roles()
Determines the list of roles, that the current host is assigned to. If ``env.roledefs`` is not set, an empty list is returned. :return: List of roles of the current host. :rtype: list
4.296971
3.511662
1.223629
added = set() for rxnid in model.database.reactions: reaction = model.database.get_reaction(rxnid) if all(compound.compartment in compartments for compound, _ in reaction.compounds): if not model.has_reaction(rxnid): added.add(rxnid) m...
def add_all_database_reactions(model, compartments)
Add all reactions from database that occur in given compartments. Args: model: :class:`psamm.metabolicmodel.MetabolicModel`.
3.682669
3.659415
1.006355
all_reactions = {} if not allow_duplicates: # TODO: Avoid adding reactions that already exist in the database. # This should be integrated in the database. for rxnid in model.database.reactions: rx = model.database.get_reaction(rxnid) all_reactions[rx] = rxn...
def add_all_exchange_reactions(model, compartment, allow_duplicates=False)
Add all exchange reactions to database and to model. Args: model: :class:`psamm.metabolicmodel.MetabolicModel`.
3.446387
3.504352
0.983459
all_reactions = {} if not allow_duplicates: # TODO: Avoid adding reactions that already exist in the database. # This should be integrated in the database. for rxnid in model.database.reactions: rx = model.database.get_reaction(rxnid) all_reactions[rx] = rxn...
def add_all_transport_reactions(model, boundaries, allow_duplicates=False)
Add all transport reactions to database and to model. Add transport reactions for all boundaries. Boundaries are defined by pairs (2-tuples) of compartment IDs. Transport reactions are added for all compounds in the model, not just for compounds in the two boundary compartments. Args: mode...
3.118933
2.991792
1.042496
# Create metabolic model model_extended = model.create_metabolic_model() extra_compartment = model.extracellular_compartment compartment_ids = set(c.id for c in model.compartments) # Add database reactions to extended model if len(compartment_ids) > 0: logger.info( 'U...
def create_extended_model(model, db_penalty=None, ex_penalty=None, tp_penalty=None, penalties=None)
Create an extended model for gap-filling. Create a :class:`psamm.metabolicmodel.MetabolicModel` with all reactions added (the reaction database in the model is taken to be the universal database) and also with artificial exchange and transport reactions added. Return the extended :class:`psamm.meta...
2.430634
2.286302
1.063129
# Create a set of excluded reactions exclude = set(self._args.exclude) count = 0 unbalanced = 0 unchecked = 0 for reaction, result in formula_balance(self._model): count += 1 if reaction.id in exclude or reaction.equation is None: ...
def run(self)
Run formula balance command
3.746176
3.418185
1.095955
# Overwrite previous reaction if the same id is used if reaction_id in self._reactions: # Clean up compound to reaction mapping for compound in self._reactions[reaction_id]: self._compound_reactions[compound].remove(reaction_id) self._revers...
def set_reaction(self, reaction_id, reaction)
Set the reaction ID to a reaction given by a :class:`Reaction <psamm.reaction.Reaction>` If an existing reaction exists with the given reaction ID it will be overwritten.
2.880607
2.918578
0.98699
for other_database in self._databases: if other_database == database: break if other_database.has_reaction(reaction_id): return True return False
def _is_shadowed(self, reaction_id, database)
Whether reaction in database is shadowed by another database
3.523262
3.009433
1.17074
if args: msg = info % args else: msg = info try: puts('docker: {0}'.format(msg)) except UnicodeDecodeError: puts('docker: -- non-printable output --')
def push_log(self, info, level=None, *args, **kwargs)
Prints the log as usual for fabric output, enhanced with the prefix "docker". :param info: Log output. :type info: unicode :param level: Logging level. Has no effect here. :type level: int
6.745999
5.992764
1.125691
fastprint(progress_fmt(status, object_id, progress), end='\n')
def push_progress(self, status, object_id, progress)
Prints progress information. :param status: Status text. :type status: unicode :param object_id: Object that the progress is reported on. :type object_id: unicode :param progress: Progress bar. :type progress: unicode
17.63703
21.435392
0.822799
try: super(DockerFabricClient, self).close() finally: if self._tunnel is not None: self._tunnel.close()
def close(self)
Closes the connection and any tunnels created for it.
6.363379
4.448252
1.430535
self.push_log("Building image '{0}'.".format(tag)) set_raise_on_error(kwargs) try: return super(DockerFabricClient, self).build(tag, **kwargs) except DockerStatusError as e: error(e.message)
def build(self, tag, **kwargs)
Identical to :meth:`dockermap.client.base.DockerClientWrapper.build` with additional logging.
6.864617
5.483421
1.251886
name_str = " '{0}'".format(name) if name else "" self.push_log("Creating container{0} from image '{1}'.".format(name_str, image)) return super(DockerFabricClient, self).create_container(image, name=name, **kwargs)
def create_container(self, image, name=None, **kwargs)
Identical to :meth:`docker.api.container.ContainerApiMixin.create_container` with additional logging.
3.825607
3.473388
1.101405
self.push_log("Receiving tarball for resource '{0}:{1}' and storing as {2}".format(container, resource, local_filename)) super(DockerFabricClient, self).copy_resource(container, resource, local_filename)
def copy_resource(self, container, resource, local_filename)
Identical to :meth:`dockermap.client.base.DockerClientWrapper.copy_resource` with additional logging.
6.02731
5.090099
1.184124
self.push_log("Generating list of stopped containers.") set_raise_on_error(kwargs, False) return super(DockerFabricClient, self).cleanup_containers(include_initial=include_initial, exclude=exclude, **kwargs)
def cleanup_containers(self, include_initial=False, exclude=None, **kwargs)
Identical to :meth:`dockermap.client.docker_util.DockerUtilityMixin.cleanup_containers` with additional logging.
7.570753
6.449339
1.17388
self.push_log("Checking images for dependent images and containers.") set_raise_on_error(kwargs, False) return super(DockerFabricClient, self).cleanup_images(remove_old=remove_old, keep_tags=keep_tags, **kwargs)
def cleanup_images(self, remove_old=False, keep_tags=None, **kwargs)
Identical to :meth:`dockermap.client.docker_util.DockerUtilityMixin.cleanup_images` with additional logging.
6.914488
5.961001
1.159954
self.push_log("Fetching image '{0}' from registry.".format(image)) return super(DockerFabricClient, self).import_image(image=image, tag=tag, **kwargs)
def import_image(self, image=None, tag='latest', **kwargs)
Identical to :meth:`docker.api.image.ImageApiMixin.import_image` with additional logging.
5.061499
4.589543
1.102833
c_user = kwargs.pop('username', env.get('docker_registry_user')) c_pass = kwargs.pop('password', env.get('docker_registry_password')) c_mail = kwargs.pop('email', env.get('docker_registry_mail')) c_registry = kwargs.pop('registry', env.get('docker_registry_repository')) ...
def login(self, **kwargs)
Identical to :meth:`dockermap.client.base.DockerClientWrapper.login` with two enhancements: * additional logging; * login parameters can be passed through ``kwargs``, or set as default using the following ``env`` variables: * ``env.docker_registry_user`` (kwarg: ``username``), ...
2.395175
1.883828
1.27144
c_insecure = kwargs.pop('insecure_registry', env.get('docker_registry_insecure')) set_raise_on_error(kwargs) try: return super(DockerFabricClient, self).pull(repository, tag=tag, stream=stream, insecure_registry=c_insec...
def pull(self, repository, tag=None, stream=True, **kwargs)
Identical to :meth:`dockermap.client.base.DockerClientWrapper.pull` with two enhancements: * additional logging; * the ``insecure_registry`` flag can be passed through ``kwargs``, or set as default using ``env.docker_registry_insecure``.
4.946113
4.069039
1.215548
self.push_log("Restarting container '{0}'.".format(container)) super(DockerFabricClient, self).restart(container, **kwargs)
def restart(self, container, **kwargs)
Identical to :meth:`docker.api.container.ContainerApiMixin.restart` with additional logging.
5.923918
5.515943
1.073963
self.push_log("Fetching container list.") set_raise_on_error(kwargs) super(DockerFabricClient, self).remove_all_containers(**kwargs)
def remove_all_containers(self, **kwargs)
Identical to :meth:`dockermap.client.docker_util.DockerUtilityMixin.remove_all_containers` with additional logging.
11.983906
9.8023
1.222561
self.push_log("Removing container '{0}'.".format(container)) set_raise_on_error(kwargs) super(DockerFabricClient, self).remove_container(container, **kwargs)
def remove_container(self, container, **kwargs)
Identical to :meth:`dockermap.client.base.DockerClientWrapper.remove_container` with additional logging.
6.161995
5.386535
1.143963
self.push_log("Removing image '{0}'.".format(image)) set_raise_on_error(kwargs) super(DockerFabricClient, self).remove_image(image, **kwargs)
def remove_image(self, image, **kwargs)
Identical to :meth:`dockermap.client.base.DockerClientWrapper.remove_image` with additional logging.
6.788807
5.512656
1.231495
self.push_log("Receiving tarball for image '{0}' and storing as '{1}'".format(image, local_filename)) super(DockerFabricClient, self).save_image(image, local_filename)
def save_image(self, image, local_filename)
Identical to :meth:`dockermap.client.base.DockerClientWrapper.save_image` with additional logging.
6.901752
5.147666
1.340754
self.push_log("Starting container '{0}'.".format(container)) super(DockerFabricClient, self).start(container, **kwargs)
def start(self, container, **kwargs)
Identical to :meth:`docker.api.container.ContainerApiMixin.start` with additional logging.
6.486994
5.532892
1.172442
self.push_log("Stopping container '{0}'.".format(container)) super(DockerFabricClient, self).stop(container, **kwargs)
def stop(self, container, **kwargs)
Identical to :meth:`dockermap.client.base.DockerClientWrapper.stop` with additional logging.
6.117976
5.054846
1.210319
self.push_log("Waiting for container '{0}'.".format(container)) super(DockerFabricClient, self).wait(container, **kwargs)
def wait(self, container, **kwargs)
Identical to :meth:`docker.api.container.ContainerApiMixin.wait` with additional logging.
6.560351
5.629671
1.165317
min_value = -_INF if min is None else min max_value = _INF if max is None else max return lambda fget: RangedProperty( fget, fmin=lambda obj: min_value, fmax=lambda obj: max_value)
def ranged_property(min=None, max=None)
Decorator for creating ranged property with fixed bounds.
4.293843
3.915213
1.096707
if self._prop.fget is None: raise AttributeError('Unable to read attribute') return self._prop.fget(self._obj)
def value(self)
Value of property.
6.068571
4.772518
1.271566
if self._prop.fmin is None: return -_INF return self._prop.fmin(self._obj)
def min(self)
Minimum value.
11.089862
10.05645
1.102761
if self._prop.fmax is None: return _INF return self._prop.fmax(self._obj)
def max(self)
Maximum value.
11.293666
10.109247
1.117162