removing duplicate operations from the use of list comprehensions. None of the logic within the code has been changed, just more refined. (#41098)

This commit is contained in:
Bryce Verdier 2018-07-18 13:48:12 -06:00 committed by ansibot
parent 66adabfd42
commit b16fef9aad

View file

@ -522,7 +522,6 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, dis_r
if not repoq: if not repoq:
retpkgs = []
pkgs = [] pkgs = []
updates = [] updates = []
@ -541,11 +540,9 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, dis_r
except Exception as e: except Exception as e:
module.fail_json(msg="Failure talking to yum: %s" % to_native(e)) module.fail_json(msg="Failure talking to yum: %s" % to_native(e))
for pkg in pkgs: retpkgs = (pkg for pkg in pkgs if pkg in updates)
if pkg in updates:
retpkgs.append(pkg)
return set([po_to_envra(p) for p in retpkgs]) return set(po_to_envra(p) for p in retpkgs)
else: else:
myrepoq = list(repoq) myrepoq = list(repoq)
@ -559,7 +556,7 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, dis_r
rc, out, err = module.run_command(cmd) rc, out, err = module.run_command(cmd)
if rc == 0: if rc == 0:
return set([p for p in out.split('\n') if p.strip()]) return set(p for p in out.split('\n') if p.strip())
else: else:
module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err)) module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err))
@ -607,7 +604,7 @@ def what_provides(module, repoq, yum_basecmd, req_spec, conf_file, qf=def_qf,
except Exception as e: except Exception as e:
module.fail_json(msg="Failure talking to yum: %s" % to_native(e)) module.fail_json(msg="Failure talking to yum: %s" % to_native(e))
return set([po_to_envra(p) for p in pkgs]) return set(po_to_envra(p) for p in pkgs)
else: else:
myrepoq = list(repoq) myrepoq = list(repoq)
@ -623,7 +620,7 @@ def what_provides(module, repoq, yum_basecmd, req_spec, conf_file, qf=def_qf,
rc2, out2, err2 = module.run_command(cmd) rc2, out2, err2 = module.run_command(cmd)
if rc == 0 and rc2 == 0: if rc == 0 and rc2 == 0:
out += out2 out += out2
pkgs = set([p for p in out.split('\n') if p.strip()]) pkgs = set(p for p in out.split('\n') if p.strip())
if not pkgs: if not pkgs:
pkgs = is_installed(module, repoq, req_spec, conf_file, qf=qf, installroot=installroot, disable_excludes=disable_excludes) pkgs = is_installed(module, repoq, req_spec, conf_file, qf=qf, installroot=installroot, disable_excludes=disable_excludes)
return pkgs return pkgs
@ -645,9 +642,7 @@ def transaction_exists(pkglist):
# first, we create a list of the package 'nvreas' # first, we create a list of the package 'nvreas'
# so we can compare the pieces later more easily # so we can compare the pieces later more easily
pkglist_nvreas = [] pkglist_nvreas = (splitFilename(pkg) for pkg in pkglist)
for pkg in pkglist:
pkglist_nvreas.append(splitFilename(pkg))
# next, we build the list of packages that are # next, we build the list of packages that are
# contained within an unfinished transaction # contained within an unfinished transaction
@ -751,10 +746,10 @@ def pkg_to_dict(pkgstr):
def repolist(module, repoq, qf="%{repoid}"): def repolist(module, repoq, qf="%{repoid}"):
cmd = repoq + ["--qf", qf, "-a"] cmd = repoq + ["--qf", qf, "-a"]
rc, out, _ = module.run_command(cmd) rc, out, _ = module.run_command(cmd)
ret = []
if rc == 0: if rc == 0:
ret = set([p for p in out.split('\n') if p.strip()]) return set(p for p in out.split('\n') if p.strip())
return ret else:
return []
def list_stuff(module, repoquerybin, conf_file, stuff, installroot='/', disablerepo='', enablerepo='', disable_excludes=None): def list_stuff(module, repoquerybin, conf_file, stuff, installroot='/', disablerepo='', enablerepo='', disable_excludes=None):
@ -1364,7 +1359,7 @@ def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo,
e_cmd = ['--installroot=%s' % installroot] e_cmd = ['--installroot=%s' % installroot]
yum_basecmd.extend(e_cmd) yum_basecmd.extend(e_cmd)
if state in ['installed', 'present', 'latest']: if state in ('installed', 'present', 'latest'):
""" The need of this entire if conditional has to be chalanged """ The need of this entire if conditional has to be chalanged
this function is the ensure function that is called this function is the ensure function that is called
in the main section. in the main section.