How to use the prettytable.HEADER function in prettytable

To help you get started, we’ve selected a few prettytable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ARMmbed / mbed-os / tools / test_api.py View on Github external
""" Prints test specification configuration passed to test script for verboseness
    """
    toolchains_info_cols = []
    # We need to check all toolchains for each device
    for k in json_data:
        # k should be 'targets'
        targets = json_data[k]
        for target in targets:
            toolchains = targets[target]
            for toolchain in toolchains:
                if toolchain not in toolchains_info_cols:
                    toolchains_info_cols.append(toolchain)

    # Prepare pretty table object to display test specification
    pt_cols = ["mcu"] + sorted(toolchains_info_cols)
    pt = PrettyTable(pt_cols, junction_char="|", hrules=HEADER)
    for col in pt_cols:
        pt.align[col] = "l"

    # { target : [conflicted toolchains] }
    toolchain_conflicts = {}
    toolchain_path_conflicts = []
    for k in json_data:
        # k should be 'targets'
        targets = json_data[k]
        for target in targets:
            target_supported_toolchains = get_target_supported_toolchains(target)
            if not target_supported_toolchains:
                target_supported_toolchains = []
            target_name = target if target in TARGET_MAP else "%s*"% target
            row = [target_name]
            toolchains = targets[target]
github run2fail / locker / locker / project.py View on Github external
def status(self, *, containers=None):
        ''' Show status of all project specific containers

        TODO Status report functionality requires some refactoring

        :param containers: List of containers or None (== all containers)
        '''
        if not self.args.get('extended', False):
            header = ['Def.', 'Name', 'FQDN', 'State', 'IPs', 'Ports', 'Links']
        else:
            header = ['Def.', 'Name', 'FQDN', 'State', 'IPs', 'Ports', 'Links', 'CPUs', 'Shares', 'Memory [MB]']
        table = prettytable.PrettyTable(header)
        table.align = 'l'
        table.hrules = prettytable.HEADER
        table.vrules = prettytable.NONE
        table.align['CPUs'] = 'r'
        table.align['Shares'] = 'r'
        table.align['Memory [MB]'] = 'r'

        for container in containers:
            defined = container.defined
            name = container.name.split('_')[1]
            state = container.state
            fqdn = container.yml.get('fqdn', '')
            ips = container.get_ips()
            if ips:
                ips = ','.join(ips)
            dnat_rules = container.get_port_rules()
            ports = rules_to_str(dnat_rules)
            reset_color = Fore.RESET if container.color else ''
github run2fail / locker / project.py View on Github external
for rule in [rul for rul in locker_nat_chain.rules if rul.protocol in ['tcp', 'udp']]:
                    for match in rule.matches:
                        if match.name == 'comment' and match.comment == container.name:
                            dport = [m.dport for m in rule.matches if m.name in ['tcp', 'udp']][0]
                            to_ip, to_port = rule.target.to_destination.split(':')
                            dnat_rules.append((rule.protocol, (rule.dst, dport), (to_ip, to_port)))
            except iptc.IPTCError:
                container.logger.warn('An arror occured searching the netfiler rules')
            return dnat_rules

        if containers == None:
            containers = self.containers

        table = prettytable.PrettyTable(['Def.', 'Name', 'FQDN', 'State', 'IPs', 'Ports'])
        table.align = 'l'
        table.hrules = prettytable.HEADER
        table.vrules = prettytable.NONE
        for container in containers:
            defined = container.defined
            name = container.name
            state = container.state
            fqdn = '' if 'fqdn' not in container.yml else container.yml['fqdn']
            ips = '-'
            if container.running:
                ips = ','.join(container.get_ips())
            dnat_rules = get_netfiler_rules(container)
            ports = '\n'.join(['%s:%s->%s/%s' % (dip.split('/')[0], dport, to_port, proto) for proto, (dip, dport), (to_ip, to_port) in dnat_rules])
            table.add_row(['%s%s%s' % (container.color, x, Fore.RESET) for x in [defined, name, fqdn, state, ips, ports]])
        print(table)
github ARMmbed / mbed-os / tools / export / __init__.py View on Github external
def mcu_ide_matrix(verbose_html=False):
    """Shows target map using prettytable

    Keyword argumets:
    verbose_html - print the matrix in html format
    """
    supported_ides = sorted(EXPORTERS.keys())
    # Only use it in this function so building works without extra modules
    from prettytable import PrettyTable, HEADER

    # All tests status table print
    table_printer = PrettyTable(["Platform"] + supported_ides, junction_char="|", hrules=HEADER)
    # Align table
    for col in supported_ides:
        table_printer.align[col] = "c"
    table_printer.align["Platform"] = "l"

    perm_counter = 0
    for target in sorted(TARGET_NAMES):
        row = [target]  # First column is platform name
        for ide in supported_ides:
            text = "-"
            if EXPORTERS[ide].is_target_supported(target):
                if verbose_html:
                    text = "✓"
                else:
                    text = "x"
                perm_counter += 1
