Fix installpkg exclude operation

Commit 8edaefd4d1 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 <name>-<version>-<release>
This commit is contained in:
Brian C. Lane 2018-01-15 08:38:43 -08:00
parent c611bbee73
commit 629d04dc68

View File

@ -567,24 +567,25 @@ class LoraxTemplateRunner(object):
if not pkgnames: if not pkgnames:
raise dnf.exceptions.PackageNotFoundError("no package matched", p) raise dnf.exceptions.PackageNotFoundError("no package matched", p)
# Sort the results so that we have consistent results # Apply excludes to the name only
pkgnames = sorted(["{}-{}-{}".format(pkg.name, pkg.version, pkg.release) for pkg in pkgnames])
for exclude in excludes: 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 the request is a glob, expand it in the log
if any(g for g in ['*','?','.'] if g in p): 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: try:
self.dbo.install(pkgname) self.dbo.install(pkgnvr)
except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
if required: if required:
raise raise
# Not required, log it and continue processing pkgs # 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 except Exception as e: # pylint: disable=broad-except
logger.error("installpkg %s failed: %s", p, str(e)) logger.error("installpkg %s failed: %s", p, str(e))
errors = True errors = True