[sysadmin-bin] Move imports to the top of the file



commit b91a0454f1604e8c8d54f20436f375ab7da37ea1
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date:   Fri Nov 27 10:13:17 2020 +0100

    Move imports to the top of the file

 gnome_ldap_utils.py | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
---
diff --git a/gnome_ldap_utils.py b/gnome_ldap_utils.py
index 5941ab2..34fedf1 100755
--- a/gnome_ldap_utils.py
+++ b/gnome_ldap_utils.py
@@ -1,11 +1,12 @@
 #!/usr/bin/python3
 
+import sys
+
+import ldap
+
 class Gnome_ldap_utils:
 
     def __init__(self, LDAP_GROUP_BASE, LDAP_HOST, LDAP_USER_BASE, LDAP_USER, LDAP_PASSWORD, 
LDAP_CA_PATH='/etc/ipa/ca.crt'):
-        import ldap
-        import sys
-
         self.LDAP_GROUP_BASE = LDAP_GROUP_BASE
         self.LDAP_USER_BASE = LDAP_USER_BASE
         self.LDAP_USER = LDAP_USER
@@ -23,8 +24,6 @@ class Gnome_ldap_utils:
             sys.exit(1)
 
     def get_group_from_ldap(self, group):
-        import ldap.filter
-
         filter = ldap.filter.filter_format('(&(objectClass=groupofnames)(cn=%s))', (group, ))
         results = self.conn.search_s(self.LDAP_GROUP_BASE, ldap.SCOPE_SUBTREE, filter, ('member', ))
 
@@ -42,8 +41,6 @@ class Gnome_ldap_utils:
         return members
 
     def get_attributes_from_ldap(self, uid, attr, *attrs):
-        import ldap.filter
-
         results = []
 
         filter = ldap.filter.filter_format('(uid=%s)', (uid, ))
@@ -81,28 +78,19 @@ class Gnome_ldap_utils:
         return people
 
     def replace_ldap_password(self, userid, password):
-        import ldap
-
         replace_password = [(ldap.MOD_REPLACE, 'userPassword', password)]
         self.conn.modify_s('uid=%s,%s' % (userid, self.LDAP_USER_BASE), replace_password)
 
     def add_user_to_ldap_group(self, userid, group):
-        import ldap
-
         add_members = [(ldap.MOD_ADD, 'member', 'uid=%s,%s' % (userid, self.LDAP_USER_BASE))]
         self.conn.modify_s('cn=%s,%s' % (group, self.LDAP_GROUP_BASE), add_members)
 
     def remove_user_from_ldap_group(self, userid, group):
-        import ldap
-
         uid_query = "uid={},{}".format(userid, self.LDAP_USER_BASE).encode("utf-8")
         remove_members = [(ldap.MOD_DELETE, 'member', uid_query)]
         self.conn.modify_s('cn=%s,%s' % (group, self.LDAP_GROUP_BASE), remove_members)
 
     def add_or_update_description(self, userid, comment, add=False, update=False):
-        import sys
-        import ldap
-
         if add and not update:
             update_comment = [(ldap.MOD_ADD, 'description', comment)]
             self.conn.modify_s('uid=%s,%s' % (userid, self.LDAP_USER_BASE), update_comment)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]