From 67d1ddbdec418c3a4a1f18c126023e3e8e67dba6 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 16 Oct 2011 18:47:29 +0000 Subject: [PATCH] Add downgrade command to downgrade packages more easy. --- po/pakfire.pot | 151 +++++++++++++++++--------------- python/pakfire/api.py | 6 ++ python/pakfire/base.py | 40 +++++++++ python/pakfire/cli.py | 22 +++++ python/pakfire/packages/base.py | 3 + 5 files changed, 153 insertions(+), 69 deletions(-) diff --git a/po/pakfire.pot b/po/pakfire.pot index 354034997..7be59cb81 100644 --- a/po/pakfire.pot +++ b/po/pakfire.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-10-16 12:51+0000\n" +"POT-Creation-Date: 2011-10-16 18:42+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -69,7 +69,7 @@ msgstr "" #: ../python/pakfire/base.py:203 ../python/pakfire/base.py:233 #: ../python/pakfire/base.py:279 ../python/pakfire/base.py:330 -#: ../python/pakfire/base.py:363 +#: ../python/pakfire/base.py:383 ../python/pakfire/base.py:403 msgid "Nothing to do" msgstr "" @@ -82,11 +82,16 @@ msgstr "" msgid "Excluding %s." msgstr "" -#: ../python/pakfire/base.py:475 +#: ../python/pakfire/base.py:371 +#, python-format +msgid "\"%s\" package does not seem to be installed." +msgstr "" + +#: ../python/pakfire/base.py:515 msgid "Build command has failed." msgstr "" -#: ../python/pakfire/base.py:555 +#: ../python/pakfire/base.py:595 msgid "Everything is fine." msgstr "" @@ -123,249 +128,257 @@ msgstr "" msgid "The path where pakfire should operate in." msgstr "" -#: ../python/pakfire/cli.py:113 +#: ../python/pakfire/cli.py:115 msgid "Enable verbose output." msgstr "" -#: ../python/pakfire/cli.py:116 +#: ../python/pakfire/cli.py:118 msgid "Path to a configuration file to load." msgstr "" -#: ../python/pakfire/cli.py:119 +#: ../python/pakfire/cli.py:121 msgid "Disable a repository temporarily." msgstr "" -#: ../python/pakfire/cli.py:122 +#: ../python/pakfire/cli.py:124 msgid "Enable a repository temporarily." msgstr "" -#: ../python/pakfire/cli.py:125 +#: ../python/pakfire/cli.py:127 msgid "Run pakfire in offline mode." msgstr "" -#: ../python/pakfire/cli.py:130 +#: ../python/pakfire/cli.py:132 msgid "Install one or more packages to the system." msgstr "" -#: ../python/pakfire/cli.py:132 +#: ../python/pakfire/cli.py:134 msgid "Give name of at least one package to install." msgstr "" -#: ../python/pakfire/cli.py:138 +#: ../python/pakfire/cli.py:140 msgid "Install one or more packages from the filesystem." msgstr "" -#: ../python/pakfire/cli.py:140 +#: ../python/pakfire/cli.py:142 msgid "Give filename of at least one package." msgstr "" -#: ../python/pakfire/cli.py:146 +#: ../python/pakfire/cli.py:148 msgid "Remove one or more packages from the system." msgstr "" -#: ../python/pakfire/cli.py:148 +#: ../python/pakfire/cli.py:150 msgid "Give name of at least one package to remove." msgstr "" -#: ../python/pakfire/cli.py:154 +#: ../python/pakfire/cli.py:156 msgid "Give a name of a package to update or leave emtpy for all." msgstr "" -#: ../python/pakfire/cli.py:156 +#: ../python/pakfire/cli.py:158 msgid "Exclude package from update." msgstr "" -#: ../python/pakfire/cli.py:158 +#: ../python/pakfire/cli.py:160 ../python/pakfire/cli.py:185 msgid "Allow changing the vendor of packages." msgstr "" -#: ../python/pakfire/cli.py:160 +#: ../python/pakfire/cli.py:162 ../python/pakfire/cli.py:187 msgid "Allow changing the architecture of packages." msgstr "" -#: ../python/pakfire/cli.py:165 +#: ../python/pakfire/cli.py:167 msgid "Update the whole system or one specific package." msgstr "" -#: ../python/pakfire/cli.py:172 +#: ../python/pakfire/cli.py:174 msgid "Check, if there are any updates available." msgstr "" -#: ../python/pakfire/cli.py:179 +#: ../python/pakfire/cli.py:181 +msgid "Downgrade one or more packages." +msgstr "" + +#: ../python/pakfire/cli.py:183 +msgid "Give a name of a package to downgrade." +msgstr "" + +#: ../python/pakfire/cli.py:193 msgid "Print some information about the given package(s)." msgstr "" -#: ../python/pakfire/cli.py:181 +#: ../python/pakfire/cli.py:195 msgid "Give at least the name of one package." msgstr "" -#: ../python/pakfire/cli.py:187 +#: ../python/pakfire/cli.py:201 msgid "Search for a given pattern." msgstr "" -#: ../python/pakfire/cli.py:189 +#: ../python/pakfire/cli.py:203 msgid "A pattern to search for." msgstr "" -#: ../python/pakfire/cli.py:195 +#: ../python/pakfire/cli.py:209 msgid "Get a list of packages that provide a given file or feature." msgstr "" -#: ../python/pakfire/cli.py:197 +#: ../python/pakfire/cli.py:211 msgid "File or feature to search for." msgstr "" -#: ../python/pakfire/cli.py:203 +#: ../python/pakfire/cli.py:217 msgid "Get list of packages that belong to the given group." msgstr "" -#: ../python/pakfire/cli.py:205 +#: ../python/pakfire/cli.py:219 msgid "Group name to search for." msgstr "" -#: ../python/pakfire/cli.py:211 +#: ../python/pakfire/cli.py:225 msgid "Install all packages that belong to the given group." msgstr "" -#: ../python/pakfire/cli.py:213 +#: ../python/pakfire/cli.py:227 msgid "Group name." msgstr "" -#: ../python/pakfire/cli.py:219 +#: ../python/pakfire/cli.py:233 msgid "List all currently enabled repositories." msgstr "" -#: ../python/pakfire/cli.py:223 +#: ../python/pakfire/cli.py:237 msgid "Cleanup commands." msgstr "" -#: ../python/pakfire/cli.py:231 +#: ../python/pakfire/cli.py:245 msgid "Cleanup all temporary files." msgstr "" -#: ../python/pakfire/cli.py:237 +#: ../python/pakfire/cli.py:251 msgid "Check the system for any errors." msgstr "" -#: ../python/pakfire/cli.py:243 +#: ../python/pakfire/cli.py:257 msgid "Check the dependencies for a particular package." msgstr "" -#: ../python/pakfire/cli.py:245 +#: ../python/pakfire/cli.py:259 msgid "Give name of at least one package to check." msgstr "" -#: ../python/pakfire/cli.py:313 ../python/pakfire/transaction.py:316 +#: ../python/pakfire/cli.py:335 ../python/pakfire/transaction.py:316 msgid "Repository" msgstr "" -#: ../python/pakfire/cli.py:313 +#: ../python/pakfire/cli.py:335 msgid "Enabled" msgstr "" -#: ../python/pakfire/cli.py:313 +#: ../python/pakfire/cli.py:335 msgid "Priority" msgstr "" -#: ../python/pakfire/cli.py:313 +#: ../python/pakfire/cli.py:335 msgid "Packages" msgstr "" -#: ../python/pakfire/cli.py:325 +#: ../python/pakfire/cli.py:347 msgid "Cleaning up everything..." msgstr "" -#: ../python/pakfire/cli.py:341 +#: ../python/pakfire/cli.py:363 msgid "You cannot run pakfire-builder in a pakfire chroot." msgstr "" -#: ../python/pakfire/cli.py:344 ../python/pakfire/cli.py:601 +#: ../python/pakfire/cli.py:366 ../python/pakfire/cli.py:623 msgid "Pakfire builder command line interface." msgstr "" -#: ../python/pakfire/cli.py:399 +#: ../python/pakfire/cli.py:421 msgid "Update the package indexes." msgstr "" -#: ../python/pakfire/cli.py:405 ../python/pakfire/cli.py:621 +#: ../python/pakfire/cli.py:427 ../python/pakfire/cli.py:643 msgid "Build one or more packages." msgstr "" -#: ../python/pakfire/cli.py:407 ../python/pakfire/cli.py:623 +#: ../python/pakfire/cli.py:429 ../python/pakfire/cli.py:645 msgid "Give name of at least one package to build." msgstr "" -#: ../python/pakfire/cli.py:411 ../python/pakfire/cli.py:627 +#: ../python/pakfire/cli.py:433 ../python/pakfire/cli.py:649 msgid "Build the package for the given architecture." msgstr "" -#: ../python/pakfire/cli.py:413 ../python/pakfire/cli.py:441 -#: ../python/pakfire/cli.py:629 +#: ../python/pakfire/cli.py:435 ../python/pakfire/cli.py:463 +#: ../python/pakfire/cli.py:651 msgid "Path were the output files should be copied to." msgstr "" -#: ../python/pakfire/cli.py:415 ../python/pakfire/cli.py:430 -#: ../python/pakfire/cli.py:631 +#: ../python/pakfire/cli.py:437 ../python/pakfire/cli.py:452 +#: ../python/pakfire/cli.py:653 msgid "Mode to run in. Is either 'release' or 'development' (default)." msgstr "" -#: ../python/pakfire/cli.py:417 +#: ../python/pakfire/cli.py:439 msgid "Run a shell after a successful build." msgstr "" -#: ../python/pakfire/cli.py:422 +#: ../python/pakfire/cli.py:444 msgid "Go into a shell." msgstr "" -#: ../python/pakfire/cli.py:424 +#: ../python/pakfire/cli.py:446 msgid "Give name of a package." msgstr "" -#: ../python/pakfire/cli.py:428 +#: ../python/pakfire/cli.py:450 msgid "Emulated architecture in the shell." msgstr "" -#: ../python/pakfire/cli.py:435 +#: ../python/pakfire/cli.py:457 msgid "Generate a source package." msgstr "" -#: ../python/pakfire/cli.py:437 +#: ../python/pakfire/cli.py:459 msgid "Give name(s) of a package(s)." msgstr "" -#: ../python/pakfire/cli.py:514 +#: ../python/pakfire/cli.py:536 msgid "Pakfire server command line interface." msgstr "" -#: ../python/pakfire/cli.py:551 +#: ../python/pakfire/cli.py:573 msgid "Request a build job from the server." msgstr "" -#: ../python/pakfire/cli.py:557 +#: ../python/pakfire/cli.py:579 msgid "Send a keepalive to the server." msgstr "" -#: ../python/pakfire/cli.py:564 +#: ../python/pakfire/cli.py:586 msgid "Update all repositories." msgstr "" -#: ../python/pakfire/cli.py:570 +#: ../python/pakfire/cli.py:592 msgid "Repository management commands." msgstr "" -#: ../python/pakfire/cli.py:578 +#: ../python/pakfire/cli.py:600 msgid "Create a new repository index." msgstr "" -#: ../python/pakfire/cli.py:579 +#: ../python/pakfire/cli.py:601 msgid "Path to the packages." msgstr "" -#: ../python/pakfire/cli.py:580 +#: ../python/pakfire/cli.py:602 msgid "Path to input packages." msgstr "" -#: ../python/pakfire/cli.py:633 +#: ../python/pakfire/cli.py:655 msgid "Do not verify build dependencies." msgstr "" @@ -499,11 +512,11 @@ msgstr "" msgid "File" msgstr "" -#: ../python/pakfire/packages/base.py:356 +#: ../python/pakfire/packages/base.py:359 msgid "Not set" msgstr "" -#: ../python/pakfire/packages/base.py:495 +#: ../python/pakfire/packages/base.py:498 #, python-format msgid "Config file saved as %s." msgstr "" diff --git a/python/pakfire/api.py b/python/pakfire/api.py index 42ebe1715..4092586a5 100644 --- a/python/pakfire/api.py +++ b/python/pakfire/api.py @@ -51,6 +51,12 @@ def update(pkgs, check=False, excludes=None, allow_vendorchange=False, allow_arc return pakfire.update(pkgs, check=check, excludes=excludes, allow_vendorchange=allow_vendorchange, allow_archchange=allow_archchange) +def downgrade(pkgs, allow_vendorchange=False, allow_archchange=False, **pakfire_args): + pakfire = Pakfire(**pakfire_args) + + return pakfire.downgrade(pkgs, + allow_vendorchange=allow_vendorchange, allow_archchange=allow_archchange) + def info(patterns, **pakfire_args): # Create pakfire instance. pakfire = Pakfire(**pakfire_args) diff --git a/python/pakfire/base.py b/python/pakfire/base.py index 4f537be32..1707e759f 100644 --- a/python/pakfire/base.py +++ b/python/pakfire/base.py @@ -348,6 +348,46 @@ class Pakfire(object): # Run the transaction. t.run() + def downgrade(self, pkgs, allow_vendorchange=False, allow_archchange=False): + assert pkgs + + # Create a new request. + request = self.create_request() + + # Fill request. + for pattern in pkgs: + best = None + for pkg in self.repos.whatprovides(pattern): + # Only consider installed packages. + if not pkg.is_installed(): + continue + + if best and pkg > best: + best = pkg + elif best is None: + best = pkg + + if best is None: + logging.warning(_("\"%s\" package does not seem to be installed.") % pattern) + else: + rel = self.create_relation("%s<%s" % (best.name, best.friendly_version)) + request.install(rel) + + # Solve the request. + solver = self.create_solver() + t = solver.solve(request, allow_downgrade=True, + allow_vendorchange=allow_vendorchange, + allow_archchange=allow_archchange) + + if not t: + logging.info(_("Nothing to do")) + return + + if not t.cli_yesno(): + return + + t.run() + def remove(self, pkgs): # Create a new request. request = self.create_request() diff --git a/python/pakfire/cli.py b/python/pakfire/cli.py index fb5d3c10f..a9baab3dc 100644 --- a/python/pakfire/cli.py +++ b/python/pakfire/cli.py @@ -59,6 +59,7 @@ class Cli(object): self.parse_command_search() self.parse_command_check_update() self.parse_command_update() + self.parse_command_downgrade() self.parse_command_provides() self.parse_command_grouplist() self.parse_command_groupinstall() @@ -76,6 +77,7 @@ class Cli(object): "remove" : self.handle_remove, "check_update" : self.handle_check_update, "update" : self.handle_update, + "downgrade" : self.handle_downgrade, "info" : self.handle_info, "search" : self.handle_search, "provides" : self.handle_provides, @@ -173,6 +175,18 @@ class Cli(object): sub_check_update.add_argument("action", action="store_const", const="check_update") self._parse_command_update(sub_check_update) + def parse_command_downgrade(self): + # Implement the "downgrade" command. + sub_downgrade = self.sub_commands.add_parser("downgrade", + help=_("Downgrade one or more packages.")) + sub_downgrade.add_argument("package", nargs="*", + help=_("Give a name of a package to downgrade.")) + sub_downgrade.add_argument("--allow-vendorchange", action="store_true", + help=_("Allow changing the vendor of packages.")) + sub_downgrade.add_argument("--allow-archchange", action="store_true", + help=_("Allow changing the architecture of packages.")) + sub_downgrade.add_argument("action", action="store_const", const="downgrade") + def parse_command_info(self): # Implement the "info" command. sub_info = self.sub_commands.add_parser("info", @@ -281,6 +295,14 @@ class Cli(object): def handle_check_update(self): self.handle_update(check=True) + def handle_downgrade(self, **args): + args.update(self.pakfire_args) + + pakfire.downgrade(self.args.package, + allow_vendorchange=self.args.allow_vendorchange, + allow_archchange=self.args.allow_archchange, + **args) + def handle_install(self): pakfire.install(self.args.package, **self.pakfire_args) diff --git a/python/pakfire/packages/base.py b/python/pakfire/packages/base.py index b2316e94b..7cbaacdf2 100644 --- a/python/pakfire/packages/base.py +++ b/python/pakfire/packages/base.py @@ -308,6 +308,9 @@ class Package(object): """ return "Critical" in self.groups + def is_installed(self): + return self.repo.name == "@system" + @property def type(self): return self.metadata.get("TYPE", "unknown") -- 2.39.5