Port user module to python3 and 2.4 compatible syntax (#3673)

pull/18777/head
Michael Scherer 9 years ago committed by Matt Clay
parent 31126034b0
commit f2212dc41a

@ -284,7 +284,8 @@ class User(object):
if module.params['expires']:
try:
self.expires = time.gmtime(module.params['expires'])
except Exception,e:
except Exception:
e = get_exception()
module.fail_json("Invalid expires time %s: %s" %(self.expires, str(e)))
if module.params['ssh_key_file'] is not None:
@ -584,9 +585,10 @@ class User(object):
if self.module.check_mode:
return (0, '', '')
try:
os.mkdir(ssh_dir, 0700)
os.mkdir(ssh_dir, int('0700', 8))
os.chown(ssh_dir, info[2], info[3])
except OSError, e:
except OSError:
e = get_exception()
return (1, '', 'Failed to create %s: %s' % (ssh_dir, str(e)))
if os.path.exists(ssh_key_file):
return (None, 'Key already exists', '')
@ -656,12 +658,14 @@ class User(object):
if os.path.exists(skeleton):
try:
shutil.copytree(skeleton, path, symlinks=True)
except OSError, e:
except OSError:
e = get_exception()
self.module.exit_json(failed=True, msg="%s" % e)
else:
try:
os.makedirs(path)
except OSError, e:
except OSError:
e = get_exception()
self.module.exit_json(failed=True, msg="%s" % e)
def chown_homedir(self, uid, gid, path):
@ -672,7 +676,8 @@ class User(object):
os.chown(path, uid, gid)
for f in files:
os.chown(os.path.join(root, f), uid, gid)
except OSError, e:
except OSError:
e = get_exception()
self.module.exit_json(failed=True, msg="%s" % e)
@ -1290,7 +1295,8 @@ class SunOS(User):
line = ':'.join(fields)
lines.append('%s\n' % line)
open(self.SHADOWFILE, 'w+').writelines(lines)
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to update users password: %s" % str(err))
return (rc, out, err)
@ -1377,7 +1383,8 @@ class SunOS(User):
lines.append('%s\n' % line)
open(self.SHADOWFILE, 'w+').writelines(lines)
rc = 0
except Exception, err:
except Exception:
err = get_exception()
self.module.fail_json(msg="failed to update users password: %s" % str(err))
return (rc, out, err)

Loading…
Cancel
Save