Exemple #1
0
 def do_checksum(self):
     path_to_checksum = var_stack.ResolveVarToStr("__MAIN_INPUT_FILE__")
     ignore_files = var_stack.ResolveVarToList("WTAR_IGNORE_FILES", default=list())
     checksums_dict = utils.get_recursive_checksums(path_to_checksum, ignore=ignore_files)
     total_checksum = checksums_dict.pop('total_checksum', "Unknown total checksum")
     path_and_checksum_list = [(path, checksum) for path, checksum in sorted(checksums_dict.items())]
     width_list, align_list = utils.max_widths(path_and_checksum_list)
     col_formats = utils.gen_col_format(width_list, align_list)
     for p_and_c in path_and_checksum_list:
         print(col_formats[len(p_and_c)].format(*p_and_c))
     print()
     print(col_formats[2].format("total checksum", total_checksum))
Exemple #2
0
 def do_checksum(self):
     path_to_checksum = os.fspath(config_vars["__MAIN_INPUT_FILE__"])
     ignore_files = list(config_vars.get("WTAR_IGNORE_FILES", []))
     checksums_dict = utils.get_recursive_checksums(path_to_checksum, ignore=ignore_files)
     total_checksum = checksums_dict.pop('total_checksum', "Unknown total checksum")
     path_and_checksum_list = [(path, checksum) for path, checksum in sorted(checksums_dict.items())]
     width_list, align_list = utils.max_widths(path_and_checksum_list)
     col_formats = utils.gen_col_format(width_list, align_list)
     for p_and_c in path_and_checksum_list:
         print(col_formats[len(p_and_c)].format(*p_and_c))
     print()
     print(col_formats[2].format("total checksum", total_checksum))
Exemple #3
0
def list_of_dicts_describing_disk_items_to_text_lines(items_list, ls_format):
    # when calculating widths - avoid comment lines
    real_line_list = list()  # lines that are not empty or comments
    # when printing - avoid formatting of comment lines or empty lines (empty lines might be created by weird ls_format)
    for item_dict in items_list:
        if item_dict:
            real_line_list.append(item_dict_to_list(item_dict, ls_format))
    width_list, align_list = utils.max_widths(real_line_list)
    col_formats = utils.gen_col_format(width_list, align_list)
    formatted_lines = list()
    for ls_line in real_line_list:
        formatted_lines.append(col_formats[len(ls_line)].format(*ls_line))
    return formatted_lines
Exemple #4
0
 def topic_summery(self, topic):
     retVal = "no such topics: " + topic
     short_list = list()
     if topic in self.topic_items:
         for item_name in self.topic_items[topic]:
             short_list.append((item_name + ":", self.help_items[item_name].short_text()))
     short_list.sort()
     if len(short_list) > 0:
         width_list = [0, 0]
         for name, short_text in short_list:
             width_list[0] = max(width_list[0], len(name))
             width_list[1] = max(width_list[1], len(short_text))
         format_list = utils.gen_col_format(width_list)
         retVal = "\n".join(format_list[2].format(name, short) for name, short in short_list)
     return retVal
Exemple #5
0
 def topic_summery(self, topic):
     retVal = "no such topic: " + topic
     short_list = list()
     for item in list(self.help_items.values()):
         if item.topic == topic:
             short_list.append((item.name + ":", item.short_text()))
     short_list.sort()
     if len(short_list) > 0:
         width_list = [0, 0]
         for name, short_text in short_list:
             width_list[0] = max(width_list[0], len(name))
             width_list[1] = max(width_list[1], len(short_text))
         format_list = utils.gen_col_format(width_list)
         retVal = "\n".join(format_list[2].format(name, short) for name, short in short_list)
     return retVal
Exemple #6
0
    def defaults_help(self):
        defaults_folder_path = os.path.join(var_stack.ResolveVarToStr("__INSTL_DATA_FOLDER__"), "defaults")
        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(os.path.join(defaults_folder_path, yaml_file))
        defaults_list = [("Variable name", "Raw value", "Resolved value"),
                         ("_____________", "_________", "______________")]
        for var in sorted(var_stack):
            if not var.startswith("__"):
                cv = var_stack.get_configVar_obj(var)
                raw_value = " ".join([value for value in cv])
                resolved_value = var_stack.ResolveVarToStr(var)
                if raw_value != resolved_value:
                    defaults_list.append((var, raw_value, resolved_value))
                else:
                    defaults_list.append((var, raw_value))

        col_format = utils.gen_col_format(utils.max_widths(defaults_list))
        for res_line in defaults_list:
            print(col_format[len(res_line)].format(*res_line))
Exemple #7
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)