Python tabulate.tabulate_formats() Examples

The following are 9 code examples of tabulate.tabulate_formats(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tabulate , or try the search function .
Example #1
Source File: syscall_extractor.py    From mayhem with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def main():
	output_formats = copy.copy(tabulate.tabulate_formats)
	output_formats.append('json')
	parser = argparse.ArgumentParser(description='syscall_extractor: Extract syscalls from a Windows PE file', conflict_handler='resolve')
	parser.add_argument('-f', '--format', dest='output_format', default='simple', choices=output_formats, help='output format')
	parser.add_argument('pe_files', nargs='+', help='pe files to extract syscall numbers from')
	args = parser.parse_args()

	parsed_files = []
	for pe_file in args.pe_files:
		parsed_files.append(extract_syscalls(os.path.abspath(pe_file)))
	parsed_files = list(pe_file for pe_file in parsed_files if pe_file)
	print("[+] Found {0:,} syscalls".format(sum(len(pe_file['syscalls']) for pe_file in parsed_files)))

	if args.output_format == 'json':
		print(json.dumps(parsed_files, sort_keys=True, indent=2, separators=(',', ': ')))
	else:
		syscalls = []
		for pe_file in parsed_files:
			syscalls.extend(pe_file['syscalls'])
		syscalls = ((syscall[0], hex(syscall[1]), syscall[2], syscall[3]) for syscall in syscalls)
		print(tabulate.tabulate(syscalls, headers=('Number', 'RVA', 'Name', 'Ordinal'), tablefmt=args.output_format))
	return 0 
Example #2
Source File: run_server.py    From flask-gopher with GNU General Public License v3.0 6 votes vote down vote up
def tables():
    """
    Render an ascii table using all possible styles provided by tabulate.
    """
    data = [
        ('text', 'int', 'float'),
        ('Cell 1', 100, 1/3),
        ('Cell 2', -25, 0.001),
        ('Cell 3', 0, 0)
    ]
    lines = []
    for table_fmt in tabulate_formats:
        lines.append(table_fmt)
        lines.append('')
        lines.append(gopher.formatter.tabulate(data, 'firstrow', table_fmt))
        lines.append('\n')
    return gopher.render_menu(*lines) 
Example #3
Source File: metrics.py    From mikado with GNU Lesser General Public License v3.0 6 votes vote down vote up
def metric_parser():

    """
    Command line parser for the utility.
    """

    parser = argparse.ArgumentParser("Script to generate the available metrics")
    parser.add_argument("-f", "--format",
                        help="Format of the table to be printed out.",
                        choices=tabulate.tabulate_formats, default="rst")
    parser.add_argument("-o", "--out",
                        help="Optional output file",
                        type=argparse.FileType("w"), default=sys.stdout)
    parser.add_argument("-c", "--category",
                        help="Available categories to select from.",
                        default=[], nargs="+",
                        choices=sorted(set(
                            [_ for _ in [getattr(getattr(Transcript, metric), "category", "Descriptive") for metric in
                             Transcript.get_available_metrics()] if _ is not None] + ["Descriptive"])))
    parser.add_argument("metric", nargs="*")
    parser.set_defaults(func=launch)
    return parser 
Example #4
Source File: class_codes.py    From mikado with GNU Lesser General Public License v3.0 6 votes vote down vote up
def code_parser():

    """
    Command line parser for the utility.
    """

    parser = argparse.ArgumentParser("Script to generate the available class codes.")
    parser.add_argument("-f", "--format", choices=tabulate.tabulate_formats, default="rst")
    parser.add_argument("-c", "--category", nargs="+", default=[],
                        choices=list(set(_.category for _ in class_codes.codes.values())))
    parser.add_argument("-o", "--out", type=argparse.FileType("w"), default=sys.stdout)
    parser.add_argument("code", nargs="*", help="Codes to query.",
                        default=[],
                        choices=[[]] + list(class_codes.codes.keys()))
    parser.set_defaults(func=launch)
    return parser 
Example #5
Source File: test_api.py    From python-tabulate with MIT License 5 votes vote down vote up
def test_tabulate_formats():
    "API: tabulate_formats is a list of strings" ""
    supported = tabulate_formats
    print("tabulate_formats = %r" % supported)
    assert type(supported) is list
    for fmt in supported:
        assert type(fmt) is type("")  # noqa 
Example #6
Source File: test_api.py    From python-tabulate with MIT License 5 votes vote down vote up
def test_tabulate_formats():
    "API: tabulate_formats is a list of strings"""
    supported = tabulate_formats
    print("tabulate_formats = %r" % supported)
    assert type(supported) is list
    for fmt in supported:
        assert type(fmt) is type("") 
Example #7
Source File: _bootstrap.py    From armi with Apache License 2.0 5 votes vote down vote up
def _addCustomTabulateTables():
    """Create a custom ARMI tables within tabulate."""
    tabulate._table_formats["armi"] = tabulate.TableFormat(
        lineabove=tabulate.Line("", "-", "  ", ""),
        linebelowheader=tabulate.Line("", "-", "  ", ""),
        linebetweenrows=None,
        linebelow=tabulate.Line("", "-", "  ", ""),
        headerrow=tabulate.DataRow("", "  ", ""),
        datarow=tabulate.DataRow("", "  ", ""),
        padding=0,
        with_header_hide=None,
    )
    tabulate.tabulate_formats = list(sorted(tabulate._table_formats.keys()))
    tabulate.multiline_formats["armi"] = "armi"


# runLog makes tables, so make sure this is setup before we initialize the runLog 
Example #8
Source File: cli.py    From sqlite-utils with Apache License 2.0 5 votes vote down vote up
def output_options(fn):
    for decorator in reversed(
        (
            click.option(
                "--nl",
                help="Output newline-delimited JSON",
                is_flag=True,
                default=False,
            ),
            click.option(
                "--arrays",
                help="Output rows as arrays instead of objects",
                is_flag=True,
                default=False,
            ),
            click.option("-c", "--csv", is_flag=True, help="Output CSV"),
            click.option("--no-headers", is_flag=True, help="Omit CSV headers"),
            click.option("-t", "--table", is_flag=True, help="Output as a table"),
            click.option(
                "-f",
                "--fmt",
                help="Table format - one of {}".format(
                    ", ".join(tabulate.tabulate_formats)
                ),
                default="simple",
            ),
            click.option(
                "--json-cols",
                help="Detect JSON cols and output them as JSON, not escaped strings",
                is_flag=True,
                default=False,
            ),
        )
    ):
        fn = decorator(fn)
    return fn 
Example #9
Source File: command_stats.py    From biggraphite with Apache License 2.0 5 votes vote down vote up
def add_arguments(self, parser):
        """Add custom arguments.

        See command.CommandBase.
        """
        command.add_sharding_arguments(parser)
        parser.add_argument(
            "-c", "--conf", help="Configuration file for namespaces", dest="conf"
        )

        formats = tabulate.tabulate_formats
        formats.append("graphite")
        parser.add_argument(
            "-f", "--format", help="Format: %s" % ", ".join(formats), dest="fmt"
        )
        parser.add_argument(
            "--carbon",
            help="Carbon host:port to send points to when using graphite output."
        )
        parser.add_argument(
            "--prefix",
            help="Prefix to add to every section name.",
            default='',
        )
        self._n_metrics = collections.defaultdict(int)
        self._n_points = collections.defaultdict(int)