Example #1
0
 def _draw_section_columns_bottom(section: Section, is_bottom: bool = False):
     bdr = Border()
     if is_bottom:
         col_lines = [repeat(bdr.b, x.width + (x.padding * 2)) for x in section.items if type(x) is Column]
         print(bdr.bl + bdr.bs.join(col_lines) + bdr.br)
     else:
         col_lines = [repeat(bdr.mh, x.width + (x.padding * 2)) for x in section.items if type(x) is Column]
         print(bdr.ls + bdr.bs.join(col_lines) + bdr.rs)
Example #2
0
 def _draw_section_sep(section):
     bdr = Border()
     if section.has_columns and not section.has_footers:
         col_lines = [repeat(bdr.mh, x.width + (x.padding * 2)) for x in section.items if type(x) is Column]
         print(bdr.ls + bdr.bs.join(col_lines) + bdr.rs)
     elif section.has_headers or section.has_footers:
         line = repeat(bdr.mh, section.width - (section.padding * 2))
         print(bdr.ls + line + bdr.rs)
Example #3
0
    def cli_slaves_add_path(self, source_root_path: str,
                            installed_root_path: str, recursive_flag: bool):
        abs_source_root_path = os.path.abspath(source_root_path)

        supported_extensions = [".slave", ".lha"]

        if recursive_flag:
            file_list = list(
                self._walk_path(abs_source_root_path, supported_extensions,
                                True))
        else:
            file_list = list(
                self._walk_path(abs_source_root_path, supported_extensions,
                                False))

        file_count = len(file_list)

        if shutil.get_terminal_size().columns >= 120:
            bar_file_width = 35
            bar_file_format = progressbar.FormatCustomText(
                "%(bar_file)s", {"bar_file": repeat(" ", bar_file_width)})
            bar_widgets = [
                progressbar.Percentage(), " ",
                progressbar.Bar(left="[", right="]", fill="."), " ",
                progressbar.Counter("%(value)5d"), f"/{file_count:d}", " | ",
                progressbar.Timer(format="Elapsed: %(elapsed)s"), " | ",
                bar_file_format, " "
            ]
        else:
            bar_file_width = 20
            bar_file_format = progressbar.FormatCustomText(
                "%(bar_file)s", {"bar_file": repeat(" ", bar_file_width)})
            bar_widgets = [
                progressbar.Percentage(), " ",
                progressbar.Bar(left="[", right="]", fill="."), " ",
                progressbar.Timer(format="%(elapsed)s"), " | ",
                bar_file_format, " "
            ]
        bar = progressbar.ProgressBar(widgets=bar_widgets)

        for i in bar(range(file_count)):
            file_path = file_list[i]
            bar_file = pad(
                truncate(os.path.basename(file_path), bar_file_width),
                bar_file_width, Align.Left.value)
            bar_file_format.update_mapping(bar_file=bar_file)
            file_ext = os.path.splitext(file_path)[1].lower()
            if file_ext == ".slave":
                self._cli_slaves_add_slave(
                    click.open_file(file_path, mode="rb"), installed_root_path)
            elif file_ext == ".lha":
                self._cli_slaves_add_archive(
                    click.open_file(file_path, mode="rb"),
                    abs_source_root_path, installed_root_path)
Example #4
0
    def _draw_section_column_labels(section):
        bdr = Border()
        lbl_w = [x.width for x in section.items if type(x) is Column]
        lbl_p = [x.padding for x in section.items if type(x) is Column]
        lbl_a = [x.align for x in section.items if type(x) is Column]
        lbl_c = [x.label for x in section.items if type(x) is Column]
        row_lbls = []
        for i in range(len(lbl_c)):
            padding = repeat(" ", lbl_p[i])
            col_text = pad(truncate(lbl_c[i], lbl_w[i]), lbl_w[i], lbl_a[i].value)
            row_lbls.append(padding + col_text + padding)
        print(bdr.l + bdr.mv.join(row_lbls) + bdr.r)

        col_lines = [repeat(bdr.mh, x.width + (x.padding * 2)) for x in section.items if type(x) is Column]
        print(bdr.ls + bdr.ms.join(col_lines) + bdr.rs)
Example #5
0
    def _draw_section_footers(section):
        bdr = Border()
        footers = [x for x in section.items if type(x) is Footer]
        count = 1
        for footer in footers:
            padding = repeat(" ", footer.padding)

            def footer_gen():
                for content in footer.content:
                    yield content.split("\n")

            for footer_item in footer_gen():
                for footer_line in footer_item:

                    footer_text = pad(truncate(footer_line, footer.width), footer.width, footer.align.value)
                    footer_row = bdr.l + padding + footer_text + padding + bdr.r
                    print(footer_row)

            if count < len(footers):
                line = repeat(bdr.mh, footer.width + (footer.padding * 2))
                print(bdr.ls + line + bdr.rs)
                count += 1
