Return-Path: X-Original-To: apmail-subversion-commits-archive@minotaur.apache.org Delivered-To: apmail-subversion-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6D6139C92 for ; Tue, 10 Apr 2012 22:09:50 +0000 (UTC) Received: (qmail 78442 invoked by uid 500); 10 Apr 2012 22:09:50 -0000 Delivered-To: apmail-subversion-commits-archive@subversion.apache.org Received: (qmail 78420 invoked by uid 500); 10 Apr 2012 22:09:50 -0000 Mailing-List: contact commits-help@subversion.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@subversion.apache.org Delivered-To: mailing list commits@subversion.apache.org Received: (qmail 78412 invoked by uid 99); 10 Apr 2012 22:09:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Apr 2012 22:09:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Apr 2012 22:09:48 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D8DB5238890B; Tue, 10 Apr 2012 22:09:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1312019 - in /subversion/trunk/tools/dev: merge-graph.py mergegraph/mergegraph.py Date: Tue, 10 Apr 2012 22:09:28 -0000 To: commits@subversion.apache.org From: neels@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120410220928.D8DB5238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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)