示例#1
0
    def print_licences(self):
        """Prints the fetched license information.

        Args:
            as_json (boolean): Prints the information in JSON. Defaults to False.
        """
        log.info(
            "Warning: This tool only prints licence information for the software tools packaged using conda."
        )
        log.info(
            "The pipeline may use other software and dependencies not described here. "
        )

        if self.as_json:
            return json.dumps(self.conda_package_licences, indent=4)
        else:
            table = rich.table.Table("Package Name", "Version", "Licence")
            licence_list = []
            for dep, licences in self.conda_package_licences.items():
                depname, depver = dep.split("=", 1)
                try:
                    depname = depname.split("::")[1]
                except IndexError:
                    pass
                licence_list.append([depname, depver, ", ".join(licences)])
            # Sort by licence, then package name
            licence_list = sorted(sorted(licence_list), key=lambda x: x[2])
            # Add table rows
            for lic in licence_list:
                table.add_row(*lic)
            return table
示例#2
0
    def draw_console(self, series):
        if isinstance(series, Series):
            series = [series]

        table = rich.table.Table(
            expand=False,
            box=rich.box.MINIMAL,
            border_style="rgb(100,100,100)",
        )
        table.add_column(self.x_axis.label)

        for _ in series:
            table.add_column(self.y_axis.label)

        for n in range(len(series[0].data)):
            row = [series[0].data[n][0]]

            for s in series:
                row.append(s.data[n][1])

            for n, v in enumerate(row):
                if n == 0:
                    row[n] = rich.text.Text(f"{v:0.3f}", style="bold italic")
                elif isinstance(v, float):
                    color = _color_for_value(v, self.y_axis.min,
                                             self.y_axis.max)
                    row[n] = rich.text.Text(f"{v:0.3f}", style=color)
                else:
                    row[n] = f"{v!r}"

            table.add_row(*row)

        return rich.align.Align.center(table)
示例#3
0
文件: project.py 项目: hyunmu/spb-cli
    def describe_projects(self):
        page = 1
        while True:
            projects, project_count = self._get_projects(
                page=page, page_size=self.CURRENT_PAGE_COUNT)
            table = rich.table.Table(show_header=True,
                                     header_style="bold magenta")
            table.add_column("NAME", width=50)
            table.add_column("LABELS", justify="right")
            table.add_column("PROGRESS", justify="right")

            for item in projects:
                table.add_row(item.name, f"{item.label_count}",
                              f"{item.progress}%")

            console.print(table)
            total_page = math.ceil(project_count / self.CURRENT_PAGE_COUNT)

            if total_page > page:
                click.echo(
                    f'Press any button to continue to the next page ({page}/{total_page}). Otherwise press ‘Q’ to quit.',
                    nl=False)
                key = click.getchar()
                click.echo()
                page = page + 1
                if key == 'q' or key == 'Q':
                    return
            elif total_page <= page:
                return
示例#4
0
def get_rich_table(list: typing.List[dict]):
    import rich.table

    table = rich.table.Table()
    columns: set = functools.reduce(set.union, map(set, list))
    for column in columns:
        table.add_column(column)

    for item in list:
        table.add_row(*map(get_rich, map(item.get, columns)))

    return table
示例#5
0
def get_rich_pandas(df, table=None, **k):
    if table is None:
        table = rich.table.Table()
    indexes = df.index.names
    columns = indexes + list(df.columns)
    for column in columns:
        table.add_column(column)
    for index, row in df.iterrows():
        if not isinstance(index, tuple):
            index = (index, )
        data = dict(zip(list(indexes), map("[b]{}".format, index)), **row)
        table.add_row(*map(get_rich, map(data.get, columns)))
    return table
