Merge pull request #1961 from skvidal/yum-mod

Yum mod
reviewable/pr18780/r1
Michael DeHaan 12 years ago
commit 6d6f4f0160

60
yum

@ -101,7 +101,7 @@ def yum_base(conf_file=None, cachedir=False):
cachedir = yum.misc.getCacheDir() cachedir = yum.misc.getCacheDir()
my.repos.setCacheDir(cachedir) my.repos.setCacheDir(cachedir)
my.conf.cache = 0 my.conf.cache = 0
return my return my
def po_to_nevra(po): def po_to_nevra(po):
@ -168,13 +168,22 @@ def is_available(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=[], dis_
return [ po_to_nevra(p) for p in pkgs ] return [ po_to_nevra(p) for p in pkgs ]
else: else:
myrepoq = list(repoq)
for repoid in en_repos:
r_cmd = ['--enablerepo', repoid]
myrepoq.extend(r_cmd)
for repoid in dis_repos:
r_cmd = ['--disablerepo', repoid]
myrepoq.extend(r_cmd)
cmd = repoq + ["--qf", qf, pkgspec] cmd = myrepoq + ["--qf", qf, pkgspec]
rc,out,err = module.run_command(cmd) rc,out,err = module.run_command(cmd)
if rc == 0: if rc == 0:
return [ p for p in out.split('\n') if p.strip() ] return [ p for p in out.split('\n') if p.strip() ]
else: else:
module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err + err2)) module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err))
return [] return []
@ -209,14 +218,23 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=[], dis_rep
return set([ po_to_nevra(p) for p in retpkgs ]) return set([ po_to_nevra(p) for p in retpkgs ])
else: else:
myrepoq = list(repoq)
for repoid in en_repos:
r_cmd = ['--enablerepo', repoid]
myrepoq.extend(r_cmd)
for repoid in dis_repos:
r_cmd = ['--disablerepo', repoid]
myrepoq.extend(r_cmd)
cmd = repoq + ["--pkgnarrow=updates", "--qf", qf, pkgspec] cmd = myrepoq + ["--pkgnarrow=updates", "--qf", qf, pkgspec]
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 + err2)) module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err))
return [] return []
@ -246,10 +264,18 @@ def what_provides(module, repoq, req_spec, conf_file, qf=def_qf, en_repos=[], d
return set([ po_to_nevra(p) for p in pkgs ]) return set([ po_to_nevra(p) for p in pkgs ])
else: else:
myrepoq = list(repoq)
for repoid in en_repos:
r_cmd = ['--enablerepo', repoid]
myrepoq.extend(r_cmd)
for repoid in dis_repos:
r_cmd = ['--disablerepo', repoid]
myrepoq.extend(r_cmd)
cmd = repoq + ["--qf", qf, "--whatprovides", req_spec] cmd = myrepoq + ["--qf", qf, "--whatprovides", req_spec]
rc,out,err = module.run_command(cmd) rc,out,err = module.run_command(cmd)
cmd = repoq + ["--qf", qf, req_spec] cmd = myrepoq + ["--qf", qf, req_spec]
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
@ -539,15 +565,25 @@ def ensure(module, state, pkgspec, conf_file, enablerepo, disablerepo):
r_cmd = ['--enablerepo', repoid] r_cmd = ['--enablerepo', repoid]
yum_basecmd.extend(r_cmd) yum_basecmd.extend(r_cmd)
if repoq:
repoq.extend(r_cmd)
for repoid in dis_repos: for repoid in dis_repos:
r_cmd = ['--disablerepo', repoid] r_cmd = ['--disablerepo', repoid]
yum_basecmd.extend(r_cmd) yum_basecmd.extend(r_cmd)
if repoq: if state in ['installed', 'present', 'latest']:
repoq.extend(r_cmd) my = yum_base(conf_file)
try:
for r in dis_repos:
my.repos.disableRepo(r)
for r in en_repos:
try:
my.repos.enableRepo(r)
rid = my.repos.getRepo(r)
a = rid.repoXML.repoid
except yum.Errors.YumBaseError, e:
module.fail_json(msg="Error setting/accessing repo %s: %s" % (r, e))
except yum.Errors.YumBaseError, e:
module.fail_json(msg="Error accessing repos: %s" % e)
if state in ['installed', 'present']: if state in ['installed', 'present']:
install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos) install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos)

Loading…
Cancel
Save