try to parse and interpolate all options in section "Definition" (section "Init" no more needed)

pull/1698/head
sebres 2017-02-16 13:32:56 +01:00
parent 7f63809afb
commit fc315be4ea
2 changed files with 23 additions and 5 deletions

View File

@ -221,10 +221,14 @@ class ConfigReaderUnshared(SafeConfigParserWithIncludes):
# Or it is a dict: # Or it is a dict:
# {name: [type, default], ...} # {name: [type, default], ...}
def getOptions(self, sec, options, pOptions=None, shouldExist=False): def getOptions(self, sec, options, pOptions=None,
allOpts=None, shouldExist=False
):
values = dict() values = dict()
if pOptions is None: if pOptions is None:
pOptions = {} pOptions = {}
# Get only specified options:
for optname in options: for optname in options:
if isinstance(options, (list,tuple)): if isinstance(options, (list,tuple)):
if len(optname) > 2: if len(optname) > 2:
@ -261,6 +265,15 @@ class ConfigReaderUnshared(SafeConfigParserWithIncludes):
logSys.warning("Wrong value for '" + optname + "' in '" + sec + logSys.warning("Wrong value for '" + optname + "' in '" + sec +
"'. Using default one: '" + repr(optvalue) + "'") "'. Using default one: '" + repr(optvalue) + "'")
values[optname] = optvalue values[optname] = optvalue
# Fill all option of the section (used for replacement):
if allOpts is not None and self.has_section(sec):
for optname in self.options(sec):
v = values.get(optname)
if v is None:
v = self.get(sec, optname, vars=pOptions)
allOpts[optname] = v
return values return values
@ -310,9 +323,9 @@ class DefinitionInitConfigReader(ConfigReader):
if not pOpts: if not pOpts:
pOpts = dict() pOpts = dict()
pOpts = _merge_dicts(pOpts, self._initOpts) pOpts = _merge_dicts(pOpts, self._initOpts)
self._allOpts = dict()
self._opts = ConfigReader.getOptions( self._opts = ConfigReader.getOptions(
self, "Definition", self._configOpts, pOpts) self, "Definition", self._configOpts, pOpts, allOpts=self._allOpts)
if self.has_section("Init"): if self.has_section("Init"):
for opt in self.options("Init"): for opt in self.options("Init"):
v = self.get("Init", opt) v = self.get("Init", opt)
@ -338,7 +351,8 @@ class DefinitionInitConfigReader(ConfigReader):
n, cond = cond.groups() n, cond = cond.groups()
ignore.add(n) ignore.add(n)
# substiture options already specified direct: # substiture options already specified direct:
opts = CommandAction.substituteRecursiveTags(combinedopts, ignore=ignore) opts = CommandAction.substituteRecursiveTags(combinedopts,
ignore=ignore, addtags=self._allOpts)
if not opts: if not opts:
raise ValueError('recursive tag definitions unable to be resolved') raise ValueError('recursive tag definitions unable to be resolved')
return opts return opts

View File

@ -365,7 +365,9 @@ class CommandAction(ActionBase):
return self._executeOperation('<actionreload>', 'reloading') return self._executeOperation('<actionreload>', 'reloading')
@classmethod @classmethod
def substituteRecursiveTags(cls, inptags, conditional='', ignore=()): def substituteRecursiveTags(cls, inptags, conditional='',
ignore=(), addtags={}
):
"""Sort out tag definitions within other tags. """Sort out tag definitions within other tags.
Since v.0.9.2 supports embedded interpolation (see test cases for examples). Since v.0.9.2 supports embedded interpolation (see test cases for examples).
@ -420,6 +422,8 @@ class CommandAction(ActionBase):
repl = tags.get(found_tag + '?' + conditional) repl = tags.get(found_tag + '?' + conditional)
if repl is None: if repl is None:
repl = tags.get(found_tag) repl = tags.get(found_tag)
if repl is None:
repl = addtags.get(found_tag)
if repl is None: if repl is None:
# Escaped or missing tags - just continue on searching after end of match # Escaped or missing tags - just continue on searching after end of match
# Missing tags are ok - cInfo can contain aInfo elements like <HOST> and valid shell # Missing tags are ok - cInfo can contain aInfo elements like <HOST> and valid shell