示例#6
0
def cli_list(cfg):
    engine = migrate.migrate(cfg)
    indexes = index.Index.list_indexes(engine, False)

    table = rich.table.Table(title='Indexes')
    table.add_column('Last Built')
    table.add_column('Index')
    table.add_column('S3 Prefix')
    table.add_column('Schema')

    for i in sorted(indexes, key=lambda i: i.name):
        built = f'[green]{i.built}[/]' if i.built else '[red]Not built[/]'
        table.add_row(built, i.name, i.s3_prefix, str(i.schema))

    console.print(table)
示例#7
0
文件: display.py 项目: stwins60/Preql
def _rich_table(name,
                count_str,
                rows,
                offset,
                has_more,
                colors=True,
                show_footer=False):
    header = 'table '
    if name:
        header += name
    if offset:
        header += f'[{offset}..]'
    header += f" {count_str}"

    if not rows:
        return header

    table = rich.table.Table(title=rich.text.Text(header),
                             show_footer=show_footer,
                             min_width=len(header))

    # TODO enable/disable styling
    for k, v in rows[0].items():
        kw = {}
        if isinstance(v, (int, float)):
            kw['justify'] = 'right'

        if colors:
            if isinstance(v, int):
                kw['style'] = 'cyan'
            elif isinstance(v, float):
                kw['style'] = 'yellow'
            elif isinstance(v, str):
                kw['style'] = 'green'

        table.add_column(k, footer=k, **kw)

    for r in rows:
        table.add_row(*[
            rich.markup.escape(str(x) if x is not None else '-')
            for x in r.values()
        ])

    if has_more:
        table.add_row(*['...' for x in rows[0]])

    return table
示例#8
0
    def __create_failed_table(self, resp_json, level="File"):
        """Output a response after deletion."""
        # Check that enough info
        if not all(x in resp_json for x in ["not_exists", "not_removed"]):
            raise dds_cli.exceptions.APIError(
                f"Malformatted response detected when attempting remove action on {self.project}."
            )

        # Get info
        not_exists = resp_json["not_exists"]
        delete_failed = resp_json["not_removed"]

        # Create table if any files failed
        if not_exists or delete_failed:
            if self.no_prompt:
                self.failed_files = {"Errors": []}
                for x in not_exists:
                    self.failed_files["Errors"].append(
                        {x: f"No such {level.lower()}"})
                for x, y in delete_failed.items():
                    self.failed_files["Errors"].append({x: y})
            else:
                # Create table and add columns
                table = rich.table.Table(
                    title=f"{level}s not deleted",
                    title_justify="left",
                    show_header=True,
                    header_style="bold",
                )
                columns = [level, "Error"]
                for x in columns:
                    table.add_column(x)

                # Add rows
                for x in not_exists:
                    table.add_row(rich.markup.escape(x),
                                  f"No such {level.lower()}")

                for x, y in delete_failed.items():
                    table.add_row(
                        f"[light_salmon3]{rich.markup.escape(x)}[/light_salmon3]",
                        f"[light_salmon3]{rich.markup.escape(y)}[/light_salmon3]",
                    )

                # Print out table
                self.failed_table = rich.padding.Padding(table, 1)
