[sysadmin-bin] Do not build the dictionary by using zip but parse the results directly from search_s



commit 420d3f30e615ab559900551c86b02623311f651b
Author: Andrea Veri <av gnome org>
Date:   Fri Oct 3 20:24:36 2014 +0200

    Do not build the dictionary by using zip but parse the results directly from search_s

 reset-my-password.py |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
---
diff --git a/reset-my-password.py b/reset-my-password.py
index b75f5a1..7ee2859 100755
--- a/reset-my-password.py
+++ b/reset-my-password.py
@@ -41,13 +41,10 @@ def _get_attributes_from_ldap(userid, attr):
     filter = ldap.filter.filter_format('(uid=%s)', (userid, ))
     results = l.search_s(LDAP_USER_BASE, ldap.SCOPE_SUBTREE, filter, ('uid', attr, ))
 
-    for entry in results:
-        username = entry[1]['uid']
-        attribute = entry[1][attr]
-
-        userslist = dict(zip(username, attribute))
-
-        return userslist
+    if len(results) > 0:
+        return results[0][1][attr][0]
+    else:
+        return None
 
 
 def gen_passwd(length=12, chars=string.letters + string.digits):
@@ -99,7 +96,7 @@ def update_password(userid):
     l.modify_s('uid=%s,cn=users,cn=accounts,dc=gnome,dc=org' % userid, replace_password)
 
 
-    send_password_to_user(getattr_name[userid], getattr_mail[userid], newpassword['userPassword'])
+    send_password_to_user(getattr_name, getattr_mail, newpassword['userPassword'])
 
 
 def send_password_to_user(name, email, password):


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