Nicer prints

This commit is contained in:
uid 2020-10-12 18:42:09 +02:00
parent eb9827bb33
commit 1333c03954

View File

@ -19,7 +19,7 @@ def showuser(uid):
print('User {} not found'.format(uid)) print('User {} not found'.format(uid))
return return
print('\nuid: {}\n{}\n\n'.format(uid, pp(user))) print(pp(user))
@cli.register('add a new user', ['user identifier']) @cli.register('add a new user', ['user identifier'])
@ -28,6 +28,11 @@ def adduser(uid):
full_prompt = '{} [{}] '.format(prompt, default) full_prompt = '{} [{}] '.format(prompt, default)
return input(full_prompt) or default return input(full_prompt) or default
user = get_user_by_uid(client, uid)
if user is not None:
print("User {} already existing".format(uid))
return
cn = ask('Common name:', uid) cn = ask('Common name:', uid)
sn = ask('Last name:', uid) sn = ask('Last name:', uid)
mail = ask('Mail:', '{}@localhost'.format(uid)) mail = ask('Mail:', '{}@localhost'.format(uid))
@ -42,7 +47,8 @@ def adduser(uid):
# Check # Check
user = get_user_by_uid(client, uid) user = get_user_by_uid(client, uid)
print('\nuid: {}\n{}\n\n'.format(uid, pp(user))) print()
print(pp(user))
@cli.register('delete an user', ['user identifier']) @cli.register('delete an user', ['user identifier'])
@ -54,8 +60,8 @@ def deluser(uid):
user = get_user_by_uid(client, uid) user = get_user_by_uid(client, uid)
if user is not None: if user is not None:
print('Deleting')
delete_user(client, user) delete_user(client, user)
print('Done')
else: else:
print('User {} not found'.format(uid)) print('User {} not found'.format(uid))
@ -67,18 +73,15 @@ def showgroup(cn):
print('Group {} not found'.format(gcn)) print('Group {} not found'.format(gcn))
return return
print('\ncn: {}\n{}\n\n'.format(cn, pp(group))) print(pp(group))
@cli.register('list all groups') @cli.register('list all groups')
def listgroups(): def listgroups():
groups = get_all_groups(client) groups = get_all_groups(client)
print()
for group in groups: for group in groups:
print(group['cn']) print(group['cn'])
print()
@cli.register('add an user to a group', @cli.register('add an user to a group',