From 0ee9aa8abbcb7accefe6e847988652da1617de27 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 20 Oct 2022 10:47:05 +0200 Subject: [PATCH] Making the linter happy --- lib/pp_admintools/app/ldap.py | 51 ++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/pp_admintools/app/ldap.py b/lib/pp_admintools/app/ldap.py index 60dd375..0b186ca 100644 --- a/lib/pp_admintools/app/ldap.py +++ b/lib/pp_admintools/app/ldap.py @@ -51,7 +51,7 @@ from ..config.ldap import LdapConnectionInfo, LdapConfiguration # rom ..config.ldap import DEFAULT_PORT_LDAP, DEFAULT_PORT_LDAPS from ..config.ldap import DEFAULT_TIMEOUT -__version__ = '0.8.1' +__version__ = '0.8.2' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -336,7 +336,7 @@ class BaseLdapApplication(BaseDPXApplication): } help_default_inst = _( - "If not given, then the instance {!r} will be used.").format('default') + "If not given, then the instance {!r} will be used.").format('default') help_single = _( "The LDAP instance (LDAP cluster) from configuration, " @@ -348,7 +348,7 @@ class BaseLdapApplication(BaseDPXApplication): "then all found LDAP instances except {default!r} are used. " "It is alo possible to give the value {val_list!r}, then all configured " "LDAP instances are shown, and the application is exiting.").format( - val_all='all', val_list='list', default='default') + val_all='all', val_list='list', default='default') if self.use_multiple_ldap_connections: if self.apply_default_ldap_instance_if_not_given: @@ -492,7 +492,7 @@ class BaseLdapApplication(BaseDPXApplication): msg = _("Used filter:") + ' ' + format_list(show_filter) LOG.debug(msg) - instances = [] + filtered_instances = [] for inst in self.cfg.ldap_connection.keys(): if inst == 'default': continue @@ -509,31 +509,34 @@ class BaseLdapApplication(BaseDPXApplication): if has_sync_source: if instance.sync_source is None: continue - instances.append(inst.lower()) - - if len(self.ldap_instances) == 1 and self.ldap_instances[0].lower() == 'all': - self.ldap_instances = instances + filtered_instances.append(inst.lower()) - else: + self._validate_given_instances(filtered_instances) - if 'default' in self.cfg.ldap_connection: - if self.apply_default_ldap_instance_if_not_given: - instances.insert(0, 'default') + if self.verbose > 1: + LOG.debug(_("LDAP instances to use:") + ' ' + pp(self.ldap_instances)) - all_ok = True - for given_inst in self.ldap_instances: - if given_inst not in instances: - msg = _( - "LDAP instance {!r} not found in configuration or is not usable.").format( - given_inst) - LOG.error(msg) - all_ok = False + # ------------------------------------------------------------------------- + def _validate_given_instances(self, filtered_instances): - if not all_ok: - self.exit(1) + if len(self.ldap_instances) == 1 and self.ldap_instances[0].lower() == 'all': + self.ldap_instances = filtered_instances + return - if self.verbose > 1: - LOG.debug(_("LDAP instances to use:") + ' ' + pp(self.ldap_instances)) + if 'default' in self.cfg.ldap_connection: + if self.apply_default_ldap_instance_if_not_given: + filtered_instances.insert(0, 'default') + + all_ok = True + for given_inst in self.ldap_instances: + if given_inst not in filtered_instances: + msg = _("LDAP instance {!r} not found in configuration or is not usable.").format( + given_inst) + LOG.error(msg) + all_ok = False + + if not all_ok: + self.exit(1) # ------------------------------------------------------------------------- def _init_default_connection(self): -- 2.39.5