subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ne...@apache.org
Subject svn commit: r1312019 - in /subversion/trunk/tools/dev: merge-graph.py mergegraph/mergegraph.py
Date Tue, 10 Apr 2012 22:09:28 GMT
Author: neels
Date: Tue Apr 10 22:09:28 2012
New Revision: 1312019

URL: http://svn.apache.org/viewvc?rev=1312019&view=rev
Log:
Allow easily saving merge graphs to other file formats than PNG.

* tools/dev/mergegraph/mergegraph.py
  (MergeDot.__init__): Don't save the full target filename, just the basename.
  (MergeDot.save): New function.

* tools/dev/merge-graph.py:
    Add option '[-f png|svg|gif|dia...]', parse it with getopt and use above
    MergeDot.save() to write different file formats. Tweak messages and output
    accordingly.

Modified:
    subversion/trunk/tools/dev/merge-graph.py
    subversion/trunk/tools/dev/mergegraph/mergegraph.py

Modified: subversion/trunk/tools/dev/merge-graph.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/dev/merge-graph.py?rev=1312019&r1=1312018&r2=1312019&view=diff
==============================================================================
--- subversion/trunk/tools/dev/merge-graph.py (original)
+++ subversion/trunk/tools/dev/merge-graph.py Tue Apr 10 22:09:28 2012
@@ -19,25 +19,40 @@
 #    under the License.
 # ====================================================================
 
-args_message = 'GRAPH_CONFIG_FILE...'
+args_message = '[-f png|svg|gif|dia... [-f ...]] GRAPH_CONFIG_FILE...'
 help_message = """Produce pretty graphs representing branches and merging.
-For each config file specified, construct a graph and write it as a PNG file."""
+For each config file specified, construct a graph and write it as a PNG file
+(or other graphical file formats)."""
 
 import sys
+import getopt
 from mergegraph import MergeDot
 
 
 # If run as a program, process each input filename as a graph config file.
 if __name__ == '__main__':
+  optlist, args = getopt.getopt(sys.argv[1:], 'f:', ['format'])
+
   prog_name = sys.argv[0]
-  if len(sys.argv) == 1:
+  if not args:
     usage = '%s: usage: "%s %s"' % (prog_name, prog_name, args_message)
     print >> sys.stderr, usage
     sys.exit(1)
 
-  for config_filename in sys.argv[1:]:
-    print prog_name + ": reading '" + config_filename + "',",
-    graph = MergeDot(config_filename, rankdir='LR', dpi='72')
-    print "writing '" + graph.filename + "'"
-    graph.write_png(graph.filename)
+  formats = []
+
+  for opt, opt_arg in optlist:
+    if opt == '-f':
+      formats.append(opt_arg)
 
+  if not formats:
+    formats.append('png')
+
+  for config_filename in args:
+    print "%s: reading '%s'," % (prog_name, config_filename),
+    graph = MergeDot(config_filename, rankdir='LR', dpi='72')
+    for format in formats:
+      filename = '%s.%s' % (graph.basename, format)
+      print "writing '%s'" % filename,
+      graph.save(format=format, filename=filename)
+    print

Modified: subversion/trunk/tools/dev/mergegraph/mergegraph.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/dev/mergegraph/mergegraph.py?rev=1312019&r1=1312018&r2=1312019&view=diff
==============================================================================
--- subversion/trunk/tools/dev/mergegraph/mergegraph.py (original)
+++ subversion/trunk/tools/dev/mergegraph/mergegraph.py Tue Apr 10 22:09:28 2012
@@ -228,11 +228,11 @@ class MergeDot(MergeGraph, pydot.Dot):
     """Initialize a MergeDot graph's input data from a config file."""
     import ConfigParser
     if config_filename.endswith('.txt'):
-      default_filename = config_filename[:-4] + '.png'
+      default_basename = config_filename[:-4]
     else:
-      default_filename = config_filename + '.png'
+      default_basename = config_filename
 
-    config = ConfigParser.SafeConfigParser({ 'filename': default_filename,
+    config = ConfigParser.SafeConfigParser({ 'basename': default_basename,
                                              'title': None,
                                              'merges': '[]',
                                              'annotations': '[]' })
@@ -240,7 +240,7 @@ class MergeDot(MergeGraph, pydot.Dot):
     if len(files_read) == 0:
       print >> sys.stderr, 'graph: unable to read graph config from "' + config_filename
+ '"'
       sys.exit(1)
-    graph.filename = config.get('graph', 'filename')
+    graph.basename = config.get('graph', 'basename')
     graph.title = config.get('graph', 'title')
     graph.branches = eval(config.get('graph', 'branches'))
     graph.changes = eval(config.get('graph', 'changes'))
@@ -294,3 +294,11 @@ class MergeDot(MergeGraph, pydot.Dot):
     if graph.title:
       graph.add_node(Node('title', shape='plaintext', label='"' + graph.title + '"'))
 
+  def save(graph, format='png', filename=None):
+    """Save this merge graph to the given file format. If filename is None,
+       construct a filename from the basename of the original file (as passed
+       to the constructor and then stored in graph.basename) and the suffix
+       according to the given format."""
+    if not filename:
+      filename = graph.basename + '.' + format
+    pydot.Dot.write(graph, filename, format=format)



Mime
View raw message