コード例 #1
0
ファイル: cli.py プロジェクト: miradam/python-ipalib
 def print_entry(self,
                 entry,
                 order=None,
                 labels=None,
                 flags=None,
                 print_all=True,
                 format='%s: %s',
                 indent=1):
     """
     """
     if isinstance(entry, (list, tuple)):
         entry = dict(entry)
     assert isinstance(entry, dict)
     if labels is None:
         labels = dict()
         one_value_per_line = True
     else:
         one_value_per_line = False
     if order is not None:
         for key in order:
             if key not in entry:
                 continue
             label = labels.get(key, key)
             flag = flags.get(key, [])
             value = entry[key]
             if ('suppress_empty' in flag
                     and value in [u'', '', (), [], None]):
                 continue
             if isinstance(value, dict):
                 if frontend.entry_count(value) == 0:
                     continue
                 self.print_indented(format % (label, ''), indent)
                 self.print_entry(value,
                                  order,
                                  labels,
                                  flags,
                                  print_all,
                                  format,
                                  indent=indent + 1)
             else:
                 if isinstance(value, (list, tuple)) and \
                    all(isinstance(val, dict) for val in value):
                     # this is a list of entries (dicts), not values
                     self.print_attribute(label, u'', format, indent)
                     self.print_entries(value, order, labels, flags,
                                        print_all, format, indent + 1)
                 else:
                     self.print_attribute(label, value, format, indent,
                                          one_value_per_line)
             del entry[key]
     if print_all:
         for key in sorted(entry):
             label = labels.get(key, key)
             self.print_attribute(key, entry[key], format, indent,
                                  one_value_per_line)
コード例 #2
0
ファイル: cli.py プロジェクト: msrb/freeipa
 def print_entry(self, entry, order=None, labels=None, flags=None, print_all=True, format='%s: %s', indent=1):
     """
     """
     if isinstance(entry, (list, tuple)):
         entry = dict(entry)
     assert isinstance(entry, dict)
     if labels is None:
         labels = dict()
         one_value_per_line = True
     else:
         one_value_per_line = False
     if order is not None:
         for key in order:
             if key not in entry:
                 continue
             label = labels.get(key, key)
             flag = flags.get(key, [])
             value = entry[key]
             if ('suppress_empty' in flag and
                 value in [u'', '', (), [], None]):
                 continue
             if isinstance(value, dict):
                 if frontend.entry_count(value) == 0:
                     continue
                 self.print_indented(format % (label, ''), indent)
                 self.print_entry(
                     value, order, labels, flags, print_all, format,
                     indent=indent+1
                 )
             else:
                 if isinstance(value, (list, tuple)) and \
                    all(isinstance(val, dict) for val in value):
                     # this is a list of entries (dicts), not values
                     self.print_attribute(label, u'', format, indent)
                     self.print_entries(value, order, labels, flags, print_all,
                             format, indent+1)
                 else:
                     self.print_attribute(
                         label, value, format, indent, one_value_per_line
                     )
             del entry[key]
     if print_all:
         for key in sorted(entry):
             label = labels.get(key, key)
             self.print_attribute(
                 key, entry[key], format, indent, one_value_per_line
             )