예제 #1
0
 def repr_for_yaml(self,
                   which_vars=None,
                   resolve=True,
                   ignore_unknown_vars=False):
     retVal = dict()
     vars_list = list()
     if not which_vars:
         vars_list.extend(self.keys())
     elif isinstance(which_vars, str):
         vars_list.append(which_vars)
     else:
         vars_list = which_vars
     if not hasattr(vars_list, '__iter__'):  # if which_vars is a list
         ValueError(
             f"ConfigVarStack.repr_for_yaml can except string, list or None, not {type(which_vars)} {which_vars}"
         )
     for var_name in vars_list:
         if var_name in self:
             retVal[var_name] = self.repr_var_for_yaml(var_name,
                                                       resolve=resolve)
         elif not ignore_unknown_vars:
             retVal[var_name] = aYaml.YamlDumpWrap(
                 value="UNKNOWN VARIABLE",
                 comment=var_name + " is not in variable list")
     return retVal
예제 #2
0
 def repr_var_for_yaml(self, var_name, resolve=True):
     if resolve:
         var_value = list(self[var_name])
     else:
         var_value = self[var_name].raw(join_sep=None)
     if len(var_value) == 1:
         var_value = var_value[0]
     retVal = aYaml.YamlDumpWrap(var_value)
     return retVal
예제 #3
0
    def repr_for_yaml(self, what=None):
        """ Create representation of self suitable for printing as yaml.
            parameter 'what' is a list of identifiers to represent. If 'what'
            is None (the default) create representation of everything.
            InstlInstanceBase object is represented as two yaml documents:
            one for define (tagged !define), one for the index (tagged !index).
        """
        retVal = list()
        all_iids = self.items_table.get_all_iids()
        all_vars = sorted(config_vars.keys())
        if what is None:  # None is all
            what = all_vars + all_iids

        defines = OrderedDict()
        indexes = OrderedDict()
        unknowns = list()
        for identifier in what:
            if identifier in all_vars:
                defines.update(
                    {identifier: config_vars.repr_var_for_yaml(identifier)})
            elif identifier in all_iids:
                indexes.update({
                    identifier:
                    self.items_table.repr_item_for_yaml(identifier)
                })
            else:
                unknowns.append(
                    aYaml.YamlDumpWrap(value="UNKNOWN VARIABLE",
                                       comment=identifier +
                                       " is not in variable list"))
        if defines:
            retVal.append(
                aYaml.YamlDumpDocWrap(defines,
                                      '!define',
                                      "Definitions",
                                      explicit_start=True,
                                      sort_mappings=True))
        if indexes:
            retVal.append(
                aYaml.YamlDumpDocWrap(indexes,
                                      '!index',
                                      "Installation index",
                                      explicit_start=True,
                                      sort_mappings=True))
        if unknowns:
            retVal.append(
                aYaml.YamlDumpDocWrap(unknowns,
                                      '!unknowns',
                                      "Installation index",
                                      explicit_start=True,
                                      sort_mappings=True))

        return retVal