Skip to content

Instantly share code, notes, and snippets.

@omaraboumrad omaraboumrad/apt_graph.py Secret
Created Dec 28, 2016

Embed
What would you like to do?
Generates apt depedencies graph (old code)
import os
import pydot
MAX_PACKAGES = 10
def pkgs():
cmd = 'dpkg --get-selections'
result = [v.split()[0] for v in os.popen(cmd).readlines()]
return result[:MAX_PACKAGES - 1]
def depends(pkg):
cmd = 'apt-cache depends %s' % pkg
res = os.popen(cmd).readlines()
return [v.split()[-1] for v in res if 'Depends' in v]
def collect_dependencies():
return dict((pkg, depends(pkg)) for pkg in pkgs())
def build_graph():
packages = collect_dependencies()
graph = pydot.Dot(
graph_type='digraph',
simplify=True,
fontsize=8,
overlap=False)
for pkg, deps in packages.items():
for dep in deps:
edge = pydot.Edge(pkg, dep)
graph.add_edge(edge)
graph.write_png('graph.png', prog='neato')
if __name__ == '__main__':
build_graph()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.