from pathlib import Path
# Third party modules
+import yaml
# Own modules
from fb_tools.common import to_bool
from fb_tools.config import ConfigError, BaseConfiguration
-__version__ = '0.1.1'
+__version__ = '0.2.1'
LOG = logging.getLogger(__name__)
default_suffix = 'o=isp'
default_timeout = 20
max_tcp_port = (2**16 - 1)
+ default_xlations_definitions_base = 'xlations.yaml'
re_bind_dn = re.compile(r'^\s*bind[_-]?dn\s*$', re.IGNORECASE)
re_bind_pw = re.compile(r'^\s*bind[_-]?(?:pw|passwd|passsword)\s*$', re.IGNORECASE)
# -------------------------------------------------------------------------
def __init__(
self, appname=None, verbose=0, version=__version__, base_dir=None,
+ xlations_definitions_base=None,
encoding=None, config_dir=None, config_file=None, initialized=False):
self.src_server = self.default_src_server
self.suffix = self.default_suffix
self._timeout = self.default_timeout
+ self.xlations_definitions_base = self.default_xlations_definitions_base
+ self.xlations_definitions_file = None
+ self.xlations_definitions = {}
super(LDAPMigrationConfiguration, self).__init__(
appname=appname, verbose=verbose, version=version, base_dir=base_dir,
encoding=encoding, config_dir=config_dir, config_file=config_file, initialized=False,
)
+ if xlations_definitions_base:
+ self.xlations_definitions_base = xlations_definitions_base
+ self.xlations_definitions_file = self.config_dir / self.xlations_definitions_base
+
if initialized:
self.initialized = True
return res
+ # -------------------------------------------------------------------------
+ def read(self):
+ """Reading the configuration file."""
+
+ super(LDAPMigrationConfiguration, self).read(error_if_not_exists=True)
+
+ open_args = {
+ 'encoding': 'utf-8',
+ 'errors': 'surrogateescape',
+ 'mode': 'r',
+ }
+
+ if self.xlations_definitions_file.exists() and self.xlations_definitions_file.is_file():
+ LOG.debug("Reading YAML file {!r} ...".format(str(self.xlations_definitions_file)))
+ with self.xlations_definitions_file.open(**open_args) as fh:
+ self.xlations_definitions = yaml.load(fh, Loader=yaml.Loader)
+
# -------------------------------------------------------------------------
def eval_config_section(self, config, section_name):