From 8f24c32cceb47071c8bea44de9a7265bf51e6f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Wed, 10 May 2006 09:22:55 +0000 Subject: [PATCH] * fix: make graph command work, and add some cool options to it :) --- pisi/api.py | 6 +++--- pisi/cli/commands.py | 39 +++++++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/pisi/api.py b/pisi/api.py index cab7e1e4..f230b8b8 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -156,7 +156,7 @@ def list_upgradable(): 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 all dependencies of packages A, if ignore_installed 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 # 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 # set A using packagedb @@ -178,7 +178,7 @@ def package_graph(A, ignore_installed = False): while len(B) > 0: Bp = set() for x in B: - pkg = ctx.packagedb.get_package(x) + pkg = ctx.packagedb.get_package(x, repo) #print pkg for dep in pkg.runtimeDependencies(): if ignore_installed: diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 389396c2..4a4c6b93 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -261,7 +261,9 @@ class Graph(Command): Usage: graph [ ...] 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 @@ -270,27 +272,34 @@ conflicts relations starting from given packages. super(Graph, self).__init__() 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, - 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", default='pgraph.dot', help=_("dot output file")) 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): self.init() - if ctx.get_option('all'): - ctx.ui.info(_('Plotting a graph of relations among all available packages')) - a = self.all_packages() + if not ctx.get_option('installed'): + if ctx.get_option('repository'): + 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: if self.args: a = self.args @@ -298,7 +307,9 @@ conflicts relations starting from given packages. # if A is empty, then graph all packages ctx.ui.info(_('Plotting a graph of relations among all installed packages')) 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')) self.finalize()