github ARMmbed / mbed-os / tools / memap.py View on Github external
def generate_table(self, file_desc):
        """Generate a table from a memoy map

        Returns: string of the generated table
        """
        # Create table
        columns = ['Module']
        columns.extend(self.print_sections)

        table = PrettyTable(columns, junction_char="|", hrules=HEADER)
        table.align["Module"] = "l"
        for col in self.print_sections:
            table.align[col] = 'r'

        for i in list(self.print_sections):
            table.align[i] = 'r'

        for i in sorted(self.short_modules):
            row = [i]

            for k in self.print_sections:
                row.append("{}({:+})".format(
                    self.short_modules[i][k],
                    self.short_modules[i][k + "-delta"]
                ))
github ARMmbed / mbed-os / tools / build_api.py View on Github external
def print_build_memory_usage(report):
    """ Generate result table with memory usage values for build results
    Aggregates (puts together) reports obtained from self.get_memory_summary()

    Positional arguments:
    report - Report generated during build procedure.
    """
    from prettytable import PrettyTable, HEADER
    columns_text = ['name', 'target', 'toolchain']
    columns_int = ['static_ram', 'total_flash']
    table = PrettyTable(columns_text + columns_int, junction_char="|", hrules=HEADER)

    for col in columns_text:
        table.align[col] = 'l'

    for col in columns_int:
        table.align[col] = 'r'

    for target in report:
        for toolchain in report[target]:
            for name in report[target][toolchain]:
                for dlist in report[target][toolchain][name]:
                    for dlistelem in dlist:
                        # Get 'memory_usage' record and build table with
                        # statistics
                        record = dlist[dlistelem]
                        if 'memory_usage' in record and record['memory_usage']:
github raimon49 / pip-licenses / piplicenses.py View on Github external
def factory_styled_table_with_args(args, output_fields=DEFAULT_OUTPUT_FIELDS):
    table = PrettyTable()
    table.field_names = output_fields
    table.align = 'l'
    table.border = (args.format == 'markdown' or args.format == 'rst' or
                    args.format == 'confluence' or args.format == 'json')
    table.header = True

    if args.format == 'markdown':
        table.junction_char = '|'
        table.hrules = RULE_HEADER
    elif args.format == 'rst':
        table.junction_char = '+'
        table.hrules = RULE_ALL
    elif args.format == 'confluence':
        table.junction_char = '|'
        table.hrules = RULE_NONE
    elif args.format == 'json':
        table = JsonPrettyTable(table.field_names)
    elif args.format == 'json-license-finder':
        table = JsonLicenseFinderTable(table.field_names)
    elif args.format == 'csv':
        table = CSVPrettyTable(table.field_names)
    elif args.format == 'plain-vertical':
        table = PlainVerticalTable(table.field_names)

    return table
github ceph / ceph / src / pybind / ceph_daemon.py View on Github external
def list(self, ostr=sys.stdout):
        """
        Show all selected stats with section, full name, nick, and prio
        """
        table = PrettyTable(('section', 'name', 'nick', 'prio'))
        table.align['section'] = 'l'
        table.align['name'] = 'l'
        table.align['nick'] = 'l'
        table.align['prio'] = 'r'
        self._load_schema()
        for section_name, section_stats in self._stats.items():
            for name, nick in section_stats.items():
                prio = self._schema[section_name][name].get('priority') or 0
                table.add_row((section_name, name, nick, prio))
        ostr.write(table.get_string(hrules=HEADER) + '\n')
github albertodonato / sshoot / sshoot / listing.py View on Github external
titles = ["", NAME_FIELD]
        titles.extend(_FIELDS_MAP)
        columns = list(_FIELDS_MAP.values())
        if not verbose:
            # Only basic info
            titles = titles[:4]
            columns = columns[:2]

        table = PrettyTable(titles)
        table.align = "l"
        table.vertical_char = " "
        table.junction_char = table.horizontal_char
        table.padding_width = 0
        table.left_padding_width = 0
        table.right_padding_width = 1
        table.hrules = HEADER

        for name, profile in profiles_iter:
            row = ["*" if self.manager.is_running(name) else "", name]
            row.extend(_format_value(getattr(profile, column)) for column in columns)
            table.add_row(row)
        return table.get_string(sortby=NAME_FIELD) + "\n"
github ARMmbed / mbed-os / tools / build_api.py View on Github external
release_targets = version_release_targets[release_version]
    else:
        release_targets = None

    unique_supported_toolchains = get_unique_supported_toolchains(
        release_targets)
    #Add ARMC5 column as well to the matrix to help with showing which targets are in ARMC5
    #ARMC5 is not a toolchain class but yet we use that as a toolchain id in supported_toolchains in targets.json
    #capture that info in a separate column
    unique_supported_toolchains.append('ARMC5')

    prepend_columns = ["Target"] + ["mbed OS %s" % x for x in RELEASE_VERSIONS]

    # All tests status table print
    columns = prepend_columns + unique_supported_toolchains
    table_printer = PrettyTable(columns, junction_char="|", hrules=HEADER)
    # Align table
    for col in columns:
        table_printer.align[col] = "c"
    table_printer.align["Target"] = "l"

    perm_counter = 0
    target_counter = 0

    target_names = []

    if release_targets:
        target_names = [x[0] for x in release_targets]
    else:
        target_names = TARGET_NAMES

    for target in sorted(target_names):