]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Output changes
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 11 Jan 2023 14:47:19 +0000 (15:47 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 11 Jan 2023 14:47:19 +0000 (15:47 +0100)
lib/pp_admintools/app/check_ldap_dn_attributes.py

index 45769d9ec531243351bd26918551047c93dee84d..f2a37d2e21202afc1df102c9e1955923e1f5adfc 100644 (file)
@@ -11,15 +11,13 @@ from __future__ import absolute_import
 # Standard modules
 import re
 import logging
+import sys
 
 from functools import cmp_to_key
 
 # Third party modules
-# import yaml
 
 # Own modules
-# from fb_tools.common import to_bool, is_sequence
-# from fb_tools.collections import FrozenCIStringSet, CIStringSet, CIDict
 from fb_tools.collections import CIDict, CIStringSet
 from fb_tools.xlate import format_list
 
@@ -33,7 +31,7 @@ from ..config.ldap import LdapConfiguration
 from .ldap import LdapAppError
 from .ldap import BaseLdapApplication
 
-__version__ = '0.3.2'
+__version__ = '0.3.3'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -172,7 +170,7 @@ class CheckLdapDnAttributesApplication(BaseLdapApplication):
             self.check_entry(dn)
 
         if self.failed_entries:
-            print(pp(self.failed_entries.as_dict(pure=True)))
+            self.print_errors()
             nr = len(self.failed_entries)
             nr_attr = 0
             for e_dn in self.failed_entries:
@@ -191,21 +189,28 @@ class CheckLdapDnAttributesApplication(BaseLdapApplication):
                 with open(
                         self.export_file, 'wt', encoding='utf-8', errors='surrogateescape') as fh:
                     print('---', file=fh)
-                    sorted_dns = sorted(
-                        list(self.failed_entries.keys()), key=cmp_to_key(self.compare_ldap_dns))
-                    for dn in sorted_dns:
-                        entry = self.failed_entries[dn]
-                        print("'{}':".format(dn), file=fh)
-                        for attr in entry.keys():
-                            print('  {}:'.format(attr), file=fh)
-                            for val in self.failed_entries[dn][attr]:
-                                print("  - '{}'".format(val), file=fh)
+                    self.print_errors(out=fh)
             self.exit(5)
 
         msg = _("Did not found any inconsistent entries.")
         LOG.info(msg)
         self.exit(0)
 
+    # -------------------------------------------------------------------------
+    def print_errors(self, out=sys.stdout):
+
+        sorted_dns = sorted(
+            list(self.failed_entries.keys()), key=cmp_to_key(self.compare_ldap_dns))
+
+        for dn in sorted_dns:
+            entry = self.failed_entries[dn]
+            print("'{}':".format(dn), file=out)
+            for attr in entry.keys():
+                print('  {}:'.format(attr), file=out)
+                for val in entry[attr]:
+                    print("  - '{}'".format(val), file=out)
+
+
     # -------------------------------------------------------------------------
     def check_entry(self, dn):