from pathlib import Path
# Third party modules
+from fb_tools.common import pp
from fb_tools.argparse_actions import DirectoryOptionAction
from fb_tools.handler import BaseHandler
from fb_tools.multi_config import DEFAULT_ENCODING
from .ldap import BaseLdapApplication
from ..xlate import XLATOR
-__version__ = '0.6.3'
+__version__ = '0.6.4'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
self.postmap_command = Path('/sbin') / self.default_postmap_command
self.lookup_table_types = []
- self.virtaliases_files = []
self.existing_aliases = []
self.ldap_aliases = []
self.aliases_to_create = []
super(BarracudaSyncApp, self).post_init()
self._check_postfix()
+ self._init_virtaliases_files()
self._check_virtaliases_files()
- # self._init_ignore_aliases_res()
# -------------------------------------------------------------------------
def _check_postfix(self):
LOG.error(msg)
self.exit(6)
- if self.args.hashtype not in self.usable_postfix_hashtypes:
+ if self.verbose > 1:
+ LOG.debug(_("Candidate for lookup table type: {!r}.").format(self.postfix_db_hashtype))
+
+ if self.postfix_db_hashtype not in self.usable_postfix_hashtypes:
msg = _(
'The lookup table type {!r} cannot be used to get all '
'database elements.').format(self.postfix_db_hashtype)
# -------------------------------------------------------------------------
def _init_virtaliases_files(self):
"""Collect all files used as database for virtual aliases."""
- pass
+ LOG.debug(_('Collecting all available virtual aliases table files ...'))
+
+ va_files = []
+ basenames = ['virtual', 'virtual-alias', 'virtual-aliases',
+ 'virtualalias', 'virtualaliases']
+
+ if self.args.basename:
+ for basename in self.args.basename:
+ if basename not in basenames:
+ basenames.append(basename)
+
+ for va_file in self.default_virtaliases_files:
+ if va_file.exists() and va_file.is_file():
+ if self.verbose > 1:
+ LOG.debug(_("Using virtual aliases file: {!r}").format(str(va_file)))
+ va_files.append(va_file)
+
+ for maps_dir in (self.postfix_config_dir, self.postfix_maps_dir):
+ if not maps_dir.exists():
+ LOG.debug(_("Directory {!r} does not exists.").format(str(maps_dir)))
+ continue
+ if not maps_dir.is_dir():
+ LOG.debug(_("Path {!r} exists, but is not a directory.").format(str(maps_dir)))
+ continue
+
+ for basename in basenames:
+ va_file = maps_dir / basename
+ if va_file.exists() and va_file.is_file():
+ va_file = va_file.resolve()
+ if va_file not in va_files:
+ if self.verbose > 1:
+ LOG.debug(_("Using virtual aliases file: {!r}").format(str(va_file)))
+ va_files.append(va_file)
+
+ if not len(va_files):
+ LOG.error(_("Did not found any virtual aliases files."))
+ self.exit(6)
+
+ LOG.debug(_("Found virtual aliases files:") + '\n' + pp(
+ list(map(lambda x: str(x), va_files))))
+ self.virtaliases_files = va_files
# -------------------------------------------------------------------------
def _check_virtaliases_files(self):
"""Check existence of given ."""
- LOG.debug(_('Checking postfix commands and lookup table types ...'))
+ LOG.debug(_('Checking all available virtual aliases table files ...'))
# -------------------------------------------------------------------------
def _run(self):