From 75715a1b7343d5537839ee05ac62f2e40751f915 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) --- .travis.yml | 5 ----- packaging/os/apt.py | 2 +- packaging/os/apt_repository.py | 11 +++++++---- packaging/os/redhat_subscription.py | 9 ++++++--- packaging/os/rhn_register.py | 8 +++++--- packaging/os/yum.py | 27 ++++++++++++++++++--------- 6 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7628d91f4dc..8bc87cb5163 100644 --- a/.travis.yml +++ b/.travis.yml @@ -81,11 +81,6 @@ env: cloud/rackspace/rax_scaling_group.py cloud/rackspace/rax_scaling_policy.py cloud/vmware/vsphere_guest.py - packaging/os/apt.py - packaging/os/apt_repository.py - packaging/os/redhat_subscription.py - packaging/os/rhn_register.py - packaging/os/yum.py utilities/helper/accelerate.py utilities/logic/async_status.py utilities/logic/async_wrapper.py diff --git a/packaging/os/apt.py b/packaging/os/apt.py index 7548225786e..1c388b413cd 100644 --- a/packaging/os/apt.py +++ b/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/packaging/os/apt_repository.py b/packaging/os/apt_repository.py index 55b60987824..d8ccf990db1 100644 --- a/packaging/os/apt_repository.py +++ b/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/packaging/os/redhat_subscription.py b/packaging/os/redhat_subscription.py index b2d62101577..44a65d11bb4 100644 --- a/packaging/os/redhat_subscription.py +++ b/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/packaging/os/rhn_register.py b/packaging/os/rhn_register.py index 852ea0278ce..f30cf09084d 100644 --- a/packaging/os/rhn_register.py +++ b/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/packaging/os/yum.py b/packaging/os/yum.py index ad0f93e82f7..a92a35611bc 100644 --- a/packaging/os/yum.py +++ b/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: