]> git.rmz.io Git - dotfiles.git/commitdiff
add graph.py
authorSamir Benmendil <ram-z@chakra-project.org>
Sun, 6 Jan 2013 19:55:45 +0000 (20:55 +0100)
committerSamir Benmendil <ram-z@chakra-project.org>
Sun, 6 Jan 2013 19:55:45 +0000 (20:55 +0100)
bin/graph.py [new file with mode: 0755]

diff --git a/bin/graph.py b/bin/graph.py
new file mode 100755 (executable)
index 0000000..4521a5c
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/python2
+# attempt to create a graph showing package dependencies 
+# in a nice graph
+
+from __future__ import print_function
+import os
+#import sys
+import collections
+import argparse
+import logging
+import re
+from time import sleep
+import pygraphviz as pgv
+
+pkgs = os.popen("""LANGUAGE=C pacman -Ssq "^libpng$" """).read().strip().split("\n")
+print(pkgs)
+pkglist = os.popen("LANGUAGE=C pacman -Si").read().strip().split("\n\n")
+G = pgv.AGraph(directed=True)
+p = re.compile(r"[<>=].*")
+for pkg in pkglist:
+    lines = pkg.splitlines()
+    repo = lines[0][17:]
+    name = lines[1][17:]
+    depends = lines[8][17:].split()
+    for dep in depends:
+        if dep != "None":
+            dep = p.sub("",dep)
+            G.add_edge(dep,name)
+
+all_n = set(G.nodes())
+n = set(pkgs)
+for pkg in pkgs:
+    n |= set(G.successors(pkg))
+    n |= set(G.predecessors(pkg))
+
+G.remove_nodes_from(all_n - n)
+    
+
+G.write("graph.dot")
+#G.draw("graph.svg",prog='dot')