def parse_subrepos(ctx): sub = util.OrderedDict() if '.hgsub' in ctx: sub = util.parse_hgsub(ctx['.hgsub'].data().splitlines()) substate = util.OrderedDict() if '.hgsubstate' in ctx: substate = util.parse_hgsubstate( ctx['.hgsubstate'].data().splitlines()) return sub, substate
def __init__(self): util.OrderedDict.__init__(self) self.paths = util.OrderedDict() self.options_filepath = os.path.join(__saveDir__, constants.options_filename) self.load()
def configDictValidator(d): newdict = util.OrderedDict() # values are config keys that the user specified that don't match any # valid key # keys are the correct configuration key undefined_key_matches = {} # Go through the keys the user gave us and make sure they're all valid. for key in d.iterkeys(): if key not in config: # Try to find a probable match match = _get_closest_match(key, config.iterkeys()) if match and ignore_undefined: # Save this for later. It only matters if this is a typo of # some required key that wasn't specified. (If all required # keys are specified, then this should be ignored) undefined_key_matches[match] = key newdict[key] = d[key] elif match: raise ValidationException( "'%s' is not a configuration item. Did you mean '%s'?" % (key, match)) elif not ignore_undefined: raise ValidationException( "'%s' is not a configuration item" % key) else: # the key is to be ignored. Copy it as-is to the `newdict` # to be returned. It shouldn't conflict, and may be used as # a default value for a render configdict later on. newdict[key] = d[key] # Iterate through the defined keys in the configuration (`config`), # checking each one to see if the user specified it (in `d`). Then # validate it and copy the result to `newdict` for configkey, configsetting in config.iteritems(): if configkey in d: # This key /was/ specified in the user's dict. Make sure it validates. newdict[configkey] = configsetting.validator(d[configkey]) elif configsetting.default is not None: # There is a default, use that instead newdict[configkey] = configsetting.validator( configsetting.default) elif configsetting.required: # The user did not give us this key, there is no default, AND # it's required. This is an error. if configkey in undefined_key_matches: raise ValidationException( "Key '%s' is not a valid " "configuration item. Did you mean '%s'?" % (undefined_key_matches[configkey], configkey)) else: raise ValidationException( "Required key '%s' was not " "specified. You must give a value for this setting" % configkey) return newdict
def create_operator_permutation_tests(oplist, depth, repeat, update): op_permutations = itertools.product(oplist, repeat=repeat) tests = [] for ops in op_permutations: next_char = 'a' next_selector = selector = {} for i in range(0, depth): for op, obj in ops: next_selector[op] = obj tests.append((util.OrderedDict(selector), update)) next_selector[next_char] = {} next_selector = next_selector[next_char] next_char = chr(ord(next_char) + 1) return tests
def _handle_subrepos(self, ctx, dirty_trees): substate = util.parse_hgsubstate(ctx['.hgsubstate'].data().splitlines()) sub = util.OrderedDict() if '.hgsub' in ctx: sub = util.parse_hgsub(ctx['.hgsub'].data().splitlines()) for path, sha in substate.iteritems(): # Ignore non-Git repositories keeping state in .hgsubstate. if path in sub and not sub[path].startswith('[git]'): continue d = os.path.dirname(path) dirty_trees.add(d) tree = self._dirs.setdefault(d, dulobjs.Tree()) tree.add(os.path.basename(path), dulobjs.S_IFGITLINK, sha)
def v(d): newd = util.OrderedDict() for key, value in d.iteritems(): newd[keyvalidator(key)] = valuevalidator(value) return newd
def readResults(input_buf = None, settings = None, has_header = True): ''' Converts an Intersplunk-formatted file object into a dict representation of the contained events. ''' if input_buf == None: input_buf = sys.stdin results = [] if settings == None: settings = {} # dummy if has_header: # until we get a blank line, read "attr:val" lines, setting the values in 'settings' attr = last_attr = None while True: line = input_buf.readline() line = line[:-1] # remove lastcharacter(newline) if len(line) == 0: break colon = line.find(':') if colon < 0: if last_attr: settings[attr] = settings[attr] + '\n' + urllib.unquote(line) else: continue # extract it and set value in settings last_attr = attr = line[:colon] val = urllib.unquote(line[colon+1:]) settings[attr] = val csvr = csv.reader(input_buf) header = [] first = True mv_fields = [] for line in csvr: if first: header = line first = False # Check which fields are multivalued (for a field 'foo', '__mv_foo' also exists) if MV_ENABLED: for field in header: if "__mv_" + field in header: mv_fields.append(field) continue # need to maintain field order import util result = util.OrderedDict() i = 0 for val in line: result[header[i]] = val i = i+1 for key in mv_fields: mv_key = "__mv_" + key if key in result and mv_key in result: # Expand the value of __mv_[key] to a list, store it in key, and delete __mv_[key] vals = [] if decodeMV(result[mv_key], vals): result[key] = copy.deepcopy(vals) if len(result[key]) == 1: result[key] = result[key][0] del result[mv_key] results.append(result) return results
del entities[sid] if sortKey: reverse = True if sortDir == 'asc': reverse = False try: entities = sorted(entities.items(), key=lambda x: x[1].__dict__[sortKey], reverse=reverse) except KeyError, e: logger.warn( "Attempted to sort on a key (%s) from a saved search's history that doesn't exist" % sortKey) return util.OrderedDict(entities) def getSavedSearchJobs(label, namespace=None, owner=None, ignoreExpired=True, ignoreRunning=False, sortKey='createTime', sortDir='desc', sessionKey=None, hostPath=None, **kw): '''Retrieve the saved search's history as search.SearchJob objects.''' jobs = []
import platform import sys # renders is a dictionary mapping strings to dicts. These dicts describe the # configuration for that render. Therefore, the validator for 'renders' is set # to a dict validator configured to validate keys as strings and values as... # values are set to validate as a "configdict", which is a dict mapping a set # of strings to some value. the make_configdictvalidator() function creates a # validator to use here configured with the given set of keys and Setting # objects with their respective validators. # config file. renders = Setting( required=True, default=util.OrderedDict(), validator=make_dictValidator( validateStr, make_configDictValidator({ "world": Setting(required=True, validator=validateStr, default=None), "dimension": Setting(required=True, validator=validateDimension, default="default"), "title": Setting(required=True, validator=validateStr, default=None), "rendermode": Setting(required=True, validator=validateRenderMode, default='normal'),
# Options database for the package. Reference to the dict is stored in the __init__ file from __future__ import with_statement # Needed for python 2.5 import constants, util from . import OptionWarning, DirectoryPathWarning, ExecutablePathWarning import os __saveDir__ = os.path.realpath(os.path.dirname(__file__)) if 'site-packages.zip' in __saveDir__ and 'Resources' in __saveDir__: __saveDir__ = __saveDir__[:__saveDir__.find('Resources') + 9] # If its in an app. __default_general__ = util.OrderedDict(constants.default_general) __default_paths__ = util.OrderedDict(constants.default_paths) class OptionsDict(util.OrderedDict): """Options for the molecbio.rosetta package. Is itself an OrderedDict object, so can be accessed and modified using the standard dictionary interface. The paths to all of the rosetta executables are stored in another OrderedDict object, which can be accessed at self.paths. Changes will be good for one session only unless the save method is used. """ def __init__(self): util.OrderedDict.__init__(self) self.paths = util.OrderedDict() self.options_filepath = os.path.join(__saveDir__, constants.options_filename) self.load()