]> git.ipfire.org Git - pakfire.git/commitdiff
Add repolist command.
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Mar 2011 14:12:55 +0000 (15:12 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Mar 2011 14:12:55 +0000 (15:12 +0100)
pakfire/__init__.py
pakfire/cli.py
pakfire/repository/__init__.py

index 901680ec41b9140a5230f7fd3fc759ded95c8b48..a049c457f529019cc73742f3f48b4ba64b88939a 100644 (file)
@@ -275,3 +275,6 @@ class Pakfire(object):
                pkgs.unique()
 
                return [p.name for p in pkgs]
+
+       def repolist(self):
+               return self.repos.all
index 517b76c8567d3a9ffeab31fcf7b42ba6d1953302..b7c6115e9fd6484853ce65ada88880a6ef24b80d 100644 (file)
@@ -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):
index ef50507333cf15732f75573bf6c258055a510b26..ce943e440f3791859610bcc03e2f8fc41827cd22 100644 (file)
@@ -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: