diff options
author | Pavel Zuna <pzuna@redhat.com> | 2009-07-31 17:59:28 +0200 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2009-08-03 22:56:06 -0600 |
commit | 104d02e16745bd237505afdac02ba6cdb4ec25fa (patch) | |
tree | bafe8106e3df2325f987cefd14596fe1b683b325 /ipalib | |
parent | 03a80f512cf9c0e6affb9a9d26b0fe5c3f375060 (diff) | |
download | freeipa-104d02e16745bd237505afdac02ba6cdb4ec25fa.tar.gz freeipa-104d02e16745bd237505afdac02ba6cdb4ec25fa.tar.xz freeipa-104d02e16745bd237505afdac02ba6cdb4ec25fa.zip |
Enable attribute re-mapping and ordering when printing entries.
Also print multiple values on one line separated by commas.
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/cli.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index 00e328476..07e540edc 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -251,11 +251,13 @@ class textui(backend.Backend): """ assert isinstance(attr, basestring) if not isinstance(value, (list, tuple)): - value = [value] - for v in value: - self.print_indented('%s: %s' % (attr, v), indent) + # single-value attribute + self.print_indented('%s: %s' % (attr, value), indent) + else: + # multi-value attribute + self.print_indented('%s: %s' % (attr, ', '.join(value)), indent) - def print_entry(self, entry, indent=1): + def print_entry(self, entry, indent=1, attr_map={}, attr_order=['dn']): """ Print an ldap entry dict. @@ -268,12 +270,22 @@ class textui(backend.Backend): sn: Last uid: flast """ - assert type(entry) is dict - if entry.get('dn'): - self.print_attribute('dn', entry['dn'], indent) - del entry['dn'] - for key in sorted(entry): - self.print_attribute(key, entry[key], indent) + assert isinstance(entry, dict) + assert isinstance(attr_map, dict) + assert isinstance(attr_order, (list, tuple)) + + def print_attr(a): + if attr in attr_map: + self.print_attribute(attr_map[attr], entry[attr], indent) + else: + self.print_attribute(attr, entry[attr], indent) + + for attr in attr_order: + if attr in entry: + print_attr(attr) + del entry[attr] + for attr in sorted(entry): + print_attr(attr) def print_dashed(self, string, above=True, below=True, indent=0, dash='-'): """ |