]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Making the linter happy
authorFrank Brehm <frank@brehm-online.com>
Thu, 20 Oct 2022 08:47:05 +0000 (10:47 +0200)
committerFrank Brehm <frank@brehm-online.com>
Thu, 20 Oct 2022 08:47:05 +0000 (10:47 +0200)
lib/pp_admintools/app/ldap.py

index 60dd375abed10121d0d4246579eebda8581fd8b0..0b186ca375da4b2770ca46e04d413ed2c492266b 100644 (file)
@@ -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):