community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1714759 - /comdev/projects.apache.org/scripts/cronjobs/readldap.py
Date Tue, 17 Nov 2015 11:39:16 GMT
Author: sebb
Date: Tue Nov 17 11:39:16 2015
New Revision: 1714759

URL: http://svn.apache.org/viewvc?rev=1714759&view=rev
Log:
Some more fixes (still needs some work)

Modified:
    comdev/projects.apache.org/scripts/cronjobs/readldap.py

Modified: comdev/projects.apache.org/scripts/cronjobs/readldap.py
URL: http://svn.apache.org/viewvc/comdev/projects.apache.org/scripts/cronjobs/readldap.py?rev=1714759&r1=1714758&r2=1714759&view=diff
==============================================================================
--- comdev/projects.apache.org/scripts/cronjobs/readldap.py (original)
+++ comdev/projects.apache.org/scripts/cronjobs/readldap.py Tue Nov 17 11:39:16 2015
@@ -45,7 +45,7 @@ def _getPMC(cn, ts=None):
     members = []
     response = conn.response
     if not len(response) == 1:
-        raise Error("Invalid Response - only expecting a single entry")
+        raise RuntimeError("Invalid Response - only expecting a single entry")
     for c in response:
         att = c['attributes']
         created = att['createTimestamp'][0] # returned as an array of one (!?)
@@ -65,20 +65,26 @@ def _getPMC(cn, ts=None):
 def _getUnix(cn, ts=None):
     base = 'ou=groups,dc=apache,dc=org'
     filter = '(&(cn=%s)(!(modifyTimestamp<=%s)))' % (cn, ts) if ts else '(cn=%s)'
% cn
-    attributes=['memberUid','createTimestamp','modifyTimestamp','cn']
+    # Note: 1st attribute is used for the key
+    if cn == '*':
+        attributes=['cn', 'createTimestamp','modifyTimestamp']
+    else:
+        attributes=['memberUid','createTimestamp','modifyTimestamp','cn']
     success = conn.search(base, filter, attributes=attributes, search_scope=LEVEL)
     if not success:
         return success, {'base': base, 'filter': filter, 'attributes': attributes}
     members = []
     response = conn.response
-    if not len(response) == 1:
-        raise Error("Invalid Response - only expecting a single entry")
+    if not len(response) == 1 and not cn == '*':
+        raise RuntimeError("Invalid Response - only expecting a single entry")
     for c in response:
         att = c['attributes']
         created = att['createTimestamp'][0] # returned as an array of one (!?)
         modified = att['modifyTimestamp'][0]
-        members.extend(att['memberUid'])
-    return success, {'name': cn,
+        members.extend(att[attributes[0]])
+#     print(att)
+    return success, {
+            'name': cn,
             'type': 'unix',
             'roster': sorted(members),
             'created': created,
@@ -95,10 +101,9 @@ def _getPerson(uid, ts=None):
     data = {}
     response = conn.response
     if not len(response) == 1:
-        raise Error("Invalid Response - only expecting a single entry")
+        raise RuntimeError("Invalid Response - only expecting a single entry")
     for c in response:
         att = c['attributes']
-        data = {}
         for a in att:
             data[a] = att[a][0]
     return success, data
@@ -208,10 +213,10 @@ class LdapCache(object):
                 else:
                     diff = int(time.time() - getmtime(filename))
                     if diff < self.__interval:
-                        print("Recently checked: %d < %d, skip download" % (diff, self.__interval))
+                        print("Recently checked: %d < %d, skip download for %s" % (diff,
self.__interval, filename))
                         return old
                     else:
-                        print("Not recently checked: %d > %d" % (diff, self.__interval))
+                        print("Not recently checked: %d > %d (%s)" % (diff, self.__interval,
filename))
             try:
                 modified = old['modified']
             except KeyError:
@@ -257,6 +262,10 @@ class LdapCache(object):
             return {}
 
 if __name__ == '__main__':
+#     print(_getPMC('jmeter'))
+#     print(_getUnix('jmeter'))
+    print(_getUnix('*','20151113163652Z'))
+    die
     # test the code by checking group consistency
     lc = LdapCache(None)
     members = lc.getUnix('member')['roster']



Mime
View raw message