* fix: make graph command work, and add some cool options to it :)
This commit is contained in:
+3
-3
@@ -156,7 +156,7 @@ def list_upgradable():
|
|||||||
|
|
||||||
return filter(pisi.operations.is_upgradable, ctx.installdb.list_installed())
|
return filter(pisi.operations.is_upgradable, ctx.installdb.list_installed())
|
||||||
|
|
||||||
def package_graph(A, ignore_installed = False):
|
def package_graph(A, repo = pisi.itembyrepodb.installed, ignore_installed = False):
|
||||||
"""Construct a package relations graph, containing
|
"""Construct a package relations graph, containing
|
||||||
all dependencies of packages A, if ignore_installed
|
all dependencies of packages A, if ignore_installed
|
||||||
option is True, then only uninstalled deps will
|
option is True, then only uninstalled deps will
|
||||||
@@ -167,7 +167,7 @@ def package_graph(A, ignore_installed = False):
|
|||||||
# try to construct a pisi graph of packages to
|
# try to construct a pisi graph of packages to
|
||||||
# install / reinstall
|
# install / reinstall
|
||||||
|
|
||||||
G_f = pgraph.PGraph(ctx.packagedb) # construct G_f
|
G_f = pgraph.PGraph(ctx.packagedb, repo) # construct G_f
|
||||||
|
|
||||||
# find the "install closure" graph of G_f by package
|
# find the "install closure" graph of G_f by package
|
||||||
# set A using packagedb
|
# set A using packagedb
|
||||||
@@ -178,7 +178,7 @@ def package_graph(A, ignore_installed = False):
|
|||||||
while len(B) > 0:
|
while len(B) > 0:
|
||||||
Bp = set()
|
Bp = set()
|
||||||
for x in B:
|
for x in B:
|
||||||
pkg = ctx.packagedb.get_package(x)
|
pkg = ctx.packagedb.get_package(x, repo)
|
||||||
#print pkg
|
#print pkg
|
||||||
for dep in pkg.runtimeDependencies():
|
for dep in pkg.runtimeDependencies():
|
||||||
if ignore_installed:
|
if ignore_installed:
|
||||||
|
|||||||
+25
-14
@@ -261,7 +261,9 @@ class Graph(Command):
|
|||||||
Usage: graph [<package1> <package2> ...]
|
Usage: graph [<package1> <package2> ...]
|
||||||
|
|
||||||
Write a graph of package relations, tracking dependency and
|
Write a graph of package relations, tracking dependency and
|
||||||
conflicts relations starting from given packages.
|
conflicts relations starting from given packages. By default
|
||||||
|
shows the package relations among repository packages, and writes
|
||||||
|
the package in graphviz format to 'pgraph.dot'.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__metaclass__ = autocommand
|
__metaclass__ = autocommand
|
||||||
@@ -270,27 +272,34 @@ conflicts relations starting from given packages.
|
|||||||
super(Graph, self).__init__()
|
super(Graph, self).__init__()
|
||||||
|
|
||||||
def options(self):
|
def options(self):
|
||||||
self.parser.add_option("-a", "--all", action="store_true",
|
self.parser.add_option("-r", "--repository", action="store",
|
||||||
|
default=None,
|
||||||
|
help=_("specify a particular repository"))
|
||||||
|
self.parser.add_option("-i", "--installed", action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
help=_("graph all available packages"))
|
help=_("graph of installed packages"))
|
||||||
|
self.parser.add_option("", "--ignore-installed", action="store_true",
|
||||||
|
default=False,
|
||||||
|
help=_("do not show installed packages"))
|
||||||
self.parser.add_option("-o", "--output", action="store",
|
self.parser.add_option("-o", "--output", action="store",
|
||||||
default='pgraph.dot',
|
default='pgraph.dot',
|
||||||
help=_("dot output file"))
|
help=_("dot output file"))
|
||||||
|
|
||||||
name = ("graph", None)
|
name = ("graph", None)
|
||||||
|
|
||||||
def all_packages(self):
|
|
||||||
a = set()
|
|
||||||
from pisi import packagedb
|
|
||||||
for repo in ctx.repodb.list():
|
|
||||||
a = a.union(ctx.packagedb.list_packages(repo))
|
|
||||||
return a
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.init()
|
self.init()
|
||||||
if ctx.get_option('all'):
|
if not ctx.get_option('installed'):
|
||||||
ctx.ui.info(_('Plotting a graph of relations among all available packages'))
|
if ctx.get_option('repository'):
|
||||||
a = self.all_packages()
|
repo = ctx.get_option('repository')
|
||||||
|
ctx.ui.info(_('Plotting packages in repository %s') % repo)
|
||||||
|
else:
|
||||||
|
repo = pisi.itembyrepodb.repos
|
||||||
|
if self.args:
|
||||||
|
a = self.args
|
||||||
|
else:
|
||||||
|
ctx.ui.info(_('Plotting a graph of relations among all repository packages'))
|
||||||
|
a = ctx.packagedb.list_packages(repo)
|
||||||
else:
|
else:
|
||||||
if self.args:
|
if self.args:
|
||||||
a = self.args
|
a = self.args
|
||||||
@@ -298,7 +307,9 @@ conflicts relations starting from given packages.
|
|||||||
# if A is empty, then graph all packages
|
# if A is empty, then graph all packages
|
||||||
ctx.ui.info(_('Plotting a graph of relations among all installed packages'))
|
ctx.ui.info(_('Plotting a graph of relations among all installed packages'))
|
||||||
a = ctx.installdb.list_installed()
|
a = ctx.installdb.list_installed()
|
||||||
g = pisi.api.package_graph(a)
|
repo = pisi.itembyrepodb.installed
|
||||||
|
g = pisi.api.package_graph(a, repo = repo,
|
||||||
|
ignore_installed = ctx.get_option('ignore_installed'))
|
||||||
g.write_graphviz(file(ctx.get_option('output'), 'w'))
|
g.write_graphviz(file(ctx.get_option('output'), 'w'))
|
||||||
self.finalize()
|
self.finalize()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user