示例#9
0
    def _print_error_table(self, data_results=None, label_results=None):
        results = {}

        if isinstance(data_results, dict):
            for key in data_results:
                results[key] = {}
                results[key]['data'] = data_results[key]
                results[key]['label'] = None
        if isinstance(label_results, dict):
            for key in label_results:
                if key in results:
                    results[key]['label'] = label_results[key]
                else:
                    results[key] = {'label': label_results[key], 'data': None}

        if not next(iter(results), None):
            return
        console.print('\n[b red]** Error Table **[/b red]')
        page = 1
        page_length = math.ceil(len(results) / 10)
        while True:
            table = rich.table.Table(show_header=True,
                                     header_style="bold magenta")
            table.add_column("FILE NAME")
            if isinstance(data_results, dict):
                table.add_column("DATA UPLOAD")
            if isinstance(label_results, dict):
                table.add_column("LABEL UPLOAD")

            for _ in range(10):
                key = next(iter(results), None)
                if not key:
                    break
                if isinstance(data_results, dict) and isinstance(
                        label_results, dict):
                    data = results[key]['data']
                    label = results[key]['label']
                    table.add_row(key, f"{data if data else '-'}",
                                  f"{label if label else '-'}")
                elif isinstance(data_results, dict):
                    data = results[key]['data']
                    table.add_row(key, f"{data if data else '-'}")
                else:
                    label = results[key]['label']
                    table.add_row(key, f"{label if label else '-'}")
                del results[key]
            console.print(table)
            if not next(iter(results), None):
                break
            else:
                click.echo(
                    f'Press any button to continue to the next page ({page}/{page_length}). Otherwise press ‘Q’ to quit.',
                    nl=False)
                key = click.getchar()
                click.echo()
                if key == 'q' or key == 'Q':
                    break
        console.log(f'[b]Check the log file for more details[/b]')
        console.log(f'- {simple_logger.handlers[0].baseFilename}')
        console.log(f'- {logger.handlers[0].baseFilename}')
示例#10
0
文件: list.py 项目: nf-core/tools
    def print_summary(self):
        """Prints a summary of all pipelines."""

        filtered_workflows = self.filtered_workflows()

        # Sort by released / dev / archived, then alphabetical
        if not self.sort_workflows_by or self.sort_workflows_by == "release":
            filtered_workflows.sort(key=lambda wf: (
                (wf.releases[-1].get("published_at_timestamp", 0)
                 if len(wf.releases) > 0 else 0) * -1,
                wf.archived,
                wf.full_name.lower(),
            ))
        # Sort by date pulled
        elif self.sort_workflows_by == "pulled":

            def sort_pulled_date(wf):
                try:
                    return wf.local_wf.last_pull * -1
                except:
                    return 0

            filtered_workflows.sort(key=sort_pulled_date)
        # Sort by name
        elif self.sort_workflows_by == "name":
            filtered_workflows.sort(key=lambda wf: wf.full_name.lower())
        # Sort by stars, then name
        elif self.sort_workflows_by == "stars":
            filtered_workflows.sort(key=lambda wf: (wf.stargazers_count * -1,
                                                    wf.full_name.lower()))

        # Build summary list to print
        table = rich.table.Table()
        table.add_column("Pipeline Name")
        table.add_column("Stars", justify="right")
        table.add_column("Latest Release", justify="right")
        table.add_column("Released", justify="right")
        table.add_column("Last Pulled", justify="right")
        table.add_column("Have latest release?")
        for wf in filtered_workflows:
            wf_name = "[bold][link=https://nf-co.re/{0}]{0}[/link]".format(
                wf.name, wf.full_name)
            version = "[yellow]dev"
            if len(wf.releases) > 0:
                version = "[blue]{}".format(wf.releases[-1]["tag_name"])
            published = wf.releases[-1]["published_at_pretty"] if len(
                wf.releases) > 0 else "[dim]-"
            pulled = wf.local_wf.last_pull_pretty if wf.local_wf is not None else "[dim]-"
            if wf.local_wf is not None:
                revision = ""
                if wf.local_wf.active_tag is not None:
                    revision = "v{}".format(wf.local_wf.active_tag)
                elif wf.local_wf.branch is not None:
                    revision = "{} - {}".format(wf.local_wf.branch,
                                                wf.local_wf.commit_sha[:7])
                else:
                    revision = wf.local_wf.commit_sha
                if wf.local_is_latest:
                    is_latest = "[green]Yes ({})".format(revision)
                else:
                    is_latest = "[red]No ({})".format(revision)
            else:
                is_latest = "[dim]-"

            rowdata = [
                wf_name,
                str(wf.stargazers_count), version, published, pulled, is_latest
            ]

            # Handle archived pipelines
            if wf.archived:
                rowdata[1] = "archived"
                rowdata = [re.sub("\[\w+\]", "", k) for k in rowdata]
                table.add_row(*rowdata, style="dim")
            else:
                table.add_row(*rowdata)

        if len(filtered_workflows) > 0:
            # Print summary table
            return table
        else:
            return_str = f"No pipelines found using filter keywords: '{', '.join(self.keyword_filters)}'"
            if self.keyword_filters == ("modules", ):
                return_str += "\n\n:bulb: Did you mean 'nf-core modules list' instead?"
            return return_str
