]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Formatting Export file
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 9 Jan 2023 17:10:39 +0000 (18:10 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 9 Jan 2023 17:10:39 +0000 (18:10 +0100)
lib/pp_admintools/app/check_ldap_dn_attributes.py

index 11c36c0a87a304025ef14d6ba39f49c749e08c0d..45769d9ec531243351bd26918551047c93dee84d 100644 (file)
@@ -12,8 +12,10 @@ from __future__ import absolute_import
 import re
 import logging
 
+from functools import cmp_to_key
+
 # Third party modules
-import yaml
+import yaml
 
 # Own modules
 # from fb_tools.common import to_bool, is_sequence
@@ -31,7 +33,7 @@ from ..config.ldap import LdapConfiguration
 from .ldap import LdapAppError
 from .ldap import BaseLdapApplication
 
-__version__ = '0.3.1'
+__version__ = '0.3.2'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -188,9 +190,16 @@ class CheckLdapDnAttributesApplication(BaseLdapApplication):
                 LOG.debug(_("Writing export file {!r} ...").format(self.export_file))
                 with open(
                         self.export_file, 'wt', encoding='utf-8', errors='surrogateescape') as fh:
-                    yaml.dump(
-                        self.failed_entries.as_dict(pure=True), fh, explicit_start=True,
-                        default_flow_style=False, indent=2)
+                    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.exit(5)
 
         msg = _("Did not found any inconsistent entries.")