From b8175f70ce6a2a7ef90b64224495cd6e9a303c2c Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Fri, 20 May 2016 16:48:10 +0200 Subject: [PATCH] Convert packaging/* to py3/py2.4 syntax (#3702) --- lib/ansible/modules/packaging/os/apt.py | 2 +- .../modules/packaging/os/apt_repository.py | 11 +++++--- .../packaging/os/redhat_subscription.py | 9 ++++--- .../modules/packaging/os/rhn_register.py | 8 +++--- lib/ansible/modules/packaging/os/yum.py | 27 ++++++++++++------- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/lib/ansible/modules/packaging/os/apt.py b/lib/ansible/modules/packaging/os/apt.py index 7548225786e..1c388b413cd 100644 --- a/lib/ansible/modules/packaging/os/apt.py +++ b/lib/ansible/modules/packaging/os/apt.py @@ -492,7 +492,7 @@ def install_deb(m, debs, cache, force, install_recommends, allow_unauthenticated if package_version_compare(pkg_version, installed_version) == 0: # Does not need to down-/upgrade, move on to next package continue - except Exception, e: + except Exception: # Must not be installed, continue with installation pass # Check if package is installable diff --git a/lib/ansible/modules/packaging/os/apt_repository.py b/lib/ansible/modules/packaging/os/apt_repository.py index 55b60987824..d8ccf990db1 100644 --- a/lib/ansible/modules/packaging/os/apt_repository.py +++ b/lib/ansible/modules/packaging/os/apt_repository.py @@ -273,7 +273,8 @@ class SourcesList(object): try: 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.atomic_move(tmp_path, filename) @@ -451,7 +452,7 @@ def main(): argument_spec=dict( repo=dict(required=True), 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'), filename=dict(required=False, default=None), # this should not be needed, but exists as a failsafe @@ -488,7 +489,8 @@ def main(): sourceslist.add_source(repo) elif state == 'absent': sourceslist.remove_source(repo) - except InvalidSource, err: + except InvalidSource: + err = get_exception() module.fail_json(msg='Invalid repository string: %s' % unicode(err)) sources_after = sourceslist.dump() @@ -510,7 +512,8 @@ def main(): if update_cache: cache = apt.Cache() cache.update() - except OSError, err: + except OSError: + err = get_exception() module.fail_json(msg=unicode(err)) module.exit_json(changed=changed, repo=repo, state=state, diff=diff) diff --git a/lib/ansible/modules/packaging/os/redhat_subscription.py b/lib/ansible/modules/packaging/os/redhat_subscription.py index b2d62101577..44a65d11bb4 100644 --- a/lib/ansible/modules/packaging/os/redhat_subscription.py +++ b/lib/ansible/modules/packaging/os/redhat_subscription.py @@ -475,7 +475,8 @@ def main(): if pool != '^$': try: 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)) else: module.exit_json(**result) @@ -488,7 +489,8 @@ def main(): rhn.register(username, password, autosubscribe, activationkey, org_id, consumer_type, consumer_name, consumer_id) 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)) else: module.exit_json(changed=True, @@ -502,7 +504,8 @@ def main(): try: rhn.unsubscribe() rhn.unregister() - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="Failed to unregister: %s" % e) else: module.exit_json(changed=True, msg="System successfully unregistered from %s." % server_hostname) diff --git a/lib/ansible/modules/packaging/os/rhn_register.py b/lib/ansible/modules/packaging/os/rhn_register.py index ae5102d3c72..67c54eeb788 100644 --- a/lib/ansible/modules/packaging/os/rhn_register.py +++ b/lib/ansible/modules/packaging/os/rhn_register.py @@ -120,7 +120,7 @@ try: import up2date_client import up2date_client.config HAS_UP2DATE_CLIENT = True -except ImportError, e: +except ImportError: HAS_UP2DATE_CLIENT = False # INSERT REDHAT SNIPPETS @@ -387,7 +387,8 @@ def main(): rhn.enable() rhn.register(module.params['enable_eus'] == True, activationkey, profilename, sslcacert, systemorgid) 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.exit_json(changed=True, msg="System successfully registered to '%s'." % rhn.hostname) @@ -399,7 +400,8 @@ def main(): else: try: rhn.unregister() - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="Failed to unregister: %s" % e) module.exit_json(changed=True, msg="System successfully unregistered from %s." % rhn.hostname) diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index 792362d73a4..f8a9e1e7093 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -245,7 +245,8 @@ def is_installed(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, di pkgs = e + m if not pkgs and not is_pkg: pkgs.extend(my.returnInstalledPackagesByDep(pkgspec)) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="Failure talking to yum: %s" % e) 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 if not pkgs: pkgs.extend(my.returnPackagesByDep(pkgspec)) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="Failure talking to yum: %s" % e) 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]) pkgs = e + m updates = my.doPackageLists(pkgnarrow='updates').updates - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="Failure talking to yum: %s" % e) 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]) pkgs.extend(e) pkgs.extend(m) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="Failure talking to yum: %s" % e) 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) data = rsp.read(BUFSIZE) f.close() - except Exception, e: + except Exception: + e = get_exception() shutil.rmtree(tempdir) 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 try: shutil.rmtree(tempdir) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e)) 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 try: shutil.rmtree(tempdir) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e)) return res @@ -959,9 +966,11 @@ def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo, rid = my.repos.getRepo(i) a = rid.repoXML.repoid 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)) - except yum.Errors.YumBaseError, e: + except yum.Errors.YumBaseError: + e = get_exception() module.fail_json(msg="Error accessing repos: %s" % e) if state in ['installed', 'present']: if disable_gpg_check: