summaryrefslogtreecommitdiff
path: root/parse_datasheet/parse_320066.py
diff options
context:
space:
mode:
authorNoe Rubinstein <nrubinstein@avencall.com>2012-04-02 11:03:29 +0200
committerNoe Rubinstein <nrubinstein@avencall.com>2012-04-02 11:03:29 +0200
commit2d87b59fdded1589ba0372abb147673f05bd65f6 (patch)
tree4606d0a3e556ccfb8ccd4ee34ad371fd72f5d26c /parse_datasheet/parse_320066.py
parenteca89c3d6c2d4012dc6c63b1e0e579466d81e65a (diff)
Dump {SMRBASE,GbE} as {JSON,Python,Pickle}
Diffstat (limited to 'parse_datasheet/parse_320066.py')
-rwxr-xr-xparse_datasheet/parse_320066.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/parse_datasheet/parse_320066.py b/parse_datasheet/parse_320066.py
index 6e4c002..75efe14 100755
--- a/parse_datasheet/parse_320066.py
+++ b/parse_datasheet/parse_320066.py
@@ -2,6 +2,8 @@
import cPickle as pickle
import sys
+from pprint import pprint
+import json
from datasheet_tables import load_datasheet_pages, \
abs_tables_from_pages, \
@@ -28,12 +30,27 @@ def print_stuff(a_t, options):
print
print
+def make_t(t):
+ d = {
+ "offset": t.offset,
+ "fields": [dict(c.simple_datastructure() for c in l.cells)
+ for l in t.lines]
+ }
+ d.update((h, getattr(t, h)) for h, _ in t.HeaderAttr)
+ return d
+
+def make_stuff(a_t):
+ return dict((t.reg_name, make_t(t)) for t in a_t.tables)
def main():
from optparse import OptionParser
parser = OptionParser(usage="usage: %prog [options] <tables_group> datasheet.xml")
+ parser.add_option("-H", "--human", action="store_true", dest="human", help="print a human-readable description")
+ parser.add_option("-j", "--json", action="store_true", dest="json", help="save parsed data to JSON")
+ parser.add_option("-P", "--python", action="store_true", dest="python", help="dump datastructure in Python")
parser.add_option("-p", "--pickle", dest="pickle_filename",
help="save parsed data to PICKLE", metavar="PICKLE")
+ parser.add_option("-f", "--filename", dest="filename", help="Write data to file instead of stdout")
parser.add_option("-W", "--Warning-only", action="store_true",
dest="warning_only", default=False,
help="only display tables for which a problem "
@@ -45,7 +62,7 @@ def main():
try:
datasheet = args[1]
except IndexError:
- datasheet = "/home/xilun/hard/cooked/datasheet_320066.xml"
+ datasheet = "datasheet_320066.xml"
tables_group = args[0]
profile = profile_factory(tables_group)
@@ -53,12 +70,22 @@ def main():
pages = load_datasheet_pages(datasheet, profile.min_page, profile.max_page)
a_t = abs_tables_from_pages(pages, profile)
- print_stuff(a_t, options)
+ out = open(options.filename, 'w') if options.filename else sys.stdout
+
+ if options.human:
+ print_stuff(a_t, options)
+ elif options.python:
+ pprint(make_stuff(a_t), out)
+ elif options.json:
+ import json
+ print json.dump(make_stuff(a_t), out, indent=4)
+
+ if out is not sys.stdout:
+ out.close()
if options.pickle_filename:
f = open(options.pickle_filename, "wb")
pickle.dump(a_t, f, -1)
f.close()
-
sys.exit(main())