]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Applying flake8 rules to pp_lib/dnsui_users.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 6 Feb 2018 14:49:15 +0000 (15:49 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 6 Feb 2018 14:49:15 +0000 (15:49 +0100)
pp_lib/dnsui_users.py

index aec44b069c8c49fcd78fe22eabedab550945ee60..767d7888f03baa030f6b43dbed0437fb9ff989ed 100644 (file)
@@ -14,6 +14,7 @@ import logging.config
 import textwrap
 import socket
 import re
+import traceback
 
 # Third party modules
 # from ldap3 import ObjectDef, AttrDef, Reader, Writer
@@ -25,7 +26,7 @@ from .common import pp
 
 from .ldap_app import PpLdapAppError, PpLdapApplication
 
-__version__ = '0.4.3'
+__version__ = '0.4.4'
 LOG = logging.getLogger(__name__)
 
 
@@ -117,7 +118,7 @@ class DnsuiUsersApp(PpLdapApplication):
             LOG.debug("Evaluating config section {n!r}:\n{s}".format(
                 n=section_name, s=pp(section)))
 
-        if not 'admin_group' in section:
+        if 'admin_group' not in section:
             return
 
         admin_group = str(section['admin_group']).strip()
@@ -147,7 +148,7 @@ class DnsuiUsersApp(PpLdapApplication):
                     section['host'], section_name))
             else:
                 try:
-                    _ = socket.getaddrinfo(host, 5432, proto=socket.IPPROTO_TCP)
+                    _ = socket.getaddrinfo(host, 5432, proto=socket.IPPROTO_TCP)            # noqa
                 except socket.gaierror as e:
                     msg = 'Invalid hostname {!r} in configuration section {!r}: {}'.format(
                         section['host'], section_name, e)
@@ -165,7 +166,7 @@ class DnsuiUsersApp(PpLdapApplication):
                     raise ValueError("port number must be less than {}".format((2 ** 16)))
             except (ValueError, TypeError) as e:
                 msg = 'Invalid port number {!r} in configuration section {!r}: {}'.format(
-                    section['port'],section_name, e)
+                    section['port'], section_name, e)
                 LOG.error(msg)
                 self.config_has_errors = True
             else:
@@ -196,7 +197,7 @@ class DnsuiUsersApp(PpLdapApplication):
 
         self.connect_db()
 
-     # -------------------------------------------------------------------------
+    # -------------------------------------------------------------------------
     def connect_db(self):
 
         result = None
@@ -255,14 +256,15 @@ class DnsuiUsersApp(PpLdapApplication):
 
         self.admin_user_dns = []
 
-        query_filter = ('(&(|(objectclass=groupOfUniqueNames)(objectclass=groupOfURLs))'
-            '({}))').format(self.admin_group)
+        query_filter = (
+            '(&(|(objectclass=groupOfUniqueNames)(objectclass=groupOfURLs))({}))').format(
+                self.admin_group)
         LOG.debug("Query filter: {!r}".format(query_filter))
 
         group = ObjectDef(['objectclass', 'groupOfURLs'])
         group += ['cn', 'memberURL', 'uniqueMember']
 
-        group_entries =  self.ldap_search_subtree(group, query_filter)
+        group_entries = self.ldap_search_subtree(group, query_filter)
         if self.verbose > 1:
             LOG.debug("Found {} LDAP entries.".format(len(group_entries)))
 
@@ -450,7 +452,7 @@ class DnsuiUsersApp(PpLdapApplication):
                 '(&(objectclass=posixAccount)(objectclass=shadowAccount)'
                 '(uid={}))').format(uid)
             if self.verbose > 2:
-                 LOG.debug("Query filter: {!r}".format(query_filter))
+                LOG.debug("Query filter: {!r}".format(query_filter))
 
             entries = self.ldap_search_subtree(person, query_filter)
             if self.verbose > 2:
@@ -493,8 +495,9 @@ class DnsuiUsersApp(PpLdapApplication):
                         n=db_user['name'], u=uid))
             else:
                 if db_user['active'] != 0:
-                    LOG.warn("DB user {n!r} ({u}) does not exists anymore, will be dectivated.".format(
-                        n=db_user['name'], u=uid))
+                    LOG.warn(
+                        "DB user {n!r} ({u}) does not exists anymore, will be dectivated.".format(
+                            n=db_user['name'], u=uid))
                     self.db_users_deactivate.append(db_id)
                 else:
                     LOG.debug("User {n!r} ({u}) is already dectivated.".format(
@@ -548,7 +551,9 @@ class DnsuiUsersApp(PpLdapApplication):
 
             for db_user in self.users_to_update:
 
-                #LOG.warn("Updating user {n!r} ({u}) ...".format(n=db_user['name'], u=db_user['uid']))
+                # LOG.warn(
+                #     "Updating user {n!r} ({u}) ...".format(
+                #         n=db_user['name'], u=db_user['uid']))
                 msg = "Udating user db id {}:".format(db_user['id'])
 
                 sql = 'UPDATE public.user SET'