forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fix for missing imports and boilerplate in files modules, also, removed get_exception calls to match 2.6> exception handling. Signed-off-by: Abhijeet Kasurde <[email protected]>
- Loading branch information
Showing
19 changed files
with
168 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,13 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# (c) 2016, Ben Doherty <[email protected]> | ||
# Copyright: (c) 2016, Ben Doherty <[email protected]> | ||
# Sponsored by Oomph, Inc. http://www.oomphinc.com | ||
# | ||
# This file is part of Ansible | ||
# | ||
# Ansible is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Ansible is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. | ||
# Copyright: (c) 2017, Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.0', | ||
'status': ['preview'], | ||
|
@@ -149,8 +139,9 @@ | |
import filecmp | ||
import zipfile | ||
import tarfile | ||
from traceback import format_exc | ||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.pycompat24 import get_exception | ||
from ansible.module_utils._text import to_native | ||
|
||
|
||
def main(): | ||
|
@@ -318,9 +309,8 @@ def main(): | |
else: | ||
arcfile.add(fullpath, arcname, recursive=False) | ||
|
||
except Exception: | ||
e = get_exception() | ||
errors.append('%s: %s' % (fullpath, str(e))) | ||
except Exception as e: | ||
errors.append('%s: %s' % (fullpath, to_native(e))) | ||
|
||
for filename in filenames: | ||
fullpath = dirpath + filename | ||
|
@@ -334,9 +324,8 @@ def main(): | |
arcfile.add(fullpath, arcname, recursive=False) | ||
|
||
successes.append(fullpath) | ||
except Exception: | ||
e = get_exception() | ||
errors.append('Adding %s: %s' % (path, str(e))) | ||
except Exception as e: | ||
errors.append('Adding %s: %s' % (path, to_native(e))) | ||
else: | ||
if format == 'zip': | ||
arcfile.write(path, match_root.sub('', path)) | ||
|
@@ -345,9 +334,9 @@ def main(): | |
|
||
successes.append(path) | ||
|
||
except Exception: | ||
e = get_exception() | ||
return module.fail_json(msg='Error when writing %s archive at %s: %s' % (format == 'zip' and 'zip' or ('tar.' + format), dest, str(e))) | ||
except Exception as e: | ||
module.fail_json(msg='Error when writing %s archive at %s: %s' % (format == 'zip' and 'zip' or ('tar.' + format), dest, to_native(e)), | ||
exception=format_exc()) | ||
|
||
if arcfile: | ||
arcfile.close() | ||
|
@@ -363,8 +352,7 @@ def main(): | |
shutil.rmtree(path) | ||
elif not check_mode: | ||
os.remove(path) | ||
except OSError: | ||
e = get_exception() | ||
except OSError as e: | ||
errors.append(path) | ||
|
||
if len(errors) > 0: | ||
|
@@ -421,9 +409,8 @@ def main(): | |
|
||
successes.append(path) | ||
|
||
except OSError: | ||
e = get_exception() | ||
module.fail_json(path=path, dest=dest, msg='Unable to write to compressed file: %s' % str(e)) | ||
except OSError as e: | ||
module.fail_json(path=path, dest=dest, msg='Unable to write to compressed file: %s' % to_native(e), exception=format_exc()) | ||
|
||
if arcfile: | ||
arcfile.close() | ||
|
@@ -442,9 +429,8 @@ def main(): | |
try: | ||
os.remove(path) | ||
|
||
except OSError: | ||
e = get_exception() | ||
module.fail_json(path=path, msg='Unable to remove source file: %s' % str(e)) | ||
except OSError as e: | ||
module.fail_json(path=path, msg='Unable to remove source file: %s' % to_native(e), exception=format_exc()) | ||
|
||
params['path'] = dest | ||
file_args = module.load_file_common_arguments(params) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,13 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# (c) 2012, Stephen Fromm <[email protected]> | ||
# (c) 2016, Toshio Kuratomi <[email protected]> | ||
# | ||
# This file is part of Ansible | ||
# | ||
# Ansible is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Ansible is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. | ||
# Copyright: (c) 2012, Stephen Fromm <[email protected]> | ||
# Copyright: (c) 2016, Toshio Kuratomi <[email protected]> | ||
# Copyright: (c) 2017, Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.0', | ||
'status': ['stableinterface'], | ||
|
@@ -125,8 +115,8 @@ | |
import tempfile | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.pycompat24 import get_exception | ||
from ansible.module_utils.six import b | ||
from ansible.module_utils._text import to_native | ||
|
||
|
||
# =========================================== | ||
|
@@ -178,11 +168,10 @@ def cleanup(path, result=None): | |
if os.path.exists(path): | ||
try: | ||
os.remove(path) | ||
except (IOError, OSError): | ||
e = get_exception() | ||
except (IOError, OSError) as e: | ||
# don't error on possible race conditions, but keep warning | ||
if result is not None: | ||
result['warnings'] = ['Unable to remove temp file (%s): %s' % (path, str(e))] | ||
result['warnings'] = ['Unable to remove temp file (%s): %s' % (path, to_native(e))] | ||
|
||
|
||
def main(): | ||
|
@@ -224,9 +213,8 @@ def main(): | |
if regexp is not None: | ||
try: | ||
compiled_regexp = re.compile(regexp) | ||
except re.error: | ||
e = get_exception() | ||
module.fail_json(msg="Invalid Regexp (%s) in \"%s\"" % (e, regexp)) | ||
except re.error as e: | ||
module.fail_json(msg="Invalid Regexp (%s) in \"%s\"" % (to_native(e), regexp)) | ||
|
||
if validate and "%s" not in validate: | ||
module.fail_json(msg="validate must contain %%s: %s" % validate) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,12 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# (c) 2014, 2015 YAEGASHI Takeshi <[email protected]> | ||
# | ||
# This file is part of Ansible | ||
# | ||
# Ansible is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Ansible is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. | ||
# Copyright: (c) 2014, 2015 YAEGASHI Takeshi <[email protected]> | ||
# Copyright: (c) 2017, Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.0', | ||
'status': ['preview'], | ||
|
@@ -167,6 +157,7 @@ | |
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils._text import to_bytes | ||
|
||
|
||
def write_changes(module, contents, path): | ||
|
||
tmpfd, tmpfile = tempfile.mkstemp() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,12 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# (c) 2012, Michael DeHaan <[email protected]> | ||
# | ||
# This file is part of Ansible | ||
# | ||
# Ansible is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Ansible is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. | ||
# Copyright: (c) 2012, Michael DeHaan <[email protected]> | ||
# Copyright: (c) 2017, Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.0', | ||
'status': ['stableinterface'], | ||
|
@@ -238,7 +228,6 @@ | |
|
||
# import module snippets | ||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.pycompat24 import get_exception | ||
from ansible.module_utils._text import to_bytes, to_native | ||
|
||
|
||
|
@@ -359,8 +348,7 @@ def main(): | |
# the execute bit for the current user set, in | ||
# which case the stat() call will raise an OSError | ||
os.stat(os.path.dirname(b_dest)) | ||
except OSError: | ||
e = get_exception() | ||
except OSError as e: | ||
if "permission denied" in to_native(e).lower(): | ||
module.fail_json(msg="Destination directory %s is not accessible" % (os.path.dirname(dest))) | ||
module.fail_json(msg="Destination directory %s does not exist" % (os.path.dirname(dest))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.