Example #6
0
    def _draw_section_columns(section):
        bdr = Border()
        col_w = [x.width for x in section.items if type(x) is Column]
        col_p = [x.padding for x in section.items if type(x) is Column]
        col_a = [x.align for x in section.items if type(x) is Column]
        col_c = [x.content for x in section.items if type(x) is Column]
        col_rows = zip_longest(*col_c, fillvalue="")
        for row in col_rows:
            row_cols = []
            for i in range(len(row)):
                padding = repeat(" ", col_p[i])

                col_text = pad(truncate(row[i], col_w[i]), col_w[i], col_a[i].value)
                row_cols.append(padding + col_text + padding)
            print(bdr.l + bdr.mv.join(row_cols) + bdr.r)
Example #7
0
    def _cli_packages_add_category(self, category: str):
        Packages.logger.info(f"Getting package info from www.whdload.de ...")

        all_packages = self._get_package_list(category, True)

        dupes = set(x for x in all_packages for y in self.data
                    if x == y.list_info)
        changed = set(x for x in all_packages for y in self.data
                      if x[1] == y.list_info[1] and x[3] != y.list_info[3])
        new_packages = sorted(all_packages.difference(dupes),
                              key=lambda x: x[0])

        if len(dupes) > 0:
            if len(dupes) == 1:
                package_text = "package"
            else:
                package_text = "packages"
            Packages.logger.info(
                f"Skipping {len(dupes)} duplicate {package_text}.")

        if len(changed) > 0:
            del_indexes = [
                i for x in changed for i in range(len(self.data))
                if x[1] == self.data[i].list_info[1]
            ]
            for i in del_indexes:
                del self.data[i]

            if len(changed) == 1:
                package_text = "package"
            else:
                package_text = "packages"
            Packages.logger.info(
                f"Removed {len(changed)} outdated {package_text} from WHDLoad Package data file."
            )

        if len(new_packages) > 0:
            if len(new_packages) == 1:
                package_text = "package"
            else:
                package_text = "packages"
            Packages.logger.info(
                f"Adding {len(new_packages)} {package_text} to WHDLoad Package data file."
            )

            if shutil.get_terminal_size().columns >= 120:
                bar_name_width = 35
                bar_name_format = progressbar.FormatCustomText(
                    "%(bar_name)s", {"bar_name": repeat(" ", bar_name_width)})
                bar_widgets = [
                    progressbar.Percentage(), " ",
                    progressbar.Bar(left="[", right="]", fill="."), " ",
                    progressbar.Counter("%(value)5d"),
                    f"/{len(new_packages):d}", " | ",
                    progressbar.Timer(format="Elapsed: %(elapsed)s"), " | ",
                    bar_name_format, " "
                ]
            else:
                bar_name_width = 20
                bar_name_format = progressbar.FormatCustomText(
                    "%(bar_name)s", {"bar_name": repeat(" ", bar_name_width)})
                bar_widgets = [
                    progressbar.Percentage(), " ",
                    progressbar.Bar(left="[", right="]", fill="."), " ",
                    progressbar.Timer(format="%(elapsed)s"), " | ",
                    bar_name_format, " "
                ]
            bar = progressbar.ProgressBar(widgets=bar_widgets,
                                          min_value=0,
                                          max_value=len(new_packages))

            bar_name = pad(truncate("Starting ...", bar_name_width),
                           bar_name_width, Align.Left.value)
            bar_name_format.update_mapping(bar_name=bar_name)
            bar.update(bar.min_value)

            for i in range(len(new_packages)):
                name = new_packages[i][0]
                bar_name = pad(truncate(f"{name}", bar_name_width),
                               bar_name_width, Align.Left.value)
                bar_name_format.update_mapping(bar_name=bar_name)
                DataSet.logger.info(f"Getting info for '{name}'")
                bar.update(i + 1)
                self._add_package(new_packages[i])
                self.save()
            bar_name = pad(truncate("Finished!", bar_name_width),
                           bar_name_width, Align.Left.value)
            bar_name_format.update_mapping(bar_name=bar_name)
            DataSet.logger.info("Finished!")
            bar.update(bar.max_value)
        else:
            Packages.logger.info(
                f"No packages to add to WHDLoad Package data file.")
Example #8
0
 def _draw_table_bottom(self):
     bdr = Border()
     line = repeat(bdr.b, self.width - (len(bdr.bl) + len(bdr.br)))
     print(bdr.bl + line + bdr.br)
Example #9
0
 def _draw_table_header_top(self):
     bdr = Border()
     line = repeat(bdr.t, self.width - (len(bdr.tl) + len(bdr.tr)))
     print(bdr.tl + line + bdr.tr)