[csw-devel] SF.net SVN: opencsw:[558] utilities/pkgutil-deptree-to-dot.py

skayser at users.sourceforge.net skayser at users.sourceforge.net
Mon Sep 26 17:50:56 CEST 2011


Revision: 558
          http://opencsw.svn.sourceforge.net/opencsw/?rev=558&view=rev
Author:   skayser
Date:     2011-09-26 15:50:56 +0000 (Mon, 26 Sep 2011)
Log Message:
-----------
utilities: add pkgutil deptree to graphviz converter

Added Paths:
-----------
    utilities/pkgutil-deptree-to-dot.py

Added: utilities/pkgutil-deptree-to-dot.py
===================================================================
--- utilities/pkgutil-deptree-to-dot.py	                        (rev 0)
+++ utilities/pkgutil-deptree-to-dot.py	2011-09-26 15:50:56 UTC (rev 558)
@@ -0,0 +1,82 @@
+#!/opt/csw/bin/python
+#
+# Reads pkgutil deptree output from stdin to generate a dot dependency graph
+#   pkgutil --deptree=X <pkg>
+#
+# pkgutil output looks like this
+#
+# - - - CSWxz
+# - - - - CSWcommon
+# - - - - CSWlibintl8
+# - - - - - CSWcommon
+# - - - - - CSWiconv
+# - - - - - - CSWcommon
+# - - - - - - CSWlibcharset1
+# - - - - - - - CSWcommon
+# - - - - - - CSWlibiconv2
+# - - - - CSWlibfoo
+
+import os
+import sys
+
+skip = ( "CSWcswclassutils", "CSWcas-", "CSWcommon" )
+
+def pkg_on_skiplist(pkg):
+  for s in skip:
+    if pkg.startswith(s): return True
+  return False
+
+# skip pkgs on skiplist, including their dependencies
+def skip_pkg(pkg, depth):
+  skipdepth = getattr(skip_pkg, "skipdepth", None)
+  if skipdepth and depth >= skipdepth: return True
+  elif pkg_on_skiplist(pkg):
+    skip_pkg.skipdepth = depth+1
+    return True
+  else:
+    skip_pkg.skipdepth = None
+    return False
+
+def read_from_stdin():
+  for l in sys.stdin.readlines():
+    if not (l.startswith("CSW") or l.startswith("-")): continue
+    yield(l)
+
+
+if __name__=='__main__':
+
+  deps = {}
+  parents = {}
+  pkglist = {}
+
+  # process input from stdin / pkgutil
+  for l in read_from_stdin():
+    pkg = l.split()[-1].strip("-")
+    depth = l.count("- ")
+    if skip_pkg(pkg, depth): continue
+  
+    pkglist[pkg] = True
+    parents[depth+1] = pkg
+    parent = parents.get(depth)
+  
+    if parent:
+      dep = '"%s" -> "%s";' % (parent, pkg)
+      deps[dep] = True
+  
+  if deps:
+    print """
+      digraph g {
+        label = "Dependency tree for package: %s\\n" +
+                "Nr of packages: %s\\n" +
+                "Depth (probably limited): %s\\n" +
+                "Generated with pkgutil --deptree, %s, and graphviz"
+        labelloc = t
+        labeljust = l
+        %s
+      }""" % (
+        parents[parents.keys()[0]],
+        len(pkglist),
+        len(parents.keys()),
+        os.path.basename(sys.argv[0]),
+        "\n".join(deps.keys())
+      )


Property changes on: utilities/pkgutil-deptree-to-dot.py
___________________________________________________________________
Added: svn:executable
   + *

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list