Convert the whole files/ directory to py3 syntax (#3685)
This commit is contained in:
parent
f87f0ec277
commit
69ea617093
8 changed files with 38 additions and 20 deletions
|
@ -22,8 +22,8 @@ script:
|
||||||
- python2.4 -m compileall -fq cloud/amazon/_ec2_ami_search.py cloud/amazon/ec2_facts.py
|
- python2.4 -m compileall -fq cloud/amazon/_ec2_ami_search.py cloud/amazon/ec2_facts.py
|
||||||
- python2.6 -m compileall -fq .
|
- python2.6 -m compileall -fq .
|
||||||
- python2.7 -m compileall -fq .
|
- python2.7 -m compileall -fq .
|
||||||
- python3.4 -m compileall -fq system/ commands/ source_control/ inventory/
|
- python3.4 -m compileall -fq system/ commands/ source_control/ inventory/ files/
|
||||||
- python3.5 -m compileall -fq system/ commands/ source_control/ inventory/
|
- python3.5 -m compileall -fq system/ commands/ source_control/ inventory/ files/
|
||||||
- ansible-validate-modules --exclude 'utilities/' .
|
- ansible-validate-modules --exclude 'utilities/' .
|
||||||
#- ansible-validate-modules --exclude 'cloud/amazon/ec2_lc\.py|cloud/amazon/ec2_scaling_policy\.py|cloud/amazon/ec2_scaling_policy\.py|cloud/amazon/ec2_asg\.py|cloud/azure/azure\.py|packaging/os/rhn_register\.py|network/openswitch/ops_template\.py|system/hostname\.py|utilities/' .
|
#- ansible-validate-modules --exclude 'cloud/amazon/ec2_lc\.py|cloud/amazon/ec2_scaling_policy\.py|cloud/amazon/ec2_scaling_policy\.py|cloud/amazon/ec2_asg\.py|cloud/azure/azure\.py|packaging/os/rhn_register\.py|network/openswitch/ops_template\.py|system/hostname\.py|utilities/' .
|
||||||
#- ./test-docs.sh core
|
#- ./test-docs.sh core
|
||||||
|
|
|
@ -206,7 +206,8 @@ def run_acl(module, cmd, check_rc=True):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(rc, out, err) = module.run_command(' '.join(cmd), check_rc=check_rc)
|
(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)
|
module.fail_json(msg=e.strerror)
|
||||||
|
|
||||||
lines = out.splitlines()
|
lines = out.splitlines()
|
||||||
|
|
|
@ -156,7 +156,8 @@ def cleanup(path, result=None):
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
try:
|
try:
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
except (IOError, OSError), e:
|
except (IOError, OSError):
|
||||||
|
e = get_exception()
|
||||||
# don't error on possible race conditions, but keep warning
|
# don't error on possible race conditions, but keep warning
|
||||||
if result is not None:
|
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, str(e))]
|
||||||
|
@ -203,7 +204,8 @@ def main():
|
||||||
if regexp != None:
|
if regexp != None:
|
||||||
try:
|
try:
|
||||||
compiled_regexp = re.compile(regexp)
|
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))
|
module.fail_json(msg="Invalid Regexp (%s) in \"%s\"" % (e, regexp))
|
||||||
|
|
||||||
if validate and "%s" not in validate:
|
if validate and "%s" not in validate:
|
||||||
|
|
|
@ -291,7 +291,8 @@ def main():
|
||||||
# the execute bit for the current user set, in
|
# the execute bit for the current user set, in
|
||||||
# which case the stat() call will raise an OSError
|
# which case the stat() call will raise an OSError
|
||||||
os.stat(os.path.dirname(dest))
|
os.stat(os.path.dirname(dest))
|
||||||
except OSError, e:
|
except OSError:
|
||||||
|
e = get_exception()
|
||||||
if "permission denied" in str(e).lower():
|
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 is not accessible" % (os.path.dirname(dest)))
|
||||||
module.fail_json(msg="Destination directory %s does not exist" % (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':
|
if prev_state == 'directory':
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(path, ignore_errors=False)
|
shutil.rmtree(path, ignore_errors=False)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="rmtree failed: %s" % str(e))
|
module.fail_json(msg="rmtree failed: %s" % str(e))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(path=path, msg="unlinking failed: %s " % str(e))
|
module.fail_json(path=path, msg="unlinking failed: %s " % str(e))
|
||||||
module.exit_json(path=path, changed=True, diff=diff)
|
module.exit_json(path=path, changed=True, diff=diff)
|
||||||
else:
|
else:
|
||||||
|
@ -301,7 +303,8 @@ def main():
|
||||||
if not os.path.exists(curpath):
|
if not os.path.exists(curpath):
|
||||||
try:
|
try:
|
||||||
os.mkdir(curpath)
|
os.mkdir(curpath)
|
||||||
except OSError, ex:
|
except OSError:
|
||||||
|
ex = get_exception()
|
||||||
# Possibly something else created the dir since the os.path.exists
|
# 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.
|
# 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)):
|
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 = file_args.copy()
|
||||||
tmp_file_args['path']=curpath
|
tmp_file_args['path']=curpath
|
||||||
changed = module.set_fs_attributes_if_different(tmp_file_args, changed, diff)
|
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)))
|
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.
|
# We already know prev_state is not 'absent', therefore it exists in some form.
|
||||||
|
@ -376,7 +380,8 @@ def main():
|
||||||
else:
|
else:
|
||||||
os.symlink(src, tmppath)
|
os.symlink(src, tmppath)
|
||||||
os.rename(tmppath, path)
|
os.rename(tmppath, path)
|
||||||
except OSError, e:
|
except OSError:
|
||||||
|
e = get_exception()
|
||||||
if os.path.exists(tmppath):
|
if os.path.exists(tmppath):
|
||||||
os.unlink(tmppath)
|
os.unlink(tmppath)
|
||||||
module.fail_json(path=path, msg='Error while replacing: %s' % str(e))
|
module.fail_json(path=path, msg='Error while replacing: %s' % str(e))
|
||||||
|
@ -386,7 +391,8 @@ def main():
|
||||||
os.link(src,path)
|
os.link(src,path)
|
||||||
else:
|
else:
|
||||||
os.symlink(src, path)
|
os.symlink(src, path)
|
||||||
except OSError, e:
|
except OSError:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(path=path, msg='Error while linking: %s' % str(e))
|
module.fail_json(path=path, msg='Error while linking: %s' % str(e))
|
||||||
|
|
||||||
if module.check_mode and not os.path.exists(path):
|
if module.check_mode and not os.path.exists(path):
|
||||||
|
@ -401,18 +407,21 @@ def main():
|
||||||
if prev_state == 'absent':
|
if prev_state == 'absent':
|
||||||
try:
|
try:
|
||||||
open(path, 'w').close()
|
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))
|
module.fail_json(path=path, msg='Error, could not touch target: %s' % str(e))
|
||||||
elif prev_state in ['file', 'directory', 'hard']:
|
elif prev_state in ['file', 'directory', 'hard']:
|
||||||
try:
|
try:
|
||||||
os.utime(path, None)
|
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))
|
module.fail_json(path=path, msg='Error while touching existing target: %s' % str(e))
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg='Cannot touch other than files, directories, and hardlinks (%s is %s)' % (path, prev_state))
|
module.fail_json(msg='Cannot touch other than files, directories, and hardlinks (%s is %s)' % (path, prev_state))
|
||||||
try:
|
try:
|
||||||
module.set_fs_attributes_if_different(file_args, True, diff)
|
module.set_fs_attributes_if_different(file_args, True, diff)
|
||||||
except SystemExit, e:
|
except SystemExit:
|
||||||
|
e = get_exception()
|
||||||
if e.code:
|
if e.code:
|
||||||
# We take this to mean that fail_json() was called from
|
# We take this to mean that fail_json() was called from
|
||||||
# somewhere in basic.py
|
# somewhere in basic.py
|
||||||
|
|
|
@ -326,7 +326,8 @@ def main():
|
||||||
st = os.stat(path)
|
st = os.stat(path)
|
||||||
else:
|
else:
|
||||||
st = os.lstat(path)
|
st = os.lstat(path)
|
||||||
except OSError, e:
|
except OSError:
|
||||||
|
e = get_exception()
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
d = { 'exists' : False }
|
d = { 'exists' : False }
|
||||||
module.exit_json(changed=False, stat=d)
|
module.exit_json(changed=False, stat=d)
|
||||||
|
|
|
@ -695,7 +695,8 @@ def main():
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
f.close()
|
||||||
src = package
|
src = package
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failure downloading %s, %s" % (src, e))
|
module.fail_json(msg="Failure downloading %s, %s" % (src, e))
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Source '%s' does not exist" % src)
|
module.fail_json(msg="Source '%s' does not exist" % src)
|
||||||
|
@ -706,7 +707,8 @@ def main():
|
||||||
try:
|
try:
|
||||||
if os.path.getsize(src) == 0:
|
if os.path.getsize(src) == 0:
|
||||||
module.fail_json(msg="Invalid archive '%s', the file is 0 bytes" % src)
|
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)
|
module.fail_json(msg="Source '%s' not readable" % src)
|
||||||
|
|
||||||
# is dest OK to receive tar file?
|
# is dest OK to receive tar file?
|
||||||
|
@ -746,7 +748,8 @@ def main():
|
||||||
file_args['path'] = os.path.join(dest, filename)
|
file_args['path'] = os.path.join(dest, filename)
|
||||||
try:
|
try:
|
||||||
res_args['changed'] = module.set_fs_attributes_if_different(file_args, res_args['changed'])
|
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))
|
module.fail_json(msg="Unexpected error when accessing exploded file: %s" % str(e))
|
||||||
|
|
||||||
if module.params['list_files']:
|
if module.params['list_files']:
|
||||||
|
|
|
@ -124,7 +124,8 @@ def _run_xattr(module,cmd,check_rc=True):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(rc, out, err) = module.run_command(' '.join(cmd), check_rc=check_rc)
|
(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)
|
module.fail_json(msg="%s!" % e.strerror)
|
||||||
|
|
||||||
#result = {'raw': out}
|
#result = {'raw': out}
|
||||||
|
|
Loading…
Reference in a new issue