From 9f58e7325c78f49f1c20fa4a7b072ef8e2b73790 Mon Sep 17 00:00:00 2001 From: Chris Weber Date: Sat, 4 Jun 2016 14:21:04 -0700 Subject: [PATCH] Fixed exception compatablity for py3 (and 2.4 in yum_repository.py) (#2369) * Fixed exception compatablity for py3 (and 2.4 in yum_repository.py) * Moved Import --- packaging/language/maven_artifact.py | 10 +++++----- packaging/os/layman.py | 4 ++-- packaging/os/yum_repository.py | 10 +++++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packaging/language/maven_artifact.py b/packaging/language/maven_artifact.py index f5295185451..1a33d1b9891 100644 --- a/packaging/language/maven_artifact.py +++ b/packaging/language/maven_artifact.py @@ -26,6 +26,8 @@ import os import hashlib import sys import posixpath +from ansible.module_utils.basic import * +from ansible.module_utils.urls import * DOCUMENTATION = ''' --- @@ -330,7 +332,7 @@ def main(): try: artifact = Artifact(group_id, artifact_id, version, classifier, extension) - except ValueError, e: + except ValueError as e: module.fail_json(msg=e.args[0]) prev_state = "absent" @@ -351,12 +353,10 @@ def main(): module.exit_json(state=state, dest=dest, group_id=group_id, artifact_id=artifact_id, version=version, classifier=classifier, extension=extension, repository_url=repository_url, changed=True) else: module.fail_json(msg="Unable to download the artifact") - except ValueError, e: + except ValueError as e: module.fail_json(msg=e.args[0]) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * + if __name__ == '__main__': main() diff --git a/packaging/os/layman.py b/packaging/os/layman.py index f9ace121201..ac6acd12d4b 100644 --- a/packaging/os/layman.py +++ b/packaging/os/layman.py @@ -120,7 +120,7 @@ def download_url(module, url, dest): try: with open(dest, 'w') as f: shutil.copyfileobj(response, f) - except IOError, e: + except IOError as e: raise ModuleError("Failed to write: %s" % str(e)) @@ -248,7 +248,7 @@ def main(): else: changed = uninstall_overlay(module, name) - except ModuleError, e: + except ModuleError as e: module.fail_json(msg=e.message) else: module.exit_json(changed=changed, name=name) diff --git a/packaging/os/yum_repository.py b/packaging/os/yum_repository.py index 5ea046eb9ea..dfdd665ed2f 100644 --- a/packaging/os/yum_repository.py +++ b/packaging/os/yum_repository.py @@ -21,6 +21,7 @@ import ConfigParser import os +from ansible.module_utils.pycompat24 import get_exception DOCUMENTATION = ''' @@ -575,7 +576,8 @@ class YumRepo(object): # Write data into the file try: fd = open(self.params['dest'], 'wb') - except IOError, e: + except IOError: + e = get_exception() self.module.fail_json( msg="Cannot open repo file %s." % self.params['dest'], details=str(e)) @@ -584,7 +586,8 @@ class YumRepo(object): try: fd.close() - except IOError, e: + except IOError: + e = get_exception() self.module.fail_json( msg="Cannot write repo file %s." % self.params['dest'], details=str(e)) @@ -592,7 +595,8 @@ class YumRepo(object): # Remove the file if there are not repos try: os.remove(self.params['dest']) - except OSError, e: + except OSError: + e = get_exception() self.module.fail_json( msg=( "Cannot remove empty repo file %s." %