Skip to content

Commit

Permalink
Merge pull request #9 from minrk/tidy-users
Browse files Browse the repository at this point in the history
tidy saveuser scripts a bit
  • Loading branch information
minrk committed Apr 27, 2016
2 parents 25d9c97 + f2fb213 commit 67da004
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 5 additions & 8 deletions roles/saveusers/files/create_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@
sys.exit()

with open(fname, 'r') as f:
users = json.loads(f.read())
users = json.load(f)

for username, uid in users:
home_dir = os.path.abspath(os.path.join('.', username))
try:
udata = pwd.getpwnam(username)
except KeyError:
cmd = ['adduser', '-q', '--uid', str(uid),
'--no-create-home', '--home', home_dir,
'--gecos', '""', '--disabled-password', username]
if os.path.isdir(home_dir):
cmd = ['adduser', '-q', '--uid', str(uid),
'--no-create-home', '--home', home_dir,
'--gecos', '""', '--disabled-password', username]
else:
cmd = ['adduser', '-q', '--uid', str(uid),
'--home', home_dir,
'--gecos', '""', '--disabled-password', username]
cmd.append('--no-create-home')
print('Creating user: {}'.format(' '.join(cmd)))
try:
check_call(cmd)
Expand Down
4 changes: 2 additions & 2 deletions roles/saveusers/files/save_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
data.append((username, uid))
print("Saving user: {}:{}".format(username, uid))

with open('./saved_users.txt','w') as f:
f.write(json.dumps(data))
with open('./saved_users.txt', 'w') as f:
json.dump(data, f)

0 comments on commit 67da004

Please sign in to comment.