Beispiel #1
0
    def _clean_tree(self):
        # Read all variables.
        variables = self.cfgtree.find('variables')
        if variables is not None:
            for element in variables:
                varname = element.tag.strip()
                value   = resolve_variables(self.variables, element.text)
                self.variables[varname] = value

        # Resolve variables everywhere.
        for element in self.cfgtree.iter():
            if element.tag is etree.Comment:
                continue
            element.text = self._resolve(element.text)
            for attr in element.attrib:
                value                = element.attrib[attr]
                element.attrib[attr] = self._resolve(value)
Beispiel #2
0
 def _resolve(self, text):
     if not self.resolve:
         return text
     if text is None:
         return None
     return resolve_variables(self.variables, text.strip())