]> git.ipfire.org Git - pakfire.git/commitdiff
Add "check-update" command.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Aug 2011 18:20:47 +0000 (20:20 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 6 Aug 2011 18:20:47 +0000 (20:20 +0200)
Does the same as "update" does, but breaks after calculating the
transaction.

pakfire/api.py
pakfire/base.py
pakfire/cli.py

index 983c4506d2de4776755795b07e680d2fe37b3efa..f6b16568b3ddd70da140f13579d04269d01dcf98 100644 (file)
@@ -40,10 +40,10 @@ def remove(what, **pakfire_args):
 
        return pakfire.remove(what)
 
-def update(pkgs, **pakfire_args):
+def update(pkgs, check=False, **pakfire_args):
        pakfire = Pakfire(**pakfire_args)
 
-       return pakfire.update(pkgs)
+       return pakfire.update(pkgs, check=check)
 
 def info(patterns, **pakfire_args):
        # Create pakfire instance.
index 545a382ec8fd23711993390bebc24051e2cc879b..994cc2425605584d15864e195d3dd83dc909dc2e 100644 (file)
@@ -239,7 +239,11 @@ class Pakfire(object):
                        # Remove the temporary copy of the repository we have created earlier.
                        repo.remove()
 
-       def update(self, pkgs):
+       def update(self, pkgs, check=False):
+               """
+                       check indicates, if the method should return after calculation
+                       of the transaction.
+               """
                request = self.create_request()
 
                # If there are given any packets on the command line, we will
@@ -257,6 +261,17 @@ class Pakfire(object):
 
                if not t:
                        logging.info(_("Nothing to do"))
+
+                       # If we are running in check mode, we return a non-zero value to
+                       # indicate, that there are no updates.
+                       if check:
+                               return 1
+                       else:
+                               return
+
+               # Just exit here, because we won't do the transaction in this mode.
+               if check:
+                       t.dump()
                        return
 
                # Ask the user if the transaction is okay.
index 1d4de7ced32430bd85d41b8215247ea42d195b6b..35ddaea7d41cd6aaa14a9a9950aa79141ca6f376 100644 (file)
@@ -56,6 +56,7 @@ class Cli(object):
                self.parse_command_remove()
                self.parse_command_info()
                self.parse_command_search()
+               self.parse_command_check_update()
                self.parse_command_update()
                self.parse_command_provides()
                self.parse_command_grouplist()
@@ -71,6 +72,7 @@ class Cli(object):
                        "install"      : self.handle_install,
                        "localinstall" : self.handle_localinstall,
                        "remove"       : self.handle_remove,
+                       "check_update" : self.handle_check_update,
                        "update"       : self.handle_update,
                        "info"         : self.handle_info,
                        "search"       : self.handle_search,
@@ -148,6 +150,14 @@ class Cli(object):
                        help=_("Give a name of a package to update or leave emtpy for all."))
                sub_update.add_argument("action", action="store_const", const="update")
 
+       def parse_command_check_update(self):
+               # Implement the "check-update" command.
+               sub_check_update = self.sub_commands.add_parser("check-update",
+                       help=_("Check, if there are any updates available."))
+               sub_check_update.add_argument("package", nargs="*",
+                       help=_("Give a name of a package to update or leave emtpy for all."))
+               sub_check_update.add_argument("action", action="store_const", const="check_update")
+
        def parse_command_info(self):
                # Implement the "info" command.
                sub_info = self.sub_commands.add_parser("info",
@@ -240,6 +250,9 @@ class Cli(object):
        def handle_update(self):
                pakfire.update(self.args.package, **self.pakfire_args)
 
+       def handle_check_update(self):
+               pakfire.update(self.args.package, check=True, **self.pakfire_args)
+
        def handle_install(self):
                pakfire.install(self.args.package, **self.pakfire_args)