示例#1
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
示例#2
0
def create_completion_list_imp(self, for_what="all"):
    retVal = list()
    try:
        if for_what in ("all", "index"):
            retVal.extend(list(self.items_table.get_all_iids()))
        if for_what in ("all", "define"):
            retVal.extend(list(config_vars.keys()))
        if for_what in ("all", "guid"):
            retVal.extend(self.items_table.get_detail_values_by_name_for_all_iids("guid"))
    except Exception as ex:
        print("create_completion_list:", ex)
    return retVal
示例#3
0
    def create_variables_assignment(self, in_batch_accum):
        in_batch_accum.set_current_section('assign')
        #do_not_write_vars = [var.lower() for var in config_vars["DONT_WRITE_CONFIG_VARS"].list() + list(os.environ.keys())]
        do_not_write_vars = config_vars["DONT_WRITE_CONFIG_VARS"].list()
        if not bool(
                config_vars.get(
                    "WRITE_CONFIG_VARS_READ_FROM_ENVIRON_TO_BATCH_FILE",
                    "no")):
            do_not_write_vars += [
                re.escape(a_var) for a_var in os.environ.keys()
            ]

        regex = "|".join(do_not_write_vars)
        do_not_write_vars_regex = re.compile(regex, re.IGNORECASE)
        for identifier in config_vars.keys():
            if not do_not_write_vars_regex.fullmatch(identifier):
                in_batch_accum += ConfigVarAssign(
                    identifier, *list(config_vars[identifier]))
示例#4
0
    def defaults_help(self, var_name=None):
        defaults_folder_path = config_vars["__INSTL_DEFAULTS_FOLDER__"].Path()
        for yaml_file in os.listdir(defaults_folder_path):
            if fnmatch.fnmatch(yaml_file, '*.yaml') and yaml_file != "P4.yaml":  # hack to not read the P4 defaults
                self.instlObj.read_yaml_file(defaults_folder_path.joinpath(yaml_file))
        defaults_list = [("Variable name", "Raw value", "Resolved value"),
                         ("_____________", "_________", "______________")]
        for var in sorted(config_vars.keys()):
            if not var.startswith("__"):
                raw_value = config_vars[var].raw(join_sep=" ")
                resolved_value = str(config_vars[var])
                if raw_value != resolved_value:
                    defaults_list.append((var, raw_value, resolved_value))
                else:
                    defaults_list.append((var, raw_value))

        width_list, align_list = utils.max_widths(defaults_list)
        col_format = utils.gen_col_format(width_list, align_list)
        for res_line in defaults_list:
            a_line = col_format[len(res_line)].format(*res_line)
            print(a_line)