示例#1
0
 def set_values(self, args=sys.argv[1:], set_default=False):
     """
     Examine the command line (args) and set values in the pool.
     if `set_default`, the default value (and not the value) is set.
     """
     from parampool.tree.Tree import get_leaf
     for i, arg in enumerate(args):
         if arg.startswith('--'):
             arg = arg[2:]  # strip off leading --
             try:
                 data_item = get_leaf(arg, self.options2data_items)
             except ValueError:
                 raise ValueError('%s is not a unique data item name '
                       'among\n%s' % ('--' + arg,
                       ', '.join(['--' + opt
                                  for opt in
                                  self.options2data_items])))
             if i+1 >= len(args):
                 raise ValueError('no value for command-line option %s'
                                  % arg)
             value = args[i+1]
             if set_default:
                 data_item.data['default'] = value
             else:
                 data_item.set_value(value)
示例#2
0
 def get(self, data_item_name):
     """
     Return ``DataItem`` object corresponding to `data_item_name`,
     which can be a unique valid abbreviation of the full name.
     """
     if not hasattr(self, 'paths2data_items'):
         raise ValueError(
             'pool.get("%s") does not work because pool construction is not finalized with pool.update()'
             % data_item_name)
     try:
         return get_leaf(data_item_name, self.paths2data_items)
     except ValueError:
         raise ValueError(
             '%s is not a unique data item name '
             'among\n%s' %
             (data_item_name, ', '.join(self.paths2data_items.keys())))
示例#3
0
文件: Pool.py 项目: hplgit/parampool
 def get(self, data_item_name):
     """
     Return ``DataItem`` object corresponding to `data_item_name`,
     which can be a unique valid abbreviation of the full name.
     """
     if not hasattr(self, "paths2data_items"):
         raise ValueError(
             'pool.get("%s") does not work because pool construction is not finalized with pool.update()'
             % data_item_name
         )
     try:
         return get_leaf(data_item_name, self.paths2data_items)
     except ValueError:
         raise ValueError(
             "%s is not a unique data item name "
             "among\n%s" % (data_item_name, ", ".join(self.paths2data_items.keys()))
         )
示例#4
0
 def set_values(self, args=sys.argv[1:], set_default=False):
     """
     Examine the command line (args) and set values in the pool.
     if `set_default`, the default value (and not the value) is set.
     """
     from parampool.tree.Tree import get_leaf
     for i, arg in enumerate(args):
         if arg.startswith('--'):
             arg = arg[2:]  # strip off leading --
             try:
                 data_item = get_leaf(arg, self.options2data_items)
             except ValueError:
                 raise ValueError(
                     '%s is not a unique data item name '
                     'among\n%s' % ('--' + arg, ', '.join(
                         ['--' + opt for opt in self.options2data_items])))
             if i + 1 >= len(args):
                 raise ValueError('no value for command-line option %s' %
                                  arg)
             value = args[i + 1]
             if set_default:
                 data_item.data['default'] = value
             else:
                 data_item.set_value(value)