cli/graph: Add option to generate reverse dependency graph

This commit is contained in:
Erdem Bayer
2010-10-24 15:17:00 +00:00
parent 1c47052538
commit 65ca49778e
2 changed files with 21 additions and 9 deletions
+17 -8
View File
@@ -612,7 +612,7 @@ def get_package_requirements(packages):
# ****** Danger Zone Below! Tressspassers' eyes will explode! ********** #
def package_graph(A, packagedb, ignore_installed = False):
def package_graph(A, packagedb, ignore_installed = False, reverse=False):
"""Construct a package relations graph.
Graph will contain all dependencies of packages A, if ignore_installed
@@ -638,13 +638,22 @@ def package_graph(A, packagedb, ignore_installed = False):
for x in B:
pkg = packagedb.get_package(x)
#print pkg
for dep in pkg.runtimeDependencies():
if ignore_installed:
if dep.satisfied_by_installed():
continue
if not dep.package in G_f.vertices():
Bp.add(str(dep.package))
G_f.add_dep(x, dep)
if reverse:
for name,dep in packagedb.get_rev_deps(x):
if ignore_installed:
if dep.satisfied_by_installed():
continue
if not name in G_f.vertices():
Bp.add(name)
G_f.add_dep(name, dep)
else:
for dep in pkg.runtimeDependencies():
if ignore_installed:
if dep.satisfied_by_installed():
continue
if not dep.package in G_f.vertices():
Bp.add(str(dep.package))
G_f.add_dep(x, dep)
B = Bp
return G_f
+4 -1
View File
@@ -51,6 +51,9 @@ the package in graphviz format to 'pgraph.dot'.
group.add_option("--ignore-installed", action="store_true",
default=False,
help=_("Do not show installed packages"))
group.add_option("-R", "--reverse", action="store_true",
default=False,
help=_("Draw reverse dependency graph"))
group.add_option("-o", "--output", action="store",
default='pgraph.dot',
help=_("Dot output file"))
@@ -88,5 +91,5 @@ the package in graphviz format to 'pgraph.dot'.
a = pisi.api.list_installed()
g = pisi.api.package_graph(a, packagedb,
ignore_installed = ctx.get_option('ignore_installed'))
ignore_installed = ctx.get_option('ignore_installed'), reverse = ctx.get_option('reverse'))
g.write_graphviz(file(ctx.get_option('output'), 'w'))