1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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
This commit is contained in:
Chris Weber 2016-06-04 14:21:04 -07:00 committed by Matt Clay
parent 4ee8468710
commit c3a1efee4f
3 changed files with 14 additions and 10 deletions

View file

@ -26,6 +26,8 @@ import os
import hashlib import hashlib
import sys import sys
import posixpath import posixpath
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
@ -330,7 +332,7 @@ def main():
try: try:
artifact = Artifact(group_id, artifact_id, version, classifier, extension) artifact = Artifact(group_id, artifact_id, version, classifier, extension)
except ValueError, e: except ValueError as e:
module.fail_json(msg=e.args[0]) module.fail_json(msg=e.args[0])
prev_state = "absent" 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) 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: else:
module.fail_json(msg="Unable to download the artifact") module.fail_json(msg="Unable to download the artifact")
except ValueError, e: except ValueError as e:
module.fail_json(msg=e.args[0]) 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__': if __name__ == '__main__':
main() main()

View file

@ -120,7 +120,7 @@ def download_url(module, url, dest):
try: try:
with open(dest, 'w') as f: with open(dest, 'w') as f:
shutil.copyfileobj(response, f) shutil.copyfileobj(response, f)
except IOError, e: except IOError as e:
raise ModuleError("Failed to write: %s" % str(e)) raise ModuleError("Failed to write: %s" % str(e))
@ -248,7 +248,7 @@ def main():
else: else:
changed = uninstall_overlay(module, name) changed = uninstall_overlay(module, name)
except ModuleError, e: except ModuleError as e:
module.fail_json(msg=e.message) module.fail_json(msg=e.message)
else: else:
module.exit_json(changed=changed, name=name) module.exit_json(changed=changed, name=name)

View file

@ -21,6 +21,7 @@
import ConfigParser import ConfigParser
import os import os
from ansible.module_utils.pycompat24 import get_exception
DOCUMENTATION = ''' DOCUMENTATION = '''
@ -575,7 +576,8 @@ class YumRepo(object):
# Write data into the file # Write data into the file
try: try:
fd = open(self.params['dest'], 'wb') fd = open(self.params['dest'], 'wb')
except IOError, e: except IOError:
e = get_exception()
self.module.fail_json( self.module.fail_json(
msg="Cannot open repo file %s." % self.params['dest'], msg="Cannot open repo file %s." % self.params['dest'],
details=str(e)) details=str(e))
@ -584,7 +586,8 @@ class YumRepo(object):
try: try:
fd.close() fd.close()
except IOError, e: except IOError:
e = get_exception()
self.module.fail_json( self.module.fail_json(
msg="Cannot write repo file %s." % self.params['dest'], msg="Cannot write repo file %s." % self.params['dest'],
details=str(e)) details=str(e))
@ -592,7 +595,8 @@ class YumRepo(object):
# Remove the file if there are not repos # Remove the file if there are not repos
try: try:
os.remove(self.params['dest']) os.remove(self.params['dest'])
except OSError, e: except OSError:
e = get_exception()
self.module.fail_json( self.module.fail_json(
msg=( msg=(
"Cannot remove empty repo file %s." % "Cannot remove empty repo file %s." %