[sysadmin-bin] Polish the foundation-operations.py script a bit



commit 3ec91d7809d7e90bce54394c90f43bf093510588
Author: Andrea Veri <av gnome org>
Date:   Mon Oct 6 16:24:41 2014 +0200

    Polish the foundation-operations.py script a bit

 membership/foundation-operations.py |   42 ++++++++++++++--------------------
 1 files changed, 17 insertions(+), 25 deletions(-)
---
diff --git a/membership/foundation-operations.py b/membership/foundation-operations.py
index ed2fd54..b51e3fe 100755
--- a/membership/foundation-operations.py
+++ b/membership/foundation-operations.py
@@ -50,14 +50,18 @@ except ldap.LDAPError, e:
 def _parse_members_from_group(group):
 
     filter = ldap.filter.filter_format('(&(objectClass=posixgroup)(cn=%s))', (group, ))
-    results = l.search_s(LDAP_GROUP_BASE, ldap.SCOPE_SUBTREE, filter, ('memberUid', ))
+    results = l.search_s(LDAP_GROUP_BASE, ldap.SCOPE_SUBTREE, filter, ('member', ))
 
     members = set()
-    for entry in results:
-        id = entry[0]
-        attr = entry[1]
 
-        members.update(attr['memberUid'])
+    for _, attr in results:
+        for userid in attr['member']:
+            splitentry = userid.split(',')
+            singleentry = splitentry[0]
+            splitteduid = singleentry.split('=')
+            uid = splitteduid[1]
+
+            members.add(uid)
 
     return members
 
@@ -70,13 +74,10 @@ def _get_attributes_from_ldap(uid, attr):
     filter = ldap.filter.filter_format('(uid=%s)', (uid, ))
     results = l.search_s(LDAP_USER_BASE, ldap.SCOPE_SUBTREE, filter, ('uid', attr, ))
 
-    for entry in results:
-        userid = entry[1]['uid']
-        attribute = entry[1][attr]
-
-        foundationmembership = dict(zip(userid, attribute))
-
-        return foundationmembership
+    if len(results) > 0:
+        return results[0][1][attr][0]
+    else:
+        return None
 
 def _get_foundation_fields_from_ldap():
     foundationmembers = _get_foundation_members()
@@ -87,25 +88,17 @@ def _get_foundation_fields_from_ldap():
         mail_attr = _get_attributes_from_ldap(member,'mail')
         common_name_attr = _get_attributes_from_ldap(member, 'cn')
 
-        if last_renewed_on_attr[member] == TODAY and first_added_attr == TODAY:
-           send_form_letters(new_member_form_letter, mail_attr[member], common_name_attr[member])
-        elif last_renewed_on_attr[member] == TODAY:
-           send_form_letters(renewal_form_letter, mail_attr[member], common_name_attr[member])
+        if last_renewed_on_attr == TODAY and first_added_attr == TODAY:
+           send_form_letters(new_member_form_letter, mail_attr, common_name_attr)
+        elif last_renewed_on_attr == TODAY:
+           send_form_letters(renewal_form_letter, mail_attr, common_name_attr)
         else:
            pass
 
-def sync_user_to_mailusers_memberuid(member):
-        add_members = [(ldap.MOD_ADD, 'memberUid', member)]
-        l.modify_s('cn=mailusers,cn=groups,cn=accounts,dc=gnome,dc=org', add_members)
-
 def sync_user_to_mailusers_member(member):
         add_members = [(ldap.MOD_ADD, 'member', 'uid=%s,cn=users,cn=accounts,dc=gnome,dc=org' % (member))]
         l.modify_s('cn=mailusers,cn=groups,cn=accounts,dc=gnome,dc=org', add_members)
 
-def remove_user_from_foundation_memberuid(member):
-        remove_members = [(ldap.MOD_DELETE, 'memberUid', member)]
-        l.modify_s('cn=foundation,cn=groups,cn=accounts,dc=gnome,dc=org', remove_members)
-
 def remove_user_from_foundation_member(member):
         remove_members = [(ldap.MOD_DELETE, 'member', 'uid=%s,cn=users,cn=accounts,dc=gnome,dc=org' % 
(member))]
         l.modify_s('cn=foundation,cn=groups,cn=accounts,dc=gnome,dc=org', remove_members)
@@ -116,7 +109,6 @@ def _sync_foundation_with_mailusers():
 
     for member in foundationmembers:
         if member not in mailusers:
-            sync_user_to_mailusers_memberuid(member)
             sync_user_to_mailusers_member(member)
 
 def remove_expired_memberships_from_foundation():


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