]> hydra-www.ietfng.org Git - dyna2/commitdiff
ENH: dump-to-file/display stable rendering of chart.
authortimv <tim.f.vieira@gmail.com>
Wed, 12 Dec 2012 21:19:27 +0000 (16:19 -0500)
committertimv <tim.f.vieira@gmail.com>
Wed, 12 Dec 2012 21:19:27 +0000 (16:19 -0500)
bin/stdlib.py

index a9ffe5341e8713da0c919fed0dcdcd64eabebaab..e8f0e19333ba6a3028fcebc24edc81e5b2bd903a 100644 (file)
@@ -24,19 +24,24 @@ class chart_indirect(dict):
 
 chart = chart_indirect()
 
-def dump_charts():
-    print
-    print 'Charts'
-    print '============'
-    for x in chart:
-        print x
-
-        zzz = [(pretty((x,idx)), idx, row, row[-1]) for idx, row in chart[x].data.items()]
-        zzz.sort()
-
-        for p, i, _, v in zzz:
-            print '%s: %-30s := %s' % (i, p, v)
-        print
+def dump_charts(out=sys.stdout):
+    print >> out
+    print >> out, 'Charts'
+    print >> out, '============'
+
+    fns = chart.keys()
+    fns.sort()
+
+    for x in fns:
+        print >> out, x
+        print >> out, '====================================='
+
+        rows = [(pretty((x,idx)), idx, row, row[-1]) for idx, row in chart[x].data.items()]
+        rows.sort()
+
+        for p, _, _, v in rows:
+            print >> out, '%-30s := %s' % (p, v)
+        print >> out
 
 
 class Chart(object):
@@ -96,7 +101,10 @@ def pretty(item):
     row = chart[fn].data[idx]
     args = row[:-1]
     fn = ''.join(fn.split('/')[:-1])  # drop arity from name.
-    return '%s(%s)' % (fn, ','.join(map(pretty, args)))
+    pretty_args = map(pretty, args)
+    if not len(pretty_args):          # zero arity -> no parens.
+        return fn
+    return '%s(%s)' % (fn, ','.join(pretty_args))
 
 
 def prettify(x):
@@ -261,6 +269,10 @@ def run():
     finally:
         dump_charts()
 
+        with file(dyna + '.chart', 'wb') as f:
+            dump_charts(f)
+
+
 
 # Example of reactivity
 #  >>> emit(('rewrite/3', 5), -1000)