Beispiel #1
0
 def optik_option(self, provider, opt_name, opt_dict):
     """get our personal option definition and return a suitable form for
     use with optik/optparse
     """
     opt_dict = copy(opt_dict)
     if opt_dict.has_key('action'):
         self._nocallback_options[provider] = opt_name
     else:
         opt_dict['action'] = 'callback'
         opt_dict['callback'] = self.cb_set_provider_option
     for specific in ('default', 'group', 'inputlevel'):
         if opt_dict.has_key(specific):
             del opt_dict[specific]
             if (OPTPARSE_FORMAT_DEFAULT
                 and specific == 'default' and opt_dict.has_key('help')):
                 opt_dict['help'] += ' [current: %default]'
     args = ['--' + opt_name]
     if opt_dict.has_key('short'):
         self._short_options[opt_dict['short']] = opt_name
         args.append('-' + opt_dict['short'])
         del opt_dict['short']
     available_keys = set(self._optik_parser.option_class.ATTRS)
     for key in opt_dict.keys():
         if not key in available_keys:
             opt_dict.pop(key)
     return args, opt_dict
Beispiel #2
0
 def get_column(self, col_index, distinct=False):
     """Returns the 'col_index' col
     """
     warn("table.get_column(i) is deprecated, use table[:,i] instead", DeprecationWarning, stacklevel=2)
     col = [row[col_index] for row in self.data]
     if distinct:
         return set(col)
     else:
         return col
Beispiel #3
0
 def get_column(self, col_index, distinct=False):
     """Returns the 'col_index' col
     """
     warn('table.get_column(i) is deprecated, use table[:,i] instead',
          DeprecationWarning,
          stacklevel=2)
     col = [row[col_index] for row in self.data]
     if distinct:
         return set(col)
     else:
         return col
Beispiel #4
0
 def wrapped(node, context=None, _func=func, **kwargs):
     """wrapper function handling context"""
     if context is None:
         context = InferenceContext(node)
     context.push(node)
     yielded = set()
     try:
         for res in _func(node, context, **kwargs):
             # unproxy only true instance, not const, tuple, dict...
             if res.__class__ is Instance:
                 ares = res._proxied
             else:
                 ares = res
             if not ares in yielded:
                 yield res
                 yielded.add(ares)
         context.pop()
     except:
         context.pop()
         raise
Beispiel #5
0
def read_old_config(newconfig, changes, configfile):
    """initialize newconfig from a deprecated configuration file
    
    possible changes:
    * ('renamed', oldname, newname)
    * ('moved', option, oldgroup, newgroup)
    * ('typechanged', option, oldtype, newvalue)
    """
    # build an index of changes
    changesindex = {}
    for action in changes:
        if action[0] == 'moved':
            option, oldgroup, newgroup = action[1:]
            changesindex.setdefault(option, []).append((action[0], oldgroup, newgroup))
            continue
        if action[0] == 'renamed':
            oldname, newname = action[1:]
            changesindex.setdefault(newname, []).append((action[0], oldname))
            continue
        if action[0] == 'typechanged':
            option, oldtype, newvalue = action[1:]
            changesindex.setdefault(option, []).append((action[0], oldtype, newvalue))
            continue        
        if action[1] in ('added', 'removed'):
            continue # nothing to do here
        raise Exception('unknown change %s' % action[0])    
    # build a config object able to read the old config
    options = []
    for optname, optdef in newconfig.options:
        for action in changesindex.pop(optname, ()):
            if action[0] == 'moved':
                oldgroup, newgroup = action[1:]
                optdef = optdef.copy()
                optdef['group'] = oldgroup
            elif action[0] == 'renamed':
                optname = action[1]
            elif action[0] == 'typechanged':
                oldtype = action[1]
                optdef = optdef.copy()
                optdef['type'] = oldtype
        options.append((optname, optdef))
    if changesindex:
        raise Exception('unapplied changes: %s' % changesindex)
    oldconfig = Configuration(options=options, name=newconfig.name)
    # read the old config
    oldconfig.load_file_configuration(configfile)
    # apply values reverting changes
    changes.reverse()
    done = set()
    for action in changes:
        if action[0] == 'renamed':
            oldname, newname = action[1:]
            newconfig[newname] = oldconfig[oldname]
            done.add(newname)
        elif action[0] == 'typechanged':
            optname, oldtype, newvalue = action[1:]
            newconfig[optname] = newvalue
            done.add(optname)
    for optname, optdef in newconfig.options:
        if not optname in done:
            newconfig.set_option(optname, oldconfig[optname], opt_dict=optdef)