summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorPavel Zuna <pzuna@redhat.com>2009-04-21 15:20:32 +0200
committerRob Crittenden <rcritten@redhat.com>2009-04-23 10:25:51 -0400
commit596d410471672eac0e429c53d2f28ff6ea43d867 (patch)
tree84d405e8c6ccc8c91d2174451e404200090abc67 /ipalib
parent5fa7c76f729bfebf8bcc271a7601da75d6e196fd (diff)
downloadfreeipa-596d410471672eac0e429c53d2f28ff6ea43d867.tar.gz
freeipa-596d410471672eac0e429c53d2f28ff6ea43d867.tar.xz
freeipa-596d410471672eac0e429c53d2f28ff6ea43d867.zip
Make LDAP entry output slightly nicer, don't print u's in front of unicode strings etc.
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/cli.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 36c945f2b..6a1a6d0ff 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -234,6 +234,27 @@ class textui(backend.Backend):
for (key, value) in rows:
self.print_indented('%s = %r' % (key, value), indent)
+ def print_attribute(self, attr, value, indent=1):
+ """
+ Print an ldap attribute.
+
+ For example:
+
+ >>> attr = 'dn'
+ >>> ui = textui()
+ >>> ui.print_attribute(attr, u'dc=example,dc=com')
+ dn: dc=example,dc=com
+ >>> attr = 'objectClass'
+ >>> ui.print_attribute(attr, [u'top', u'someClass'])
+ objectClass: top
+ objectClass: someClass
+ """
+ assert isinstance(attr, basestring)
+ if not isinstance(value, (list, tuple)):
+ value = [value]
+ for v in value:
+ self.print_indented('%s: %s' % (attr, v), indent)
+
def print_entry(self, entry, indent=1):
"""
Print an ldap entry dict.
@@ -249,15 +270,10 @@ class textui(backend.Backend):
"""
assert type(entry) is dict
if entry.get('dn'):
- self.print_indented('dn: %s' % (repr(entry['dn'])), indent)
+ self.print_attribute('dn', entry['dn'], indent)
del entry['dn']
for key in sorted(entry):
- value = entry[key]
- if type(value) in (list, tuple):
- for v in value:
- self.print_indented('%s: %s' % (key, repr(v)), indent)
- else:
- self.print_indented('%s: %s' % (key, repr(value)), indent)
+ self.print_attribute(key, entry[key], indent)
def print_dashed(self, string, above=True, below=True, indent=0, dash='-'):
"""