From e38914be0eb0da5a34ea45bbc2c630215f551c22 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 6 Aug 2011 20:20:47 +0200 Subject: [PATCH] Add "check-update" command. Does the same as "update" does, but breaks after calculating the transaction. --- pakfire/api.py | 4 ++-- pakfire/base.py | 17 ++++++++++++++++- pakfire/cli.py | 13 +++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/pakfire/api.py b/pakfire/api.py index 983c4506d..f6b16568b 100644 --- a/pakfire/api.py +++ b/pakfire/api.py @@ -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. diff --git a/pakfire/base.py b/pakfire/base.py index 545a382ec..994cc2425 100644 --- a/pakfire/base.py +++ b/pakfire/base.py @@ -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. diff --git a/pakfire/cli.py b/pakfire/cli.py index 1d4de7ced..35ddaea7d 100644 --- a/pakfire/cli.py +++ b/pakfire/cli.py @@ -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) -- 2.39.5