def make_bom():
    """Generate a bill of materials and return the tt object."""

    finder = ModuleFinder()
    finder.run_script(sys.argv[0])
    tt = tytable.ttable()
    tt.add_option(tt.OPTION_LONGTABLE)
    tt.add_head(['name', 'ver', 'path', 'bytes', 'lines', 'sha-1'])
    tt.set_col_alignmnets("lllrrl")
    for inc in [False, True]:
        for name, mod in sorted(finder.modules.items()):
            if system_module(mod) != inc:
                continue  # don't use this one
            stats = file_stats(mod.__file__)
            ver = mod.globalnames.get('__version__', '---')
            if ver == 1 and name in sys.modules:
                # It has a version number; get it.
                try:
                    ver = sys.modules[name].__version__
                except AttributeError:
                    ver = '---'
            fname = mod.__file__
            if type(name) != str:
                name = ""
            if type(fname) != str:
                fname = ""
            tt.add_data([
                latex_tools.latex_escape(name), ver,
                latex_tools.latex_escape(fname), stats[0], stats[1], stats[2]
            ])
        tt.add_data(tt.HR)
    return tt
Exemplo n.º 2
0
def test_ttable():
    a = ttable()
    a.add_head(['Head One', 'Head Two'])
    a.add_data([1, 2])
    a.add_data(['foo', 'bar'])
    print(a.typeset(mode=a.LATEX))
    print(a.typeset(mode=a.HTML))

    a.add_data(['foo', 'bar'], annotations=['\\cellcolor{blue}', ''])
    assert 'blue' in a.typeset(mode=a.LATEX)
def make_runtime():
    """Generate information about the runtime and return the tt object"""
    tt = tytable.ttable()
    tt.set_col_alignment(0, tt.LEFT)
    tt.set_col_alignment(1, tt.LEFT)
    tt.add_data(tt.HR)
    for (k, v) in [["hostname", socket.gethostname()],
                   ["uptime", shell("uptime")],
                   ["time", datetime.datetime.now().isoformat()[0:19]]]:
        tt.add_data([k, v])
        tt.add_data(tt.HR)
    return tt