mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Convert packaging/* to py3/py2.4 syntax (#3702)
This commit is contained in:
parent
cd09aab9b4
commit
b8175f70ce
5 changed files with 37 additions and 20 deletions
|
@ -492,7 +492,7 @@ def install_deb(m, debs, cache, force, install_recommends, allow_unauthenticated
|
||||||
if package_version_compare(pkg_version, installed_version) == 0:
|
if package_version_compare(pkg_version, installed_version) == 0:
|
||||||
# Does not need to down-/upgrade, move on to next package
|
# Does not need to down-/upgrade, move on to next package
|
||||||
continue
|
continue
|
||||||
except Exception, e:
|
except Exception:
|
||||||
# Must not be installed, continue with installation
|
# Must not be installed, continue with installation
|
||||||
pass
|
pass
|
||||||
# Check if package is installable
|
# Check if package is installable
|
||||||
|
|
|
@ -273,7 +273,8 @@ class SourcesList(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f.write(line)
|
f.write(line)
|
||||||
except IOError, err:
|
except IOError:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, unicode(err)))
|
self.module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, unicode(err)))
|
||||||
self.module.atomic_move(tmp_path, filename)
|
self.module.atomic_move(tmp_path, filename)
|
||||||
|
|
||||||
|
@ -451,7 +452,7 @@ def main():
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
repo=dict(required=True),
|
repo=dict(required=True),
|
||||||
state=dict(choices=['present', 'absent'], default='present'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
mode=dict(required=False, default=0644),
|
mode=dict(required=False, default=int('0644',8)),
|
||||||
update_cache = dict(aliases=['update-cache'], type='bool', default='yes'),
|
update_cache = dict(aliases=['update-cache'], type='bool', default='yes'),
|
||||||
filename=dict(required=False, default=None),
|
filename=dict(required=False, default=None),
|
||||||
# this should not be needed, but exists as a failsafe
|
# this should not be needed, but exists as a failsafe
|
||||||
|
@ -488,7 +489,8 @@ def main():
|
||||||
sourceslist.add_source(repo)
|
sourceslist.add_source(repo)
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
sourceslist.remove_source(repo)
|
sourceslist.remove_source(repo)
|
||||||
except InvalidSource, err:
|
except InvalidSource:
|
||||||
|
err = get_exception()
|
||||||
module.fail_json(msg='Invalid repository string: %s' % unicode(err))
|
module.fail_json(msg='Invalid repository string: %s' % unicode(err))
|
||||||
|
|
||||||
sources_after = sourceslist.dump()
|
sources_after = sourceslist.dump()
|
||||||
|
@ -510,7 +512,8 @@ def main():
|
||||||
if update_cache:
|
if update_cache:
|
||||||
cache = apt.Cache()
|
cache = apt.Cache()
|
||||||
cache.update()
|
cache.update()
|
||||||
except OSError, err:
|
except OSError:
|
||||||
|
err = get_exception()
|
||||||
module.fail_json(msg=unicode(err))
|
module.fail_json(msg=unicode(err))
|
||||||
|
|
||||||
module.exit_json(changed=changed, repo=repo, state=state, diff=diff)
|
module.exit_json(changed=changed, repo=repo, state=state, diff=diff)
|
||||||
|
|
|
@ -475,7 +475,8 @@ def main():
|
||||||
if pool != '^$':
|
if pool != '^$':
|
||||||
try:
|
try:
|
||||||
result = rhn.update_subscriptions(pool)
|
result = rhn.update_subscriptions(pool)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failed to update subscriptions for '%s': %s" % (server_hostname, e))
|
module.fail_json(msg="Failed to update subscriptions for '%s': %s" % (server_hostname, e))
|
||||||
else:
|
else:
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
@ -488,7 +489,8 @@ def main():
|
||||||
rhn.register(username, password, autosubscribe, activationkey, org_id,
|
rhn.register(username, password, autosubscribe, activationkey, org_id,
|
||||||
consumer_type, consumer_name, consumer_id)
|
consumer_type, consumer_name, consumer_id)
|
||||||
subscribed_pool_ids = rhn.subscribe(pool)
|
subscribed_pool_ids = rhn.subscribe(pool)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failed to register with '%s': %s" % (server_hostname, e))
|
module.fail_json(msg="Failed to register with '%s': %s" % (server_hostname, e))
|
||||||
else:
|
else:
|
||||||
module.exit_json(changed=True,
|
module.exit_json(changed=True,
|
||||||
|
@ -502,7 +504,8 @@ def main():
|
||||||
try:
|
try:
|
||||||
rhn.unsubscribe()
|
rhn.unsubscribe()
|
||||||
rhn.unregister()
|
rhn.unregister()
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failed to unregister: %s" % e)
|
module.fail_json(msg="Failed to unregister: %s" % e)
|
||||||
else:
|
else:
|
||||||
module.exit_json(changed=True, msg="System successfully unregistered from %s." % server_hostname)
|
module.exit_json(changed=True, msg="System successfully unregistered from %s." % server_hostname)
|
||||||
|
|
|
@ -120,7 +120,7 @@ try:
|
||||||
import up2date_client
|
import up2date_client
|
||||||
import up2date_client.config
|
import up2date_client.config
|
||||||
HAS_UP2DATE_CLIENT = True
|
HAS_UP2DATE_CLIENT = True
|
||||||
except ImportError, e:
|
except ImportError:
|
||||||
HAS_UP2DATE_CLIENT = False
|
HAS_UP2DATE_CLIENT = False
|
||||||
|
|
||||||
# INSERT REDHAT SNIPPETS
|
# INSERT REDHAT SNIPPETS
|
||||||
|
@ -387,7 +387,8 @@ def main():
|
||||||
rhn.enable()
|
rhn.enable()
|
||||||
rhn.register(module.params['enable_eus'] == True, activationkey, profilename, sslcacert, systemorgid)
|
rhn.register(module.params['enable_eus'] == True, activationkey, profilename, sslcacert, systemorgid)
|
||||||
rhn.subscribe(channels)
|
rhn.subscribe(channels)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failed to register with '%s': %s" % (rhn.hostname, e))
|
module.fail_json(msg="Failed to register with '%s': %s" % (rhn.hostname, e))
|
||||||
|
|
||||||
module.exit_json(changed=True, msg="System successfully registered to '%s'." % rhn.hostname)
|
module.exit_json(changed=True, msg="System successfully registered to '%s'." % rhn.hostname)
|
||||||
|
@ -399,7 +400,8 @@ def main():
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
rhn.unregister()
|
rhn.unregister()
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failed to unregister: %s" % e)
|
module.fail_json(msg="Failed to unregister: %s" % e)
|
||||||
|
|
||||||
module.exit_json(changed=True, msg="System successfully unregistered from %s." % rhn.hostname)
|
module.exit_json(changed=True, msg="System successfully unregistered from %s." % rhn.hostname)
|
||||||
|
|
|
@ -245,7 +245,8 @@ def is_installed(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, di
|
||||||
pkgs = e + m
|
pkgs = e + m
|
||||||
if not pkgs and not is_pkg:
|
if not pkgs and not is_pkg:
|
||||||
pkgs.extend(my.returnInstalledPackagesByDep(pkgspec))
|
pkgs.extend(my.returnInstalledPackagesByDep(pkgspec))
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failure talking to yum: %s" % e)
|
module.fail_json(msg="Failure talking to yum: %s" % e)
|
||||||
|
|
||||||
return [ po_to_nevra(p) for p in pkgs ]
|
return [ po_to_nevra(p) for p in pkgs ]
|
||||||
|
@ -301,7 +302,8 @@ def is_available(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, di
|
||||||
pkgs = e + m
|
pkgs = e + m
|
||||||
if not pkgs:
|
if not pkgs:
|
||||||
pkgs.extend(my.returnPackagesByDep(pkgspec))
|
pkgs.extend(my.returnPackagesByDep(pkgspec))
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failure talking to yum: %s" % e)
|
module.fail_json(msg="Failure talking to yum: %s" % e)
|
||||||
|
|
||||||
return [ po_to_nevra(p) for p in pkgs ]
|
return [ po_to_nevra(p) for p in pkgs ]
|
||||||
|
@ -348,7 +350,8 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, dis_r
|
||||||
e,m,u = my.pkgSack.matchPackageNames([pkgspec])
|
e,m,u = my.pkgSack.matchPackageNames([pkgspec])
|
||||||
pkgs = e + m
|
pkgs = e + m
|
||||||
updates = my.doPackageLists(pkgnarrow='updates').updates
|
updates = my.doPackageLists(pkgnarrow='updates').updates
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failure talking to yum: %s" % e)
|
module.fail_json(msg="Failure talking to yum: %s" % e)
|
||||||
|
|
||||||
for pkg in pkgs:
|
for pkg in pkgs:
|
||||||
|
@ -399,7 +402,8 @@ def what_provides(module, repoq, req_spec, conf_file, qf=def_qf, en_repos=None,
|
||||||
e,m,u = my.rpmdb.matchPackageNames([req_spec])
|
e,m,u = my.rpmdb.matchPackageNames([req_spec])
|
||||||
pkgs.extend(e)
|
pkgs.extend(e)
|
||||||
pkgs.extend(m)
|
pkgs.extend(m)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failure talking to yum: %s" % e)
|
module.fail_json(msg="Failure talking to yum: %s" % e)
|
||||||
|
|
||||||
return set([ po_to_nevra(p) for p in pkgs ])
|
return set([ po_to_nevra(p) for p in pkgs ])
|
||||||
|
@ -588,7 +592,8 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
|
||||||
f.write(data)
|
f.write(data)
|
||||||
data = rsp.read(BUFSIZE)
|
data = rsp.read(BUFSIZE)
|
||||||
f.close()
|
f.close()
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
shutil.rmtree(tempdir)
|
shutil.rmtree(tempdir)
|
||||||
module.fail_json(msg="Failure downloading %s, %s" % (spec, e))
|
module.fail_json(msg="Failure downloading %s, %s" % (spec, e))
|
||||||
|
|
||||||
|
@ -664,7 +669,8 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
|
||||||
# Remove rpms downloaded for EL5 via url
|
# Remove rpms downloaded for EL5 via url
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(tempdir)
|
shutil.rmtree(tempdir)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e))
|
module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e))
|
||||||
|
|
||||||
module.exit_json(changed=True, results=res['results'], changes=dict(installed=pkgs))
|
module.exit_json(changed=True, results=res['results'], changes=dict(installed=pkgs))
|
||||||
|
@ -704,7 +710,8 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
|
||||||
# Remove rpms downloaded for EL5 via url
|
# Remove rpms downloaded for EL5 via url
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(tempdir)
|
shutil.rmtree(tempdir)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e))
|
module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e))
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
@ -959,9 +966,11 @@ def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo,
|
||||||
rid = my.repos.getRepo(i)
|
rid = my.repos.getRepo(i)
|
||||||
a = rid.repoXML.repoid
|
a = rid.repoXML.repoid
|
||||||
current_repos = new_repos
|
current_repos = new_repos
|
||||||
except yum.Errors.YumBaseError, e:
|
except yum.Errors.YumBaseError:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Error setting/accessing repos: %s" % (e))
|
module.fail_json(msg="Error setting/accessing repos: %s" % (e))
|
||||||
except yum.Errors.YumBaseError, e:
|
except yum.Errors.YumBaseError:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Error accessing repos: %s" % e)
|
module.fail_json(msg="Error accessing repos: %s" % e)
|
||||||
if state in ['installed', 'present']:
|
if state in ['installed', 'present']:
|
||||||
if disable_gpg_check:
|
if disable_gpg_check:
|
||||||
|
|
Loading…
Reference in a new issue