From: Frank Brehm Date: Thu, 26 Nov 2020 11:51:13 +0000 (+0100) Subject: Cleaning code X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=14d86756dcca71afde0f203c5ba9faa424ea8e7b;p=pixelpark%2Fldap-migration.git Cleaning code --- diff --git a/lib/ldap_migration/__init__.py b/lib/ldap_migration/__init__.py index 4a9171f..0295c31 100644 --- a/lib/ldap_migration/__init__.py +++ b/lib/ldap_migration/__init__.py @@ -40,7 +40,7 @@ from .config import LDAPMigrationConfiguration from .idict import CaseInsensitiveDict from .istringset import CaseInsensitiveStringSet -__version__ = '0.6.9' +__version__ = '0.6.10' LOG = logging.getLogger(__name__) CFG_BASENAME = 'ldap-migration.ini' @@ -1136,55 +1136,60 @@ class LDAPMigrationApplication(BaseApplication): if not is_root: src_dn = cur_hash['dn'] - LOG.debug("Migrating source DN {dn!r}.".format(dn=src_dn)) + if self.migrate_entry(src_dn, with_acl=with_acl): + if wait: + time.sleep(wait) - tgt_dn = self.mangle_dn(src_dn) + for key in cur_hash['childs'].keys(): + self._migrate_entries(cur_hash['childs'][key], is_root=False, with_acl=with_acl) + # ------------------------------------------------------------------------- + def migrate_entry(self, src_dn, with_acl=False): - rev_dn = self.get_reverse_dn(tgt_dn) - if rev_dn in self.migrated_entries: - LOG.debug("Entry {!r} is already migrated.".format(tgt_dn)) - else: + tgt_dn = self.mangle_dn(src_dn) + rev_dn = self.get_reverse_dn(tgt_dn) + LOG.debug("Migrating source DN {sdn!r} -> {tdn!r}.".format( + sdn=src_dn, tdn=tgt_dn)) - src_entry = self.get_source_item(src_dn, tgt_dn, with_acl=with_acl) - tgt_entry = self.get_target_item(tgt_dn, with_acl=with_acl) + if rev_dn in self.migrated_entries: + LOG.debug("Entry {!r} is already migrated.".format(tgt_dn)) + return False - if tgt_entry: + src_entry = self.get_source_item(src_dn, tgt_dn, with_acl=with_acl) + tgt_entry = self.get_target_item(tgt_dn, with_acl=with_acl) - changes = self.generate_modify_data(src_entry, tgt_entry, src_dn, tgt_dn) - if changes: - if self.verbose: - LOG.info("Updating target entry {!r} ...".format(tgt_dn)) - if self.verbose > 2: - msg = "Changes on target entry {tdn!r}:\n{ch}".format( - tdn=tgt_dn, ch=pp(changes)) - LOG.debug(msg) - self.count_modified += 1 - if not self.simulate: - self.target.modify(tgt_dn, changes) - self.migrated_entries[rev_dn] = tgt_dn - if wait: - time.sleep(wait) + if tgt_entry: - else: - (tgt_obj_classes, tgt_entry) = self.generate_target_entry(src_entry, src_dn, tgt_dn) - if self.verbose: - LOG.info("Creating target entry {!r} ...".format(tgt_dn)) - if self.verbose > 2: - msg = "Generated entry for target DN {dn!r}:\n" - msg += "object classes: {oc}\n" - msg += "entry: {en}" - msg = msg.format(dn=tgt_dn, oc=tgt_obj_classes, en=tgt_entry) - LOG.debug(msg) - self.count_added += 1 - if not self.simulate: - self.target.add(tgt_dn, object_class=tgt_obj_classes, attributes=tgt_entry) - self.migrated_entries[rev_dn] = tgt_dn - if wait: - time.sleep(wait) + changes = self.generate_modify_data(src_entry, tgt_entry, src_dn, tgt_dn) + if changes: + if self.verbose: + LOG.info("Updating target entry {!r} ...".format(tgt_dn)) + if self.verbose > 2: + msg = "Changes on target entry {tdn!r}:\n{ch}".format( + tdn=tgt_dn, ch=pp(changes)) + LOG.debug(msg) + self.count_modified += 1 + if not self.simulate: + self.target.modify(tgt_dn, changes) + self.migrated_entries[rev_dn] = tgt_dn + return True + else: + return False - for key in cur_hash['childs'].keys(): - self._migrate_entries(cur_hash['childs'][key], is_root=False, with_acl=with_acl) + (tgt_obj_classes, tgt_entry) = self.generate_target_entry(src_entry, src_dn, tgt_dn) + if self.verbose: + LOG.info("Creating target entry {!r} ...".format(tgt_dn)) + if self.verbose > 2: + msg = "Generated entry for target DN {dn!r}:\n" + msg += "object classes: {oc}\n" + msg += "entry: {en}" + msg = msg.format(dn=tgt_dn, oc=tgt_obj_classes, en=tgt_entry) + LOG.debug(msg) + self.count_added += 1 + if not self.simulate: + self.target.add(tgt_dn, object_class=tgt_obj_classes, attributes=tgt_entry) + self.migrated_entries[rev_dn] = tgt_dn + return True # ------------------------------------------------------------------------- def compare_values(self, first, second):