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

meaningless whitespace changes

This commit is contained in:
Michael DeHaan 2012-08-14 19:33:11 -04:00
parent de4b8dc53a
commit ded0c61750

View file

@ -25,15 +25,16 @@ import traceback
import os
import yum
def_qf = "%{name}-%{version}-%{release}.%{arch}"
repoquery='/usr/bin/repoquery'
if not os.path.exists(repoquery):
repoquery = None
yumbin='/usr/bin/yum'
def yum_base(conf_file=None, cachedir=False):
my = yum.YumBase()
my.preconf.debuglevel=0
my.preconf.errorlevel=0
@ -50,15 +51,16 @@ def yum_base(conf_file=None, cachedir=False):
return my
def po_to_nevra(po):
if hasattr(po, 'ui_nevra'):
return po.ui_nevra
else:
return '%s-%s-%s.%s' % (po.name, po.version, po.release, po.arch)
def is_installed(module, repoq, pkgspec, conf_file, qf=def_qf):
if not repoq:
pkgs = []
try:
my = yum_base(conf_file)
@ -70,7 +72,9 @@ def is_installed(module, repoq, pkgspec, conf_file, qf=def_qf):
module.fail_json(msg="Failure talking to yum: %s" % e)
return [ po_to_nevra(p) for p in pkgs ]
else:
cmd = repoq + ["--disablerepo=*", "--pkgnarrow=installed", "--qf", qf, pkgspec]
rc,out,err = run(cmd)
cmd = repoq + ["--disablerepo=*", "--pkgnarrow=installed", "--qf", qf, "--whatprovides", pkgspec]
@ -84,7 +88,9 @@ def is_installed(module, repoq, pkgspec, conf_file, qf=def_qf):
return []
def is_available(module, repoq, pkgspec, conf_file, qf=def_qf):
if not repoq:
pkgs = []
try:
my = yum_base(conf_file)
@ -96,7 +102,9 @@ def is_available(module, repoq, pkgspec, conf_file, qf=def_qf):
module.fail_json(msg="Failure talking to yum: %s" % e)
return [ po_to_nevra(p) for p in pkgs ]
else:
cmd = repoq + ["--qf", qf, pkgspec]
rc,out,err = run(cmd)
if rc == 0:
@ -107,10 +115,13 @@ def is_available(module, repoq, pkgspec, conf_file, qf=def_qf):
return []
def is_update(module, repoq, pkgspec, conf_file, qf=def_qf):
if not repoq:
retpkgs = []
pkgs = []
updates = []
try:
my = yum_base(conf_file)
pkgs = my.returnPackagesByDep(pkgspec) + my.returnInstalledPackagesByDep(pkgspec)
@ -128,6 +139,7 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf):
return set([ po_to_nevra(p) for p in retpkgs ])
else:
cmd = repoq + ["--pkgnarrow=updates", "--qf", qf, pkgspec]
rc,out,err = run(cmd)
@ -139,7 +151,9 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf):
return []
def what_provides(module, repoq, req_spec, conf_file, qf=def_qf):
if not repoq:
pkgs = []
try:
my = yum_base(conf_file)
@ -155,7 +169,9 @@ def what_provides(module, repoq, req_spec, conf_file, qf=def_qf):
module.fail_json(msg="Failure talking to yum: %s" % e)
return set([ po_to_nevra(p) for p in pkgs ])
else:
cmd = repoq + ["--qf", qf, "--whatprovides", req_spec]
rc,out,err = run(cmd)
cmd = repoq + ["--qf", qf, req_spec]
@ -180,6 +196,7 @@ def local_nvra(path):
return nvra
def pkg_to_dict(pkgstr):
if pkgstr.strip():
n,e,v,r,a,repo = pkgstr.split('|')
else:
@ -203,6 +220,7 @@ def pkg_to_dict(pkgstr):
return d
def repolist(repoq, qf="%{repoid}"):
cmd = repoq + ["--qf", qf, "-a"]
rc,out,err = run(cmd)
ret = []
@ -211,6 +229,7 @@ def repolist(repoq, qf="%{repoid}"):
return ret
def list_stuff(module, conf_file, stuff):
qf = "%{name}|%{epoch}|%{version}|%{release}|%{arch}|%{repoid}"
repoq = [repoquery, '--show-duplicates', '--plugins', '--quiet', '-q']
if conf_file and os.path.exists(conf_file):
@ -228,6 +247,7 @@ def list_stuff(module, conf_file, stuff):
return [ pkg_to_dict(p) for p in is_installed(module, repoq, stuff, conf_file, qf=qf) + is_available(module, repoq, stuff, conf_file, qf=qf) if p.strip() ]
def run(command):
try:
cmd = subprocess.Popen(command,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@ -251,6 +271,7 @@ def run(command):
def install(module, items, repoq, yum_basecmd, conf_file):
res = {}
res['results'] = []
res['msg'] = ''
@ -369,6 +390,7 @@ def remove(module, items, repoq, yum_basecmd, conf_file):
module.exit_json(**res)
def latest(module, items, repoq, yum_basecmd, conf_file):
res = {}
res['results'] = []
res['msg'] = ''
@ -376,6 +398,7 @@ def latest(module, items, repoq, yum_basecmd, conf_file):
res['rc'] = 0
for spec in items:
pkg = None
basecmd = 'update'
# groups, again
@ -408,7 +431,6 @@ def latest(module, items, repoq, yum_basecmd, conf_file):
res['results'].append("All packages providing %s are up to date" % spec)
continue
pkg = spec
cmd = yum_basecmd + [basecmd, pkg]
@ -423,7 +445,6 @@ def latest(module, items, repoq, yum_basecmd, conf_file):
changed = True
failed = False
if rc:
res['changed'] = False
res['failed'] = True
@ -439,20 +460,22 @@ def latest(module, items, repoq, yum_basecmd, conf_file):
module.exit_json(**res)
def ensure(module, state, pkgspec, conf_file):
# take multiple args comma separated
items = pkgspec.split(',')
yum_basecmd = [yumbin, '-d', '1', '-y']
if not repoquery:
repoq = None
else:
repoq = [repoquery, '--show-duplicates', '--plugins', '--quiet', '-q']
if conf_file and os.path.exists(conf_file):
yum_basecmd += ['-c', conf_file]
if repoq:
repoq += ['-c', conf_file]
if state in ['installed', 'present']:
install(module, items, repoq, yum_basecmd, conf_file)
elif state in ['removed', 'absent']:
@ -460,11 +483,11 @@ def ensure(module, state, pkgspec, conf_file):
elif state == 'latest':
latest(module, items, repoq, yum_basecmd, conf_file)
# should be caught by AnsibleModule argument_spec
return dict(changed=False, failed=True, results='', errors='unexpected state')
def main():
# state=installed name=pkgspec
# state=removed name=pkgspec
# state=latest name=pkgspec
@ -504,6 +527,5 @@ def main():
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main()