From: Frank Brehm Date: Tue, 23 May 2023 15:14:24 +0000 (+0200) Subject: Collecting virtual aliases files X-Git-Tag: 0.9.0~1^2~39 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=5bfb8e49bfbda789020614ca236a083702d0e105;p=pixelpark%2Fpp-admin-tools.git Collecting virtual aliases files --- diff --git a/lib/pp_admintools/app/barracuda_sync.py b/lib/pp_admintools/app/barracuda_sync.py index 80185c4..7d02519 100644 --- a/lib/pp_admintools/app/barracuda_sync.py +++ b/lib/pp_admintools/app/barracuda_sync.py @@ -16,6 +16,7 @@ import re 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 @@ -25,7 +26,7 @@ from fb_tools.xlate import format_list from .ldap import BaseLdapApplication from ..xlate import XLATOR -__version__ = '0.6.3' +__version__ = '0.6.4' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -98,7 +99,6 @@ class BarracudaSyncApp(BaseLdapApplication): 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 = [] @@ -165,8 +165,8 @@ class BarracudaSyncApp(BaseLdapApplication): 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): @@ -232,7 +232,10 @@ class BarracudaSyncApp(BaseLdapApplication): 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) @@ -242,12 +245,52 @@ class BarracudaSyncApp(BaseLdapApplication): # ------------------------------------------------------------------------- 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):