1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- def archivers(self):
- """
- This method load the configuration and instantiate all the Source and
- Destination objects needed for each archiver
- """
- self.load()
- if self._archivers:
- return self._archivers
- archiver_sections = [
- a for a in self.sections() if str(a).startswith('archiver:')
- ]
- def args_factory(section):
- """
- Generic function that takes a section from configuration file
- and return arguments that are passed to source or destination
- factory
- """
- args_factory = {
- k: v if k not in BOOLEAN_OPTIONS else self.parser.getboolean(
- section, k)
- for (k, v) in self.parser.items(section)
- }
- args_factory['name'] = re.sub('^(src|dst):', '', section)
- args_factory['dry_run'] = self.dry_run
- args_factory['conf'] = self
- logging.debug(
- "'%s' factory parameters: %s", args_factory['name'], {
- k: v if k != 'password' else '***********'
- for (k, v) in args_factory.items()
- })
- return args_factory
- # Instanciate archivers:
- # One archiver is bascally a process of archiving
- # One archiver got one source and at least one destination
- # It means we have a total of source*count(destination)
- # processes to run per archiver
- for archiver in archiver_sections:
- # If enable: 0 in archiver config ignore it
- if not self.parser.getboolean(archiver, 'enable'):
- logging.info("Archiver %s is disabled, ignoring it", archiver)
- continue
- # src and dst sections are comma, semicolon, or carriage return
- # separated name
- src_sections = [
- 'src:{}'.format(i.strip())
- for i in re.split(r'\n|,|;', self.parser[archiver]['src'])
- ]
- # destination is not mandatory
- # usefull to just delete data from DB
- dst_sections = [
- 'dst:{}'.format(i.strip()) for i in re.split(
- r'\n|,|;', self.parser[archiver].get('dst', '')) if i
- ]
- for src_section in src_sections:
- src_args_factory = args_factory(src_section)
- src = src_factory(**src_args_factory)
- destinations = []
- for dst_section in dst_sections:
- dst_args_factory = args_factory(dst_section)
- dst_args_factory['source'] = src
- dst = dst_factory(**dst_args_factory)
- destinations.append(dst)
- self._archivers.append(
- Archiver(name=re.sub('^archiver:', '', archiver),
- src=src,
- dst=destinations,
- conf=self))
- return self._archivers
|