Skip to content

Instantly share code, notes, and snippets.

@jsoffer
Created December 5, 2013 18:45
Show Gist options
  • Save jsoffer/7810955 to your computer and use it in GitHub Desktop.
Save jsoffer/7810955 to your computer and use it in GitHub Desktop.
Plots the reverse dependences of a FreeBSD package, cleaned up to remove redundant edges
import subprocess
import networkx as nx
import matplotlib.pyplot as plt
from sys import argv
root = argv[1]
G = nx.DiGraph()
processed = []
def simplify(s):
return "-".join(s.split("-")[:-1]) + " "*8
def branches(depth, pkg):
if pkg not in processed:
processed.append(pkg)
print depth, pkg
for i in subprocess.check_output(
[ "pkg", "query", "%rn-%rv", pkg ]).splitlines():
G.add_edge(simplify(pkg), simplify(i))
branches(depth + 1, i)
branches(0, root)
# TODO check fetching two entries from the generator
def not_unique(gen):
return len(list(gen)) > 1
for (p,q) in G.edges():
if not_unique(nx.all_simple_paths(G, source=p, target=q)):
G.remove_edge(p,q)
pos=nx.graphviz_layout(G, prog="dot")
nx.draw(G, pos,
node_size=0, alpha=0.2, edge_color='r', font_size=9)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment