LDAP patron load: handle more errors more gracefully
authorDan Scott <dscott@laurentian.ca>
Fri, 7 Oct 2011 17:16:09 +0000 (13:16 -0400)
committerDan Scott <dscott@laurentian.ca>
Tue, 7 May 2013 18:57:10 +0000 (14:57 -0400)
It's possible for users in LDAP to not have email; instead of absolutely
dying, just warn and move on to the next user.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
tools/patron-load/ldap_osrf_sync

index 2bab8b6..8b2626d 100755 (executable)
@@ -82,13 +82,13 @@ class User:
 
         if 'mail' not in self.ldap_atts:
             print >> sys.stderr, 'mail not found for %s' % self.cname
-            return None
+            return None
 
         # Strip leading/ending whitespace; LDAP data can be dirty
 
         # Using email for username deliberately here
-        self.usrname = self._simple_map('mail').lower()
-        self.email = self._simple_map('mail').lower()
+        self.usrname = (self._simple_map('mail') or '').lower()
+        self.email = (self._simple_map('mail') or '').lower()
         self.family_name = self._simple_map('sn')
         self.ident_type, self.ident_value = self.get_identity()
         self.home_ou = self.get_home_ou()
@@ -165,6 +165,7 @@ class User:
             'faculty': 11,
             'staff': 15,
             'proxy': None,
+            'retired': None,
             'affiliate': 15
         }
 
@@ -173,6 +174,7 @@ class User:
         else:
             print >> sys.stderr, "Affiliation '%s' not mapped to a profile " \
                 "for user %s" % (affiliation, self.usrname)
+        return None
 
     def get_home_ou(self):
         """
@@ -308,6 +310,9 @@ def find_ldap_users(con, ldap_filter, attributes, auth):
                 if res:
                     update_ldap_barcode(con, user)
             if ARGS.push_barcode:
+                if user.barcode:
+                    continue
+
                 try:
                     uid = find_evergreen_user(auth, user)
                 except AttributeError:
@@ -399,6 +404,9 @@ def create_evergreen_user(auth, user):
         print >> sys.stderr, "No profile set for %s" % user.usrname
         return
 
+    if user.barcode is not None:
+        return
+
     found = find_evergreen_user(auth, user)
     if found:
         print("Found: %s" % user.usrname)