From 629d04dc68889c45755b1d9a36aefc7d6fae2552 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 15 Jan 2018 08:38:43 -0800 Subject: [PATCH] Fix installpkg exclude operation Commit 8edaefd4d1726e added the ability to install specific NVR's of packages, but it did not adjust the exclude operation to account for this. This patch fixes that, applying the exclude only to the name part of the package NVR, and changes some variable names to pkgnvr/pkgnvrs to make it more clear that the content has changed to -- --- src/pylorax/ltmpl.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py index 854ff8a4..2a607b64 100644 --- a/src/pylorax/ltmpl.py +++ b/src/pylorax/ltmpl.py @@ -567,24 +567,25 @@ class LoraxTemplateRunner(object): if not pkgnames: raise dnf.exceptions.PackageNotFoundError("no package matched", p) - # Sort the results so that we have consistent results - pkgnames = sorted(["{}-{}-{}".format(pkg.name, pkg.version, pkg.release) for pkg in pkgnames]) - + # Apply excludes to the name only for exclude in excludes: - pkgnames = [pkg for pkg in pkgnames if not fnmatch.fnmatch(pkg, exclude)] + pkgnames = [pkg for pkg in pkgnames if not fnmatch.fnmatch(pkg.name, exclude)] + + # Convert to a sorted NVR list for installation + pkgnvrs = sorted(["{}-{}-{}".format(pkg.name, pkg.version, pkg.release) for pkg in pkgnames]) # If the request is a glob, expand it in the log if any(g for g in ['*','?','.'] if g in p): - logger.info("installpkg: %s expands to %s", p, ",".join(pkgnames)) + logger.info("installpkg: %s expands to %s", p, ",".join(pkgnvrs)) - for pkgname in pkgnames: + for pkgnvr in pkgnvrs: try: - self.dbo.install(pkgname) + self.dbo.install(pkgnvr) except Exception as e: # pylint: disable=broad-except if required: raise # Not required, log it and continue processing pkgs - logger.error("installpkg %s failed: %s", pkgname, str(e)) + logger.error("installpkg %s failed: %s", pkgnvr, str(e)) except Exception as e: # pylint: disable=broad-except logger.error("installpkg %s failed: %s", p, str(e)) errors = True