gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r984515 - /gump/trunk/python/gump/tool/dot/dot.py
Date Wed, 11 Aug 2010 18:26:02 GMT
Author: bodewig
Date: Wed Aug 11 18:26:02 2010
New Revision: 984515

URL: http://svn.apache.org/viewvc?rev=984515&view=rev
Log:
allow to emit the dependency graph for a set of projects that match an expression

Modified:
    gump/trunk/python/gump/tool/dot/dot.py

Modified: gump/trunk/python/gump/tool/dot/dot.py
URL: http://svn.apache.org/viewvc/gump/trunk/python/gump/tool/dot/dot.py?rev=984515&r1=984514&r2=984515&view=diff
==============================================================================
--- gump/trunk/python/gump/tool/dot/dot.py (original)
+++ gump/trunk/python/gump/tool/dot/dot.py Wed Aug 11 18:26:02 2010
@@ -18,28 +18,53 @@
 import sys
 from gump.core.config import default
 from gump.core.loader.loader import WorkspaceLoader
-from gump.core.run.gumpset import GumpSet
+from gump.core.run.gumprun import GumpRun
 
 def write_to_dot_file(gump_set, dot_file_name):
     """
     Writes a dependency graph for the given GumpSet to the named file
     using the DOT language.
     """
+    hull = set(p.getName() for p in gump_set.getProjects())
+
     dot = open(dot_file_name, "w")
     dot.write("digraph {\n")
     for project in gump_set.getProjects():
-        for dep in project.getDirectDependencies():
-            dot.write('\t"%s" -> "%s"\n' % (project.getName(),
-                                            dep.getProject().getName()))
-        for dep in project.get_removed_dependencies():
-            dot.write('\t"%s" -> "%s" [color = red]\n' %
-                      (project.getName(), dep.getProject().getName()))
+        _write_edges_for_project(project, dot, hull)
     dot.write("}\n")
 
+def _write_edges_for_project(project, dot, hull):
+    """
+    Writes all edges starting in project and may recurse into all
+    dependencies unless they are already contained in the set of
+    projects to visit/visited
+    """
+    for dep in project.getDirectDependencies():
+        _write_edge_and_maybe_recurse(project, dep.getProject(), '', dot, hull)
+    for dep in project.get_removed_dependencies():
+        _write_edge_and_maybe_recurse(project, dep.getProject(),
+                                      ' [color = red]', dot, hull)
+
+def _write_edge_and_maybe_recurse(left, right, style, dot, hull):
+    """
+    Writes a single edgre from left to right and may recurse into
+    right unless it is already contained in the set of projects to
+    visit/visited
+    """
+    dot.write('\t"%s" -> "%s"%s\n' % (left.getName(), right.getName(), style))
+    if not right.getName() in hull:
+        hull.add(right.getName())
+        _write_edges_for_project(right, dot, hull)
+
 if __name__ == '__main__':
-    if len(sys.argv) != 3:
-        print "requires exactly two args: worksapce and outputfile"
+    if not len(sys.argv) in [3, 4]:
+        print "requires two args: workspace and outputfile and has one " + \
+            "optional: project"
         exit(1)
     default.date_s = default.datetime.strftime('YYYYMMDD')
+    default.datetime_s = default.datetime.strftime('YYYYMMDD-hhmmss')
     WORKSPACE = WorkspaceLoader().load(sys.argv[1])
-    write_to_dot_file(GumpSet(WORKSPACE), sys.argv[2])
+    write_to_dot_file(GumpRun(WORKSPACE,
+                              len(sys.argv) == 4 and sys.argv[3] or None)
+                      .getGumpSet(),
+                      sys.argv[2])



Mime
View raw message