Пример #1
0
 def new_by_json_str(jstr):
     """Creates a new Cfg object with the contents of the given
     string.  The string must be a valid JSON structure.
     This is a static factory method.
     """
     config = Cfg()
     cfg_format = CfgFormatJson(config, 'json')
     DictHelper.merge(config, cfg_format.create_cfg_from_str(jstr))
     return config
Пример #2
0
 def evaluate(self):
     """As long as there are parameters, handle them."""
     try:
         while True:
             config = self.__cfg.get_value(['configuration', self.__name])
             # This must be removed before the evaluation, because it
             # is possible that during the evaluation additional
             # entries will appear.
             del self.__cfg['configuration'][self.__name]
             DictHelper.merge(self.__cfg, self.__evaluate_once(config))
     except RMTException:
         # Nothing to do: entries not available
         pass
Пример #3
0
 def get_integer(self, key, default_value):
     '''Returns the value of the key - converted to an integer.
        If key does not exists, the default value is returned.'''
     try:
         return int(DictHelper.get_raw(self, key))
     except CfgEx:
         return default_value
Пример #4
0
 def get_value_default(self, key, default_value):
     '''Return the value of the key from the configuration.
        If the key is not available, the default_value is returned.'''
     try:
         return DictHelper.get_raw(self, key)
     except CfgEx:
         return default_value
Пример #5
0
 def get_rvalue_default(self, key, default_value):
     '''Return the value of the key from the configuration.
        Replacement of ${} is done, if the key is available,
        If the key is not available, the default_value is returned.'''
     try:
         return self.dollar_replace(DictHelper.get_raw(self, key))
     except CfgEx:
         return default_value
Пример #6
0
 def get_bool(self, key, default_value):
     '''Returns the value of the key - converted to a boolean.
        If key does not exists, the default value is returned.'''
     try:
         return DictHelper.get_raw(self, key) \
             in ['True', 'true', 'on', '1',
                 'Yes', 'yes', True]
     except CfgEx:
         return default_value
Пример #7
0
 def get_value(self, key):
     '''Returns the value of the given key.
        If key is not found a RMTException is thrown.'''
     try:
         rval = DictHelper.get_raw(self, key)
         if isinstance(rval, dict):
             return Cfg(rval)
         return rval
     except CfgEx as cex:
         raise RMTException(
             96, "Mandatory configuration parameter "
             "[%s] not found. (Root cause: [%s])" % (key, cex))
Пример #8
0
 def __evaluate_once(self, config):
     """Evaluates the given configuration and returns it"""
     cfg = {}
     for cfg_idx in config:
         DictHelper.merge(cfg, self.__create_cfg_from_url(cfg_idx))
     return cfg
Пример #9
0
 def set_value(self, key, value):
     '''Sets the value. If the key is already there a CfgEx is
        raised.'''
     ckey = DictHelper.cfg_key(key)
     DictHelper.set_value(self, ckey, value)
Пример #10
0
 def merge_cmd_line_params(self, args):
     '''Merges the command line arguments into the
        existing configuration.'''
     ldicts = CmdLineParams.create_dicts(args)
     for ldict in ldicts:
         DictHelper.merge(self, ldict)
Пример #11
0
 def merge_json_str(self, jstr):
     """Merges a JSON config into an already existing"""
     cfg_format = CfgFormatJson(self, 'json')
     DictHelper.merge(self, cfg_format.create_cfg_from_str(jstr))