[Limacute-commit] r208 - in trunk/tools/csv2ldap: . logging

jhf at projects.linpro.no jhf at projects.linpro.no
Thu Jun 21 15:09:26 CEST 2007


Author: jhf
Date: 2007-06-21 15:09:25 +0200 (Thu, 21 Jun 2007)
New Revision: 208

Modified:
   trunk/tools/csv2ldap/complex_user.csv
   trunk/tools/csv2ldap/csv.pyc
   trunk/tools/csv2ldap/csv2ldap.py
   trunk/tools/csv2ldap/logging/__init__.pyc
   trunk/tools/csv2ldap/optparse.pyc
Log:
Allow multiple aliases on command line useradd

Modified: trunk/tools/csv2ldap/complex_user.csv
===================================================================
--- trunk/tools/csv2ldap/complex_user.csv	2007-06-21 09:04:15 UTC (rev 207)
+++ trunk/tools/csv2ldap/complex_user.csv	2007-06-21 13:09:25 UTC (rev 208)
@@ -1,2 +1,2 @@
-givenName,sn,mail,title,o,ou,roomNumber,street,postOfficeBox,postalCode,l,c,telephoneNumber,facsimileTelephoneNumber,alias,alias,cyrus-userquota
-James,Bond,james at linpro.no,Agent,Linpro,Kundeservice,007,Vitaminveien 1A,,,Oslo,Norway,+47 007,+47 000,bond at linpro.no,james.bond at linpro.no,100
+givenName,sn,mail,title,o,ou,roomNumber,street,postOfficeBox,postalCode,l,c,telephoneNumber,facsimileTelephoneNumber,alias,cyrus-userquota
+James,Bond,james at linpro.no,Agent,Linpro,Kundeservice,007,Vitaminveien 1A,,,Oslo,Norway,+47 007,+47 000,"bond at linpro.no,james.bond at linpro.no",100

Modified: trunk/tools/csv2ldap/csv.pyc
===================================================================
(Binary files differ)

Modified: trunk/tools/csv2ldap/csv2ldap.py
===================================================================
--- trunk/tools/csv2ldap/csv2ldap.py	2007-06-21 09:04:15 UTC (rev 207)
+++ trunk/tools/csv2ldap/csv2ldap.py	2007-06-21 13:09:25 UTC (rev 208)
@@ -42,6 +42,7 @@
 # Helpful information
 required_attributes = ['mail','sn','givenName',]
 supported_attributes = ['alias','c','cn','cyrus-userquota','dn','facsimileTelephoneNumber','givenName','kolabHomeServer','l','mail','o','ou','postalCode','postOfficeBox','roomNumber','sn','street','telephoneNumber','title','uid','password','userPassword']
+valid_email_pattern = re.compile(r"^[-a-zA-Z0-9\.]+@[-a-zA-Z0-9]+\.[-a-zA-Z0-9\.]+$")
 
 # Helper function for option parsing
 def compile_filter(option, opt_str, value, parser):
@@ -210,6 +211,23 @@
         # Skip zero-length strings
         elif len(user[key]) == 0:
             del(user[key])
+    # Check for valid email and alias syntax
+    if user.has_key('mail'):
+        value = user['mail']
+        if not valid_email_pattern.match(value):
+            username = user['mail']
+            error("Invalid value %(value)s in mail column for user %(username)s." % vars())
+            return False
+    # Transform alias string "alias1,alias2,.." into a list [alias1,alias2,..]
+    if user.has_key('alias'):
+        aliases = []
+        for alias in user['alias'].split(','):
+            if not valid_email_pattern.match(alias):
+                username = user['mail']
+                error("Invalid value %(value)s in alias column for user %(username)s." % vars())
+                return False
+            aliases.append(alias)
+        user['alias']=aliases
     # Create uid, if not given.
     # The uid is the login name, and is usually the email address
     if not user.has_key('uid'):
@@ -232,6 +250,7 @@
         del(user['password'])
     # Ensure proper objectClass
     user['objectClass']=['top','inetOrgPerson','kolabInetOrgPerson']
+    # Transform alias string "alias1,alias2,.." into a list [alias1,alias2,..]
     # Transform values to single item lists, unless they are already a list.
     for key in user.keys():
         if type(user[key]) == type([]):

Modified: trunk/tools/csv2ldap/logging/__init__.pyc
===================================================================
(Binary files differ)

Modified: trunk/tools/csv2ldap/optparse.pyc
===================================================================
(Binary files differ)



More information about the Limacute-commit mailing list