From 67bc4528320900f6cd45301ac86fa9cc8db58230 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 22 Mar 2011 15:12:55 +0100 Subject: [PATCH] Add repolist command. --- pakfire/__init__.py | 3 +++ pakfire/cli.py | 26 ++++++++++++++++++++++++++ pakfire/repository/__init__.py | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/pakfire/__init__.py b/pakfire/__init__.py index 901680ec4..a049c457f 100644 --- a/pakfire/__init__.py +++ b/pakfire/__init__.py @@ -275,3 +275,6 @@ class Pakfire(object): pkgs.unique() return [p.name for p in pkgs] + + def repolist(self): + return self.repos.all diff --git a/pakfire/cli.py b/pakfire/cli.py index 517b76c85..b7c6115e9 100644 --- a/pakfire/cli.py +++ b/pakfire/cli.py @@ -53,6 +53,7 @@ class Cli(object): self.parse_command_provides() self.parse_command_grouplist() self.parse_command_groupinstall() + self.parse_command_repolist() # Finally parse all arguments from the command line and save them. self.args = self.parser.parse_args() @@ -73,6 +74,7 @@ class Cli(object): "provides" : self.handle_provides, "grouplist" : self.handle_grouplist, "groupinstall" : self.handle_groupinstall, + "repolist" : self.handle_repolist, } def parse_common_arguments(self): @@ -149,6 +151,11 @@ class Cli(object): help=_("Group name.")) sub_groupinstall.add_argument("action", action="store_const", const="groupinstall") + def parse_command_repolist(self): + # Implement the "repolist" command + sub_repolist = self.sub_commands.add_parser("repolist", + help=_("List all currently enabled repositories.")) + sub_repolist.add_argument("action", action="store_const", const="repolist") def run(self): action = self.args.action @@ -214,6 +221,23 @@ class Cli(object): def handle_groupinstall(self): self.pakfire.groupinstall(self.args.group[0]) + def handle_repolist(self): + repos = self.pakfire.repolist() + repos.sort() + + FORMAT = " %-20s %8s %12s " + + title = FORMAT % (_("Repository"), _("Enabled"), _("Priority")) + print title + print "=" * len(title) # spacing line + + for repo in repos: + # Skip the installed repository. + if repo.name == "installed": + continue + + print FORMAT % (repo.name, repo.enabled, repo.priority) + class CliBuilder(Cli): def __init__(self): @@ -233,6 +257,7 @@ class CliBuilder(Cli): self.parse_command_shell() self.parse_command_update() self.parse_command_provides() + self.parse_command_repolist() # Finally parse all arguments from the command line and save them. self.args = self.parser.parse_args() @@ -251,6 +276,7 @@ class CliBuilder(Cli): "search" : self.handle_search, "shell" : self.handle_shell, "provides" : self.handle_provides, + "repolist" : self.handle_repolist, } def parse_command_update(self): diff --git a/pakfire/repository/__init__.py b/pakfire/repository/__init__.py index ef5050733..ce943e440 100644 --- a/pakfire/repository/__init__.py +++ b/pakfire/repository/__init__.py @@ -67,6 +67,10 @@ class Repositories(object): self._repos.append(repo) self._repos.sort() + @property + def all(self): + return self._repos[:] + @property def enabled(self): for repo in self._repos: -- 2.39.5