from .idict import CaseInsensitiveDict
from .istringset import CaseInsensitiveStringSet
-__version__ = '0.8.6'
+__version__ = '0.8.7'
LOG = logging.getLogger(__name__)
CFG_BASENAME = 'ldap-migration.ini'
self.source = None
self.tgt_server = None
self.target = None
- self.tmp_dir = None
+ self.log_dir = None
self.all_dns_file = None
self.structural_dns_file = None
self.migrated_file = None
+ self.general_logfile = None
self.lap = 0
self.total_count = 0
description=description, initialized=False,
)
- 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.migrated_file = self.tmp_dir / 'migrated-entries.txt'
self.initialized = True
# -------------------------------------------------------------------------
return formatter
+ # -------------------------------------------------------------------------
+ def _get_logfile_formatter(self):
+
+ format_str = '[%(asctime)s]: '
+ format_str += self.appname + ': '
+ if self.verbose > 1:
+ format_str += '%(name)s(%(lineno)d) %(funcName)s() '
+ else:
+ format_str += '%(name)s '
+ format_str += '%(levelname)s - %(message)s'
+
+ return logging.Formatter(format_str)
+
# -------------------------------------------------------------------------
def init_logging(self):
"""
"""
log_level = logging.INFO
- if self.verbose:
- log_level = logging.DEBUG
- elif self.quiet:
+ if self.quiet:
log_level = logging.WARNING
root_logger = logging.getLogger()
else:
paramiko_logger.setLevel(logging.INFO)
+ lf_formatter = self._get_logfile_formatter()
+ lh_file = logging.FileHandler(
+ str(self.general_logfile), mode='a', encoding='utf-8', delay=True)
+ if self.verbose:
+ lh_file.setLevel(logging.DEBUG)
+ else:
+ lh_file.setLevel(logging.INFO)
+ lh_file.setFormatter(lf_formatter)
+ root_logger.addHandler(lh_file)
+
return
# -------------------------------------------------------------------------
self.initialized = False
+ file_timestamp = datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
+
+ self.log_dir = self.base_dir / 'log'
+ self.check_log_dir()
+
+ self.all_dns_file = self.log_dir / 'all-dns.{}.txt'.format(file_timestamp)
+ self.structural_dns_file = self.log_dir / 'structural-dns.{}.txt'.format(file_timestamp)
+ self.migrated_file = self.log_dir / 'migrated-entries.{}.txt'.format(file_timestamp)
+ self.general_logfile = self.log_dir / 'migration.{}.log'.format(file_timestamp)
+
self.init_logging()
self.perform_arg_parser()
self.integer_attribute_types.as_list()))
# -------------------------------------------------------------------------
- def check_tmp_dir(self):
- """Checking existence of temp-dir and creating it, if necessary."""
+ def check_log_dir(self):
+ """Checking existence of logging-dir and creating it, if necessary."""
- LOG.debug("Checking temporary directory {!r} ...".format(str(self.tmp_dir)))
+ LOG.debug("Checking logging directory {!r} ...".format(str(self.log_dir)))
- if self.tmp_dir.exists():
- if self.tmp_dir.is_dir():
- LOG.debug("Temporary directory {!r} is already existing.".format(
- str(self.tmp_dir)))
+ if self.log_dir.exists():
+ if self.log_dir.is_dir():
+ LOG.debug("Logging directory {!r} is already existing.".format(
+ str(self.log_dir)))
else:
msg = "Path {!r} is already existing, but is not a directory.".format(
- str(self.tmp_dir))
+ str(self.log_dir))
raise CommonLDAPMigrationError(msg)
else:
- LOG.info("Creating temporary directory {!r} ...".format(str(self.tmp_dir)))
- self.tmp_dir.mkdir(mode=0o755, exist_ok=True)
+ LOG.info("Creating logging directory {!r} ...".format(str(self.log_dir)))
+ self.log_dir.mkdir(mode=0o755, exist_ok=True)
mod2check = os.R_OK | os.W_OK | os.X_OK
euid = False
if os.access in os.supports_effective_ids:
euid = True
- if not os.access(str(self.tmp_dir), mod2check, effective_ids=euid):
- msg = "Insufficient access rights to temporary directory {!r}.".format(
- str(self.tmp_dir))
+ if not os.access(str(self.log_dir), mod2check, effective_ids=euid):
+ msg = "Insufficient access rights to logging directory {!r}.".format(
+ str(self.log_dir))
raise CommonLDAPMigrationError(msg)
if self.verbose > 1:
- LOG.debug("Access to {!r} is okay.".format(str(self.tmp_dir)))
+ LOG.debug("Access to {!r} is okay.".format(str(self.log_dir)))
# -------------------------------------------------------------------------
def lookup_for_attrtype(self, attrtype, silent=True):
self.connect_source()
self.connect_target()
self.discover_target_schema()
- self.check_tmp_dir()
self.get_all_dns()
self.get_structural_dns()
self.migrate_entries()