]> Frank Brehm's Git Trees - pixelpark/ldap-migration.git/commitdiff
Bugfixing
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 3 Dec 2020 17:30:00 +0000 (18:30 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 3 Dec 2020 17:30:00 +0000 (18:30 +0100)
lib/ldap_migration/__init__.py

index a3dbf987984d44a7a498f87b8e0efc8870f016a3..830b0229df23c51ec1b6be57307fbf1d2ee4a9e8 100644 (file)
@@ -45,7 +45,7 @@ from .config import LDAPMigrationConfiguration
 from .idict import CaseInsensitiveDict
 from .istringset import CaseInsensitiveStringSet
 
-__version__ = '0.8.3'
+__version__ = '0.8.4'
 
 LOG = logging.getLogger(__name__)
 CFG_BASENAME = 'ldap-migration.ini'
@@ -904,6 +904,9 @@ class LDAPMigrationApplication(BaseApplication):
         if cur_hash is None:
             cur_hash = self.dns
 
+        if self.verbose > 4:
+            LOG.debug("Trying to register DN {!r} ...".format(dn))
+
         iter_hash = cur_hash
         tokens = []
         for token in reversed(self.re_dn_split.split(dn)):
@@ -919,6 +922,9 @@ class LDAPMigrationApplication(BaseApplication):
                 iter_hash['childs'][token]['childs'] = CaseInsensitiveDict()
             iter_hash = iter_hash['childs'][token]
             if not len(tokens):
+                if self.verbose > 3:
+                    LOG.debug("Registred DN {dn!r} with path {p}.".format(
+                        dn=dn, p=tokens_copy))
                 iter_hash['dn'] = dn
                 iter_hash['path'] = tokens_copy
                 iter_hash['object_classes'] = object_classes
@@ -936,6 +942,7 @@ class LDAPMigrationApplication(BaseApplication):
         }
         sfilter = '(objectClass=*)'
         attrs = ['objectClass']
+        self.all_entries = []
 
         item_count = 0
 
@@ -952,6 +959,7 @@ class LDAPMigrationApplication(BaseApplication):
                 new_dn = self.mangle_dn(old_dn)
                 if self.verbose > 2:
                     LOG.debug("Found DN {!r}.".format(old_dn))
+                self.all_entries.append(old_dn)
                 self.register_dn_tokens(old_dn, entry['attributes']['objectClass'], self.dns)
                 fh.write("{old} => {new}\n".format(old=old_dn, new=new_dn))
                 if self.limit:
@@ -963,26 +971,6 @@ class LDAPMigrationApplication(BaseApplication):
         if self.verbose > 4:
             LOG.debug("Registred DN tokens:\n{}".format(pp(self.dns.as_dict())))
 
-    # -------------------------------------------------------------------------
-    def get_entry_list(self):
-
-        print()
-        LOG.info("Getting an ordered list of all source entries ...")
-
-        self.all_entries = []
-        cur_hash = self.dns
-        self._get_entries(cur_hash)
-
-    # -------------------------------------------------------------------------
-    def _get_entries(cur_hash):
-
-        if 'dn' in cur_hash:
-            self.struct_entries.append(cur_hash['dn'])
-
-        if 'childs' in cur_hash:
-            for key in cur_hash['childs'].keys():
-                self._get_entries(fh, cur_hash['childs'][key])
-
     # -------------------------------------------------------------------------
     def get_structural_dns(self):
 
@@ -1116,14 +1104,18 @@ class LDAPMigrationApplication(BaseApplication):
         self.count_added = 0
         self.count_modified = 0
 
-        try:
-            self._migrate_entries(
-                self.dns, fh=fh, force=False, is_root=True,
-                with_group_entries=False, with_acl=False)
-        except (ReadLDAPItemError, WriteLDAPItemError) as e:
-            msg = "Abort migration: " + str(e)
-            LOG.error(msg)
-            return False
+        for src_dn in self.all_entries:
+            try:
+                self.migrate_entry(
+                    src_dn, fh=fh, force=False, with_acl=False, migrate_if_group=False)
+            except WriteLDAPItemError as e:
+                msg = "Abort migration: " + str(e)
+                LOG.error(msg)
+                return False
+            except ReadLDAPItemError as e:
+                msg = "Could not get source item: " + str(e)
+                LOG.error(msg)
+                continue
 
         print()
         count_groups = 0
@@ -1442,13 +1434,15 @@ class LDAPMigrationApplication(BaseApplication):
                 return True
             return False
 
-        # Both parameters are values
+        # Both parameters are arays
         first_array = []
-        for val in sorted(first, key=str.lower):
+        for val in first:
             first_array.append(str(val).lower())
+        first_array.sort()
         second_array = []
-        for val in sorted(second, key=str.lower):
+        for val in second:
             second_array.append(str(val).lower())
+        second_array.sort()
 
         if first_array == second_array:
             return True
@@ -1466,7 +1460,6 @@ class LDAPMigrationApplication(BaseApplication):
             self.discover_target_schema()
             self.check_tmp_dir()
             self.get_all_dns()
-            self.get_entry_list()
             self.get_structural_dns()
             self.migrate_entries()
             if self.verbose > 1: