serialdata/sr-info.py

Sun, 01 Nov 2020 22:10:10 +0100

author
David Douard <david.douard@sdf3.org>
date
Sun, 01 Nov 2020 22:10:10 +0100
changeset 40
069bbd5ee3e4
parent 23
daf26b083899
permissions
-rw-r--r--

SSD1322: add power off/on methods

23
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 import zipfile
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2 import configparser
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5 def extract_metadata(fname):
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6 cfg = configparser.ConfigParser()
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 with zipfile.ZipFile(fname) as zf:
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 mdata = zf.open('metadata').read()
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9 cfg.read_string(mdata.decode())
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 return cfg
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
12
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13 def print_metadata(mdata):
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 for kv in mdata['global'].items():
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
15 print('%s: %s' % kv)
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
16 for device, cfg in mdata.items():
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 if device in ('global', 'DEFAULT'):
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18 continue
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19 print('%s:' % device)
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20 for kv in cfg.items():
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21 print(' %s: %s' % kv)
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24 if __name__ == '__main__':
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25 import sys
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 for fn in sys.argv[1:]:
daf26b083899 Add the serialdata tool
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 print_metadata(extract_metadata(fn))

mercurial