serialdata/sr-info.py

Thu, 12 Nov 2020 20:26:35 +0100

author
David Douard <david.douard@sdf3.org>
date
Thu, 12 Nov 2020 20:26:35 +0100
changeset 53
74e85b34d26b
parent 23
daf26b083899
permissions
-rw-r--r--

Reorganize the display + improvements for dimmed flags

- the whole upper zone is now dediacated to the main character line
- make sure eash flag has a dedicated non-overlaping area
- improve support for dimmed flags (not yet properly functionning since this
dimm state is actually stateful, so some major refactorings are needed to
properly handle this).

import zipfile
import configparser


def extract_metadata(fname):
    cfg = configparser.ConfigParser()
    with zipfile.ZipFile(fname) as zf:
        mdata = zf.open('metadata').read()
    cfg.read_string(mdata.decode())
    return cfg


def print_metadata(mdata):
    for kv in mdata['global'].items():
        print('%s: %s' % kv)
    for device, cfg in mdata.items():
        if device in ('global', 'DEFAULT'):
            continue
        print('%s:' % device)
        for kv in cfg.items():
            print('  %s: %s' % kv)


if __name__ == '__main__':
    import sys
    for fn in sys.argv[1:]:
        print_metadata(extract_metadata(fn))

mercurial