Ejemplo n.º 1
0
 def get(self, section, option):
     # Try the cache first
     cache_key = cfg_helpers.make_id(section, option)
     if cache_key in self.opts_cache:
         return self.opts_cache[cache_key]
     # Check the resolvers
     val = None
     for resolver in self.read_resolvers:
         LOG.debug("Looking for %r using resolver %s", cfg_helpers.make_id(section, option), resolver)
         found_val = resolver.get(section, option)
         if found_val is not None:
             LOG.debug(
                 "Found value %r for section %r using resolver %s",
                 found_val,
                 cfg_helpers.make_id(section, option),
                 resolver,
             )
             val = found_val
             break
     # Store in cache if we found something
     if val is not None:
         self.opts_cache[cache_key] = val
     # Mark as read
     if section not in self.opts_read:
         self.opts_read[section] = set()
     self.opts_read[section].add(option)
     return val
Ejemplo n.º 2
0
 def set(self, section, option, value):
     for resolver in self.set_resolvers:
         LOG.debug("Setting %r to %s using resolver %s", cfg_helpers.make_id(section, option), value, resolver)
         resolver.set(section, option, value)
     cache_key = cfg_helpers.make_id(section, option)
     self.opts_cache[cache_key] = value
     if section not in self.opts_set:
         self.opts_set[section] = set()
     self.opts_set[section].add(option)
     return value
Ejemplo n.º 3
0
 def create(cls, cli_args):
     parsed_args = dict()
     for c in cli_args:
         if not c:
             continue
         split_up = c.split("/")
         if len(split_up) != 3:
             LOG.warn("Incorrectly formatted cli option: %r", c)
         else:
             section = (split_up[0]).strip()
             if not section or section.lower() == "default":
                 section = "DEFAULT"
             option = split_up[1].strip()
             if not option:
                 LOG.warn("Badly formatted cli option - no option name: %r", c)
             else:
                 parsed_args[cfg_helpers.make_id(section, option)] = split_up[2]
     return cls(parsed_args)
Ejemplo n.º 4
0
 def _form_key(self, section, option):
     return cfg_helpers.make_id(section, option)
Ejemplo n.º 5
0
 def get(self, section, option):
     return self.cli_args.get(cfg_helpers.make_id(section, option))