Convert the whole files/ directory to py3 syntax (#3685)
This commit is contained in:
parent
0027158b74
commit
f7b29ba8fd
7 changed files with 36 additions and 18 deletions
|
@ -206,7 +206,8 @@ def run_acl(module, cmd, check_rc=True):
|
|||
|
||||
try:
|
||||
(rc, out, err) = module.run_command(' '.join(cmd), check_rc=check_rc)
|
||||
except Exception, e:
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg=e.strerror)
|
||||
|
||||
lines = out.splitlines()
|
||||
|
|
|
@ -181,7 +181,8 @@ def cleanup(path, result=None):
|
|||
if os.path.exists(path):
|
||||
try:
|
||||
os.remove(path)
|
||||
except (IOError, OSError), e:
|
||||
except (IOError, OSError):
|
||||
e = get_exception()
|
||||
# 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))]
|
||||
|
@ -232,7 +233,8 @@ def main():
|
|||
if regexp != None:
|
||||
try:
|
||||
compiled_regexp = re.compile(regexp)
|
||||
except re.error, e:
|
||||
except re.error:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="Invalid Regexp (%s) in \"%s\"" % (e, regexp))
|
||||
|
||||
if validate and "%s" not in validate:
|
||||
|
|
|
@ -291,7 +291,8 @@ 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(dest))
|
||||
except OSError, e:
|
||||
except OSError:
|
||||
e = get_exception()
|
||||
if "permission denied" in str(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)))
|
||||
|
|
|
@ -250,12 +250,14 @@ def main():
|
|||
if prev_state == 'directory':
|
||||
try:
|
||||
shutil.rmtree(path, ignore_errors=False)
|
||||
except Exception, e:
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="rmtree failed: %s" % str(e))
|
||||
else:
|
||||
try:
|
||||
os.unlink(path)
|
||||
except Exception, e:
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(path=path, msg="unlinking failed: %s " % str(e))
|
||||
module.exit_json(path=path, changed=True, diff=diff)
|
||||
else:
|
||||
|
@ -301,7 +303,8 @@ def main():
|
|||
if not os.path.exists(curpath):
|
||||
try:
|
||||
os.mkdir(curpath)
|
||||
except OSError, ex:
|
||||
except OSError:
|
||||
ex = get_exception()
|
||||
# Possibly something else created the dir since the os.path.exists
|
||||
# check above. As long as it's a dir, we don't need to error out.
|
||||
if not (ex.errno == errno.EEXIST and os.path.isdir(curpath)):
|
||||
|
@ -309,7 +312,8 @@ def main():
|
|||
tmp_file_args = file_args.copy()
|
||||
tmp_file_args['path']=curpath
|
||||
changed = module.set_fs_attributes_if_different(tmp_file_args, changed, diff)
|
||||
except Exception, e:
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(path=path, msg='There was an issue creating %s as requested: %s' % (curpath, str(e)))
|
||||
|
||||
# We already know prev_state is not 'absent', therefore it exists in some form.
|
||||
|
@ -376,7 +380,8 @@ def main():
|
|||
else:
|
||||
os.symlink(src, tmppath)
|
||||
os.rename(tmppath, path)
|
||||
except OSError, e:
|
||||
except OSError:
|
||||
e = get_exception()
|
||||
if os.path.exists(tmppath):
|
||||
os.unlink(tmppath)
|
||||
module.fail_json(path=path, msg='Error while replacing: %s' % str(e))
|
||||
|
@ -386,7 +391,8 @@ def main():
|
|||
os.link(src,path)
|
||||
else:
|
||||
os.symlink(src, path)
|
||||
except OSError, e:
|
||||
except OSError:
|
||||
e = get_exception()
|
||||
module.fail_json(path=path, msg='Error while linking: %s' % str(e))
|
||||
|
||||
if module.check_mode and not os.path.exists(path):
|
||||
|
@ -401,18 +407,21 @@ def main():
|
|||
if prev_state == 'absent':
|
||||
try:
|
||||
open(path, 'w').close()
|
||||
except OSError, e:
|
||||
except OSError:
|
||||
e = get_exception()
|
||||
module.fail_json(path=path, msg='Error, could not touch target: %s' % str(e))
|
||||
elif prev_state in ['file', 'directory', 'hard']:
|
||||
try:
|
||||
os.utime(path, None)
|
||||
except OSError, e:
|
||||
except OSError:
|
||||
e = get_exception()
|
||||
module.fail_json(path=path, msg='Error while touching existing target: %s' % str(e))
|
||||
else:
|
||||
module.fail_json(msg='Cannot touch other than files, directories, and hardlinks (%s is %s)' % (path, prev_state))
|
||||
try:
|
||||
module.set_fs_attributes_if_different(file_args, True, diff)
|
||||
except SystemExit, e:
|
||||
except SystemExit:
|
||||
e = get_exception()
|
||||
if e.code:
|
||||
# We take this to mean that fail_json() was called from
|
||||
# somewhere in basic.py
|
||||
|
|
|
@ -326,7 +326,8 @@ def main():
|
|||
st = os.stat(path)
|
||||
else:
|
||||
st = os.lstat(path)
|
||||
except OSError, e:
|
||||
except OSError:
|
||||
e = get_exception()
|
||||
if e.errno == errno.ENOENT:
|
||||
d = { 'exists' : False }
|
||||
module.exit_json(changed=False, stat=d)
|
||||
|
|
|
@ -695,7 +695,8 @@ def main():
|
|||
f.write(data)
|
||||
f.close()
|
||||
src = package
|
||||
except Exception, e:
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="Failure downloading %s, %s" % (src, e))
|
||||
else:
|
||||
module.fail_json(msg="Source '%s' does not exist" % src)
|
||||
|
@ -706,7 +707,8 @@ def main():
|
|||
try:
|
||||
if os.path.getsize(src) == 0:
|
||||
module.fail_json(msg="Invalid archive '%s', the file is 0 bytes" % src)
|
||||
except Exception, e:
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="Source '%s' not readable" % src)
|
||||
|
||||
# is dest OK to receive tar file?
|
||||
|
@ -746,7 +748,8 @@ def main():
|
|||
file_args['path'] = os.path.join(dest, filename)
|
||||
try:
|
||||
res_args['changed'] = module.set_fs_attributes_if_different(file_args, res_args['changed'])
|
||||
except (IOError, OSError), e:
|
||||
except (IOError, OSError):
|
||||
e = get_exception()
|
||||
module.fail_json(msg="Unexpected error when accessing exploded file: %s" % str(e))
|
||||
|
||||
if module.params['list_files']:
|
||||
|
|
|
@ -124,7 +124,8 @@ def _run_xattr(module,cmd,check_rc=True):
|
|||
|
||||
try:
|
||||
(rc, out, err) = module.run_command(' '.join(cmd), check_rc=check_rc)
|
||||
except Exception, e:
|
||||
except Exception:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="%s!" % e.strerror)
|
||||
|
||||
#result = {'raw': out}
|
||||
|
|
Loading…
Reference in a new issue