From: Frank Brehm Date: Thu, 4 May 2017 16:40:14 +0000 (+0200) Subject: Applying flake8 rules X-Git-Tag: 0.1.2~175^2 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=7fe9bb8ac618c8ba199905b882a14c436d7da400;p=pixelpark%2Fadmin-tools.git Applying flake8 rules --- diff --git a/barracuda-sync b/barracuda-sync index 6cb3770..2d5fe69 100755 --- a/barracuda-sync +++ b/barracuda-sync @@ -15,8 +15,6 @@ if sys.argv[0] != '' and sys.argv[0] != '-c': if os.path.exists(os.path.join(cur_dir, 'pp_lib')): sys.path.insert(0, os.path.abspath(cur_dir)) -from pp_lib.common import pp - from pp_lib.barracuda_sync_app import PpBarracudaSyncApp log = logging.getLogger(__name__) diff --git a/pp_lib/barracuda_sync_app.py b/pp_lib/barracuda_sync_app.py index 4d0d83b..217c40e 100644 --- a/pp_lib/barracuda_sync_app.py +++ b/pp_lib/barracuda_sync_app.py @@ -9,42 +9,28 @@ from __future__ import absolute_import # Standard modules -import sys import os import logging import logging.config import re -import traceback import textwrap import copy -import shutil import shlex -import stat # Third party modules import six -import ldap3 - -from ldap3 import ObjectDef, AttrDef, Reader, Writer -from ldap3 import BASE, LEVEL, SUBTREE - -from ldap3.core.exceptions import LDAPKeyError +from ldap3 import ObjectDef +from ldap3 import BASE, LEVEL, SUBTREE # noqa # Own modules -from .global_version import __version__ as __global_version__ - -from .errors import FunctionNotImplementedError, PpAppError - -from .common import pp, terminal_can_colors, to_bytes, to_bool - -from .merge import merge_structure +from .common import pp from .ldap_app import PpLdapAppError, PpLdapApplication from .mailaddress import MailAddress -__version__ = '0.4.2' +__version__ = '0.4.3' LOG = logging.getLogger(__name__) @@ -157,7 +143,6 @@ class PpBarracudaSyncApp(PpLdapApplication): super(PpBarracudaSyncApp, self).perform_config() - aliases_files = None virtaliases_files = None for section_name in self.cfg.keys(): @@ -165,7 +150,7 @@ class PpBarracudaSyncApp(PpLdapApplication): if self.verbose > 2: LOG.debug("Checking config section {!r} ...".format(section_name)) - if section_name.lower() not in ('barracuda-sync', 'barracuda_sync', 'barracudasync') : + if section_name.lower() not in ('barracuda-sync', 'barracuda_sync', 'barracudasync'): continue section = self.cfg[section_name] @@ -177,29 +162,11 @@ class PpBarracudaSyncApp(PpLdapApplication): self._init_postfix_dir(section['postfix_dir']) if 'virtaliases_files' in section: - v = section['virtaliases_files'] - files = shlex.split(v) - if files: - if virtaliases_files is None: - virtaliases_files = [] - for f in files: - if f not in virtaliases_files: - virtaliases_files.append(f) + virtaliases_files = self._cfg_virtaliases_files( + section['virtaliases_files'], virtaliases_files) if 'ignore_aliases' in section: - v = section['ignore_aliases'] - aliases = shlex.split(v) - if aliases: - for alias in aliases: - if alias.startswith('-'): - alias = alias[1:] - if alias == '': - continue - if alias in self.ignore_aliases: - self.ignore_aliases.remove(alias) - elif alias not in self.ignore_aliases: - self.ignore_aliases.append(alias) - + self._cfg_ignore_aliases(section['ignore_aliases']) if 'base_dn' in section: v = section['base_dn'].strip() @@ -216,6 +183,38 @@ class PpBarracudaSyncApp(PpLdapApplication): self._init_virtaliases_files(virtaliases_files) + # ------------------------------------------------------------------------- + def _cfg_virtaliases_files(self, value, virtaliases_files): + + ret = None + if virtaliases_files is not None: + ret = copy.copy(virtaliases_files) + + files = shlex.split(value) + if files: + if ret is None: + ret = [] + for f in files: + if f not in ret: + ret.append(f) + + return ret + + # ------------------------------------------------------------------------- + def _cfg_ignore_aliases(self, value): + + aliases = shlex.split(value) + if aliases: + for alias in aliases: + if alias.startswith('-'): + alias = alias[1:] + if alias == '': + continue + if alias in self.ignore_aliases: + self.ignore_aliases.remove(alias) + elif alias not in self.ignore_aliases: + self.ignore_aliases.append(alias) + # ------------------------------------------------------------------------- def _init_virtaliases_files(self, virtaliases_files):