from .config import LDAPMigrationConfiguration
-__version__ = '0.5.0'
+__version__ = '0.5.1'
LOG = logging.getLogger(__name__)
CFG_BASENAME = 'ldap-migration.ini'
self.target = None
self.tmp_dir = None
self.all_dns_file = None
+ self.structural_dns_file = None
self.object_classes = {}
self.attribute_types = {}
+ self.dns = {}
super(LDAPMigrationApplication, self).__init__(
appname=appname, verbose=verbose, version=version, base_dir=base_dir,
self.tmp_dir = self.base_dir / 'tmp'
self.all_dns_file = self.tmp_dir / 'all-dns.txt'
+ self.structural_dns_file = self.tmp_dir / 'structural-dns.txt'
self.initialized = True
# -------------------------------------------------------------------------
return ','.join(parts)
+ # -------------------------------------------------------------------------
+ def register_dn_tokens(self, dn):
+
+ tokens = reversed(self.re_dn_split.split(dn))
+ cur_hash = self.dns
+ for token in tokens:
+ if token not in cur_hash:
+ cur_hash[token] = {}
+ cur_hash = cur_hash[token]
+
# -------------------------------------------------------------------------
def get_all_dns(self):
- LOG.info("Collecting all source SNs and writing them into {!r} ...".format(
+ LOG.info("Collecting all source DNs and writing them into {!r} ...".format(
str(self.all_dns_file)))
open_args = {
new_dn = self.mangle_dn(old_dn)
if self.verbose > 2:
LOG.debug("Found DN {!r}.".format(old_dn))
+ self.register_dn_tokens(old_dn)
fh.write("{old} => {new}\n".format(old=old_dn, new=new_dn))
LOG.info("Found {nr} items in subtree of {sfx!r}.".format(
nr=item_count, sfx=self.config.suffix))
+ if self.verbose > 3:
+ LOG.debug("Registred DN tokens:\n{}".format(pp(self.dns)))
+
+ # -------------------------------------------------------------------------
+ def get_structural_dns(self):
+
+ LOG.info("Collecting all structural and writing them into {!r} ...".format(
+ str(self.structural_dns_file)))
+
+ cur_hash = self.dns
+ cur_tokens = []
+
+ open_args = {
+ 'encoding': 'utf-8',
+ 'errors': 'surrogateescape',
+ 'mode': 'w',
+ }
+
+ with self.structural_dns_file.open(**open_args) as fh:
+ self._get_structural_dns(fh, cur_hash, cur_tokens)
+
+ # TODO
+ # Noch viele viele Fehler!
+
+ # -------------------------------------------------------------------------
+ def _get_structural_dns(self, fh, cur_hash, cur_tokens):
+
+ if not cur_hash.keys():
+ return
+
+ if cur_tokens:
+ my_dn = ','.join(reversed(cur_tokens))
+ LOG.debug("Found stuctural DN: {!r}".format(my_dn))
+ fh.write("{}\n".format(my_dn))
+
+ for key in sorted(cur_hash.keys(), key=str.lower):
+ sub_tokens = copy.copy(cur_tokens)
+ sub_tokens.append(key)
+ self._get_structural_dns(fh, cur_hash[key], sub_tokens)
# -------------------------------------------------------------------------
def _run(self):
self.discover_target_schema()
self.check_tmp_dir()
self.get_all_dns()
+ self.get_structural_dns()
LOG.info("Sleeping ...")
time.sleep(2)
finally: