1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

pkgng: refactor upgraded pattern matching

Implement russoz's suggestion to put all
variants in the pattern.
This commit is contained in:
Ross Williams 2021-10-09 12:50:30 +00:00
parent 752817cf5a
commit d54f84f227

View file

@ -191,10 +191,9 @@ def upgrade_packages(module, pkgng_path, dir_arg):
cmd += " -n" cmd += " -n"
rc, out, err = module.run_command(cmd) rc, out, err = module.run_command(cmd)
for action in ('upgraded', 'reinstalled',): matches = re.findall('^Number of packages to be (?:upgraded|reinstalled): ([0-9]+)', out, re.MULTILINE)
match = re.search('^Number of packages to be %s: ([0-9]+)' % (action,), out, re.MULTILINE) for match in matches:
if match: upgraded_c += int(match)
upgraded_c += int(match.group(1))
if upgraded_c > 0: if upgraded_c > 0:
return (True, "updated %s package(s)" % upgraded_c, out, err) return (True, "updated %s package(s)" % upgraded_c, out, err)