# HG changeset patch # User Paul Boddie # Date 1309090557 -7200 # Node ID 29c1a981024908cf449eb5202b8959d931738acd # Parent 36ceaeeee09185cf6d2c2b49ee85e90faf0b6bc1 Changed the title of generated graphs. diff -r 36ceaeeee091 -r 29c1a9810249 micropython/graph.py --- a/micropython/graph.py Sun Jun 19 02:07:58 2011 +0200 +++ b/micropython/graph.py Sun Jun 26 14:15:57 2011 +0200 @@ -21,28 +21,34 @@ from micropython.common import TableError from micropython.data import Class, Function -import sys +import sys, os -def get_graph(program, out=None): +def get_graph(program, out=None, filename=None): """ Using the importer maintained by the given 'program', write out the graph definition for consumption by the Graphviz tools such as the dot program. + If the optional 'out' parameter is set to a stream, that stream will be used to write out the graph definition; otherwise, standard output will be used. + If the optional 'filename' is specified, the leafname minus extension will + be used as the name of the graph. + A command line like the following can be used to produce viewable graph files: dot -T svg -o output.svg output.dot """ + filename = filename and os.path.splitext(os.path.split(filename)[-1])[0] or "program" + importer = program.get_importer() objtable = program.get_object_table() out = out or sys.stdout - print >>out, 'digraph G {' + print >>out, 'digraph %s {' % filename print >>out, ' ratio=auto;' print >>out, ' center=true;' print >>out, ' rankdir=LR;' diff -r 36ceaeeee091 -r 29c1a9810249 test.py --- a/test.py Sun Jun 19 02:07:58 2011 +0200 +++ b/test.py Sun Jun 26 14:15:57 2011 +0200 @@ -79,7 +79,7 @@ print "Generating graph as", graph f = open(graph, "w") try: - get_graph(p, f) + get_graph(p, f, filename) finally: f.close()