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:
parent
4ee8468710
commit
c3a1efee4f
3 changed files with 14 additions and 10 deletions
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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." %
|
||||
|
|
Loading…
Reference in a new issue