From 596d410471672eac0e429c53d2f28ff6ea43d867 Mon Sep 17 00:00:00 2001 From: Pavel Zuna Date: Tue, 21 Apr 2009 15:20:32 +0200 Subject: Make LDAP entry output slightly nicer, don't print u's in front of unicode strings etc. --- ipalib/cli.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'ipalib') 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='-'): """ -- cgit