summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-11-17 15:27:08 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-11-17 15:27:08 -0700
commit42bf555a3ad1f1777b26a4092b49512b9360c882 (patch)
tree82ec2c847b81f44a9e060957a505e05c6f70a273 /ipalib
parente7ec4131589d5d387c4257bca76e91a17ad7e1a3 (diff)
downloadfreeipa-42bf555a3ad1f1777b26a4092b49512b9360c882.tar.gz
freeipa-42bf555a3ad1f1777b26a4092b49512b9360c882.tar.xz
freeipa-42bf555a3ad1f1777b26a4092b49512b9360c882.zip
Started updated user_* commands to use textui
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/cli.py22
-rw-r--r--ipalib/plugins/f_user.py29
2 files changed, 39 insertions, 12 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index fc58f2e95..1c7256a2a 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -198,6 +198,28 @@ class textui(backend.Backend):
for (key, value) in rows:
self.print_indented('%s = %r' % (key, value), indent)
+ def print_entry(self, entry, indent=1):
+ """
+ Print an ldap entry dict.
+
+ For example:
+
+ >>> entry = dict(sn='Last', givenname='First', uid='flast')
+ >>> ui = textui()
+ >>> ui.print_entry(entry)
+ givenname: 'First'
+ sn: 'Last'
+ uid: 'flast'
+ """
+ assert type(entry) is dict
+ for key in sorted(entry):
+ value = entry[key]
+ if type(value) in (list, tuple):
+ value = ', '.join(repr(v) for v in value)
+ else:
+ value = repr(value)
+ self.print_indented('%s: %s' % (key, value), indent)
+
def print_dashed(self, string, above=True, below=True):
"""
Print a string with a dashed line above and/or below.
diff --git a/ipalib/plugins/f_user.py b/ipalib/plugins/f_user.py
index 3adb328cb..e96d787b0 100644
--- a/ipalib/plugins/f_user.py
+++ b/ipalib/plugins/f_user.py
@@ -191,18 +191,21 @@ class user_add(crud.Add):
kw['objectClass'] = config.get('ipauserobjectclasses')
return ldap.create(**kw)
- def output_for_cli(self, ret):
+
+ def output_for_cli(self, textui, result, *args, **options):
"""
Output result of this command to command line interface.
"""
- if ret:
- print "User added"
+ textui.print_name(self.name)
+ textui.print_entry(result)
+ textui.print_dashed('Added user "%s"' % result['uid'])
api.register(user_add)
class user_del(crud.Del):
'Delete an existing user.'
+
def execute(self, uid, **kw):
"""Delete a user. Not to be confused with inactivate_user. This
makes the entry go away completely.
@@ -224,12 +227,12 @@ class user_del(crud.Del):
ldap = self.api.Backend.ldap
dn = ldap.find_entry_dn("uid", uid)
return ldap.delete(dn)
- def output_for_cli(self, ret):
+
+ def output_for_cli(self, textui, result, uid):
"""
Output result of this command to command line interface.
"""
- if ret:
- print "User deleted"
+ textui.print_plain('Deleted user "%s"' % uid)
api.register(user_del)
@@ -254,12 +257,13 @@ class user_mod(crud.Mod):
dn = ldap.find_entry_dn("uid", uid)
return ldap.update(dn, **kw)
- def output_for_cli(self, ret):
+ def output_for_cli(self, textui, result, uid, **options):
"""
Output result of this command to command line interface.
"""
- if ret:
- print "User updated"
+ textui.print_name(self.name)
+ textui.print_entry(result)
+ textui.print_dashed('Updated user "%s"' % result['uid'])
api.register(user_mod)
@@ -330,9 +334,10 @@ class user_show(crud.Get):
return ldap.retrieve(dn)
else:
return ldap.retrieve(dn, default_attributes)
- def output_for_cli(self, user):
- if user:
- display_user(user)
+
+ def output_for_cli(self, textui, result, uid, **options):
+ if result:
+ display_user(result)
api.register(user_show)