示例#11
0
 def _blob_to_table(cls, rows, cols):
     table = rich.table.Table(show_header=True)
     [table.add_column(col_name) for col_name in cols]
     [table.add_row(*r) for r in rows]
     return table
    def v2_playbook_on_stats(self, stats):
        self._display.banner('RECAP')

        def cell(v, style, align='right'):
            if v:
                return rich.align.Align(str(v), align=align, style=style)
            else:
                return rich.align.Align(str(v), align=align, style='dim')

        def stat_column(header, field, style):
            total = sum(field.values())
            return rich.table.Column(
                header=rich.align.Align(header, align='center'),
                footer=cell(total, style=style)
            )

        table = rich.table.Table(
            rich.table.Column(header='Host', footer='Total'),
            stat_column('OK', stats.ok, style='ok'),
            stat_column('Changed', stats.changed, style='changed'),
            stat_column('Unreachable', stats.dark, style='unreachable'),
            stat_column('Failed', stats.failures, style='failed'),
            stat_column('Skipped', stats.skipped, style='skipped'),
            stat_column('Rescued', stats.rescued, style='rescued'),
            stat_column('Ignored', stats.ignored, style='ignored'),
            rich.table.Column(header='Total'),
            box=SIMPLER,
            padding=(0, 0, 0, 0),  # Top, Right, Bottom, Left
            pad_edge=False,
            show_edge=False,
            show_footer=True,
        )

        overall_total = 0
        for h in sorted(stats.processed.keys()):
            t = stats.summarize(h)
            host_total = sum(t.values())
            overall_total += host_total
            table.add_row(
                h,
                cell(t['ok'], style='ok'),
                cell(t['changed'], style='changed'),
                cell(t['unreachable'], style='unreachable'),
                cell(t['failures'], style='failed'),
                cell(t['skipped'], style='skipped'),
                cell(t['rescued'], style='rescued'),
                cell(t['ignored'], style='ignored'),
                cell(host_total, style='default'),
            )

            self._display.display(
                u"%s : %s %s %s %s %s %s %s" % (
                    hostcolor(h, t, False),
                    colorize(u'ok', t['ok'], None),
                    colorize(u'changed', t['changed'], None),
                    colorize(u'unreachable', t['unreachable'], None),
                    colorize(u'failed', t['failures'], None),
                    colorize(u'skipped', t['skipped'], None),
                    colorize(u'rescued', t['rescued'], None),
                    colorize(u'ignored', t['ignored'], None),
                ),
                log_only=True
            )
        table.columns[-1].footer = cell(overall_total, style='default')
        self._display.console.print(table)

        # print custom stats if required
        if stats.custom and self.show_custom_stats:
            self._display.banner("CUSTOM STATS: ")
            # per host
            # TODO: come up with 'pretty format'
            for k in sorted(stats.custom.keys()):
                if k == '_run':
                    continue
                self._display.display('\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace('\n', '')))

            # print per run custom stats
            if '_run' in stats.custom:
                self._display.display("", screen_only=True)
                self._display.display('\tRUN: %s' % self._dump_results(stats.custom['_run'], indent=1).replace('\n', ''))
            self._display.display("", screen_only=True)

        if context.CLIARGS['check'] and self.check_mode_markers:
            self._display.banner("DRY RUN")
示例#13
0
文件: _main.py 项目: euri10/httpx
def print_help() -> None:
    console = rich.console.Console()

    console.print("[bold]HTTPX :butterfly:", justify="center")
    console.print()
    console.print("A next generation HTTP client.", justify="center")
    console.print()
    console.print(
        "Usage: [bold]httpx[/bold] [cyan]<URL> [OPTIONS][/cyan] ", justify="left"
    )
    console.print()

    table = rich.table.Table.grid(padding=1, pad_edge=True)
    table.add_column("Parameter", no_wrap=True, justify="left", style="bold")
    table.add_column("Description")
    table.add_row(
        "-m, --method [cyan]METHOD",
        "Request method, such as GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD.\n"
        "[Default: GET, or POST if a request body is included]",
    )
    table.add_row(
        "-p, --params [cyan]<NAME VALUE> ...",
        "Query parameters to include in the request URL.",
    )
    table.add_row(
        "-c, --content [cyan]TEXT", "Byte content to include in the request body."
    )
    table.add_row(
        "-d, --data [cyan]<NAME VALUE> ...", "Form data to include in the request body."
    )
    table.add_row(
        "-f, --files [cyan]<NAME FILENAME> ...",
        "Form files to include in the request body.",
    )
    table.add_row("-j, --json [cyan]TEXT", "JSON data to include in the request body.")
    table.add_row(
        "-h, --headers [cyan]<NAME VALUE> ...",
        "Include additional HTTP headers in the request.",
    )
    table.add_row(
        "--cookies [cyan]<NAME VALUE> ...", "Cookies to include in the request."
    )
    table.add_row(
        "--auth [cyan]<USER PASS>",
        "Username and password to include in the request. Specify '-' for the password to use "
        "a password prompt. Note that using --verbose/-v will expose the Authorization "
        "header, including the password encoding in a trivially reversible format.",
    )

    table.add_row(
        "--proxy [cyan]URL",
        "Send the request via a proxy. Should be the URL giving the proxy address.",
    )

    table.add_row(
        "--timeout [cyan]FLOAT",
        "Timeout value to use for network operations, such as establishing the connection, "
        "reading some data, etc... [Default: 5.0]",
    )

    table.add_row("--follow-redirects", "Automatically follow redirects.")
    table.add_row("--no-verify", "Disable SSL verification.")
    table.add_row(
        "--http2", "Send the request using HTTP/2, if the remote server supports it."
    )

    table.add_row(
        "--download [cyan]FILE",
        "Save the response content as a file, rather than displaying it.",
    )

    table.add_row("-v, --verbose", "Verbose output. Show request as well as response.")
    table.add_row("--help", "Show this message and exit.")
    console.print(table)
示例#14
0
def print_entries(
    *,
    console: rich.console.Console,
    title: str,
    entries: Iterable[client.Entry],
    debug: bool,
    highlight_ids: AbstractSet[str] = frozenset(),
    center: bool = False,
    only_totals: bool = False,
    add_date: bool = False,
) -> None:
    table = rich.table.Table(
        title=title,
        box=rich.box.ROUNDED,
    )
    table.add_column("Description", style="yellow")
    table.add_column("Start", style="cyan")
    table.add_column("End", style="cyan")
    table.add_column("Duration", style="dim cyan")
    table.add_column("Project")
    table.add_column("Tags", style="blue")
    table.add_column(":gear:")  # icons

    total = datetime.timedelta()
    project_totals = collections.defaultdict(datetime.timedelta)

    time_format = "[b]%Y-%m-%d[/b] %H:%M" if add_date else "%H:%M"

    for entry in reversed(list(entries)):
        if debug:
            console.print(entry, highlight=True)

        data = []

        data.append(entry.description)

        assert entry.start is not None, entry
        data.append(entry.start.strftime(time_format))

        if entry.end is None:
            data.append(":clock3:")
            now = datetime.datetime.now(dateutil.tz.tzlocal())
            duration = now - entry.start
        else:
            data.append(entry.end.strftime(time_format))
            duration = entry.end - entry.start

        total += duration
        data.append(timedelta_str(duration))

        proj_key = (entry.project or "Other", entry.project_color or "default")
        project_totals[proj_key] += duration

        if entry.project is None:
            data.append("")
        else:
            data.append(
                f"[{entry.project_color}]{entry.project}[/{entry.project_color}]"
            )

        data.append(", ".join(entry.tags))

        icon = ""
        if entry.eid in highlight_ids:
            icon += ":sparkles:"
        if entry.billable:
            icon += ":heavy_dollar_sign:"
        data.append(icon)

        style = None
        if highlight_ids and entry.eid not in highlight_ids:
            style = rich.style.Style(dim=True)

        table.add_row(*data, style=style)

    if not only_totals:
        renderable = rich.align.Align(table, "center") if center else table
        console.print(renderable)

    justify = "center" if center else None
    grid = rich.table.Table.grid()
    grid.add_column()
    grid.add_column()
    grid.add_row("Total: ", timedelta_str(total), style="bold")
    for (proj, color), tag_total in sorted(project_totals.items()):
        grid.add_row(f"[{color}]{proj}[/{color}]: ", timedelta_str(tag_total))
    console.print(grid, justify=justify)
示例#15
0
def print_entries(
    console: rich.console.Console,
    date: datetime.date,
    entries: Iterable[client.Entry],
    *,
    debug: bool,
    workspace_name: str,
    highlight_ids: AbstractSet[str] = frozenset(),
    center: bool = False,
) -> None:
    console.print(f"[yellow]Workspace:[/yellow] {workspace_name}\n")
    date_str = date.strftime("%a, %Y-%m-%d")
    table = rich.table.Table(
        title=date_str,
        box=rich.box.ROUNDED,
    )
    table.add_column("Description", style="yellow")
    table.add_column("Start", style="cyan")
    table.add_column("End", style="cyan")
    table.add_column("Project")
    table.add_column("Tags", style="blue")
    table.add_column(":gear:")  # icons

    total = datetime.timedelta()
    project_totals = collections.defaultdict(datetime.timedelta)

    for entry in reversed(list(entries)):
        if debug:
            console.print(entry, highlight=True)

        data = []

        data.append(entry.description)

        assert entry.start is not None, entry
        data.append(entry.start.strftime("%H:%M"))

        if entry.end is None:
            data.append(":clock3:")
            now = datetime.datetime.now(dateutil.tz.tzlocal())
            duration = now - entry.start
        else:
            data.append(entry.end.strftime("%H:%M"))
            duration = entry.end - entry.start

        total += duration
        proj_key = (entry.project or "Other", entry.project_color or "default")
        project_totals[proj_key] += duration

        if entry.project is None:
            data.append("")
        else:
            data.append(
                f"[{entry.project_color}]{entry.project}[/{entry.project_color}]"
            )

        data.append(", ".join(entry.tags))

        icon = ""
        if entry.eid in highlight_ids:
            icon += ":sparkles:"
        if entry.billable:
            icon += ":heavy_dollar_sign:"
        data.append(icon)

        style = None
        if highlight_ids and entry.eid not in highlight_ids:
            style = rich.style.Style(dim=True)

        table.add_row(*data, style=style)

    renderable = rich.align.Align(table, "center") if center else table
    console.print(renderable)

    justify = "center" if center else None
    console.print(f"[b]Total: {timedelta_str(total)}[/b]", justify=justify)
    for (proj, color), tag_total in sorted(project_totals.items()):
        console.print(
            f"[{color}]{proj}[/{color}]: {timedelta_str(tag_total)}",
            justify=justify,
        )
示例#16
0
def __add_result_to_table(table: rich.table.Table,
                          result: "BaseResult",
                          level: int = 0) -> None:
    table.add_row(" " * level * NAME_INDENT + result.name, *result.info())
    for child in result.children:
        __add_result_to_table(table, child, level + 1)