From: Michael Tremer Date: Tue, 22 Mar 2011 11:34:10 +0000 (+0100) Subject: Add grouplist command. X-Git-Tag: 0.9.3~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c1962d4008adbebe68d55f45ce1d940ee1d0e47a;p=pakfire.git Add grouplist command. --- diff --git a/pakfire/__init__.py b/pakfire/__init__.py index ccca46159..267e13f9a 100644 --- a/pakfire/__init__.py +++ b/pakfire/__init__.py @@ -262,3 +262,11 @@ class Pakfire(object): repo._collect_packages(input_path) repo.save() + + def grouplist(self, group): + pkgs = self.repos.get_by_group(group) + + pkgs = packages.PackageListing(pkgs) + pkgs.unique() + + return [p.name for p in pkgs] diff --git a/pakfire/cli.py b/pakfire/cli.py index 4f1693c3b..c30363102 100644 --- a/pakfire/cli.py +++ b/pakfire/cli.py @@ -51,6 +51,7 @@ class Cli(object): self.parse_command_search() self.parse_command_update() self.parse_command_provides() + self.parse_command_grouplist() # Finally parse all arguments from the command line and save them. self.args = self.parser.parse_args() @@ -69,6 +70,7 @@ class Cli(object): "info" : self.handle_info, "search" : self.handle_search, "provides" : self.handle_provides, + "grouplist" : self.handle_grouplist, } def parse_common_arguments(self): @@ -129,6 +131,14 @@ class Cli(object): help=_("File or feature to search for.")) sub_provides.add_argument("action", action="store_const", const="provides") + def parse_command_grouplist(self): + # Implement the "grouplist" command + sub_grouplist = self.sub_commands.add_parser("grouplist", + help=_("Get list of packages that belong to the given group.")) + sub_grouplist.add_argument("group", nargs=1, + help=_("Group name to search for.")) + sub_grouplist.add_argument("action", action="store_const", const="grouplist") + def run(self): action = self.args.action @@ -184,6 +194,12 @@ class Cli(object): for pkg in pkgs: print pkg.dump() + def handle_grouplist(self): + pkgs = self.pakfire.grouplist(self.args.group[0]) + + for pkg in pkgs: + print " * %s" % pkg + class CliBuilder(Cli): def __init__(self): diff --git a/pakfire/repository/__init__.py b/pakfire/repository/__init__.py index a3d689948..ef5050733 100644 --- a/pakfire/repository/__init__.py +++ b/pakfire/repository/__init__.py @@ -119,6 +119,11 @@ class Repositories(object): for pkg in repo.get_by_file(filename): yield pkg + def get_by_group(self, group): + for repo in self.enabled: + for pkg in repo.get_by_group(group): + yield pkg + def search(self, pattern): pkg_names = [] diff --git a/pakfire/repository/base.py b/pakfire/repository/base.py index 1cd57e604..e6d4e9afe 100644 --- a/pakfire/repository/base.py +++ b/pakfire/repository/base.py @@ -88,6 +88,14 @@ class RepositoryFactory(object): if match: yield pkg + def get_by_group(self, group): + """ + Get all packages that belong to a specific group. + """ + for pkg in self.packages: + if group in pkg.groups: + yield pkg + def search(self, pattern): """ Returns a list of packages, that match the given pattern, diff --git a/pakfire/repository/local.py b/pakfire/repository/local.py index 588e65b52..dcee556c9 100644 --- a/pakfire/repository/local.py +++ b/pakfire/repository/local.py @@ -56,6 +56,10 @@ class LocalRepository(RepositoryFactory): if not isinstance(pkg, packages.BinaryPackage): raise Exception + # Skip everything but binary packages. + if pkg.type == "source": + return + repo_filename = os.path.join(self.path, os.path.basename(pkg.filename)) # Do we need to copy the package files?