From: Dan Scott Date: Wed, 31 Aug 2011 20:42:39 +0000 (-0400) Subject: Fix filter error, improve key existence test X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5b64cbc1b98257bf4ad5b22717a9d538edba47bb;p=contrib%2FConifer.git Fix filter error, improve key existence test Signed-off-by: Dan Scott --- diff --git a/tools/patron-load/ldap_sync b/tools/patron-load/ldap_sync index 216250f98f..43cecce263 100644 --- a/tools/patron-load/ldap_sync +++ b/tools/patron-load/ldap_sync @@ -110,7 +110,7 @@ def database_barcode_to_datatel(): Define a PostgreSQL function for generating Colleague ID from barcode """ - print """CREATE OR REPLACE FUNCTION evergreen.barcode_to_datatel(TEXT) RETURNS TEXT AS $$ + return """CREATE OR REPLACE FUNCTION evergreen.barcode_to_datatel(TEXT) RETURNS TEXT AS $$ use strict; use warnings; @@ -130,7 +130,7 @@ def database_mod10(): Define a PostgreSQL function for generating mod10 check digits """ - print """CREATE OR REPLACE FUNCTION evergreen.mod10(TEXT) RETURNS TEXT AS $$ + return """CREATE OR REPLACE FUNCTION evergreen.mod10(TEXT) RETURNS TEXT AS $$ use strict; use warnings; @@ -175,7 +175,7 @@ def generate_lu_barcode(): our user. """ - print """ + return """ CREATE SEQUENCE evergreen.lu_barcode START 200000; CREATE OR REPLACE FUNCTION evergreen.lu_update_barcode(usr_id INT) RETURNS TEXT AS $$ @@ -215,7 +215,7 @@ def create_staging_table(): Create a staging table for creating or updating user accounts """ - print """ + return """ DROP TABLE IF EXISTS scratchpad.usr_staging; CREATE TABLE scratchpad.usr_staging (usrname TEXT, email TEXT, family_name TEXT, first_given_name TEXT, ident_value TEXT, lang TEXT, affiliation TEXT, profile INT, home_ou INT, status TEXT); COPY scratchpad.usr_staging (usrname, email, family_name, first_given_name, ident_value, lang, affiliation) FROM STDIN; @@ -232,7 +232,7 @@ def update_existing_users(): Note, be careful with names until we see what LDAP does with middle names. """ - print """ + return """ BEGIN; UPDATE actor.usr SET ident_type = 2, ident_value = ( SELECT barcode_to_datatel(barcode) @@ -290,7 +290,7 @@ def insert_new_users(): Then, create their card. """ - print """ + return """ BEGIN; @@ -329,7 +329,7 @@ def search_for_students(con, attributes, create_date): base_dn = 'o=lul' search_scope = ldap.SCOPE_SUBTREE filter = '(&(objectclass=lulEduPerson))' - filter = '(&(objectclass=lulEduPerson)(lulPrimaryAffiliation=*)(createTimestamp>=%s000000Z)' % create_date + filter = '(&(objectclass=lulEduPerson)(lulPrimaryAffiliation=*)(createTimestamp>=%s000000Z))' % create_date try: result_id = con.search(base_dn, search_scope, filter, attributes) @@ -355,8 +355,16 @@ def insert_into_staging(result_data): family_name = result_data[0][1]['sn'] given_name = result_data[0][1]['givenName'] datatel = result_data[0][1]['lulColleagueId'] - lang = result_data[0][1]['preferredLanguage'] or r'\N' - affiliation = result_data[0][1]['lulPrimaryAffiliation'] or r'\N' + + if 'preferredLanguage' in result_data[0][1]: + lang = result_data[0][1]['preferredLanguage'] + else: + lang = r'\N' + + if 'lulPrimaryAffiliation' in result_data[0][1]: + affiliation = result_data[0][1]['lulPrimaryAffiliation'] + else: + affiliation = r'\N' print "%s\t%s\t%s\t%s\t%s\t%s" % ( usrname, family_name, given_name, datatel, lang, affiliation @@ -381,6 +389,11 @@ if __name__ == '__main__': con = ldap.initialize(luauth.hostname) con.set_option(ldap.OPT_REFERRALS, 0) + print(database_barcode_to_datatel()) + print(database_mod10()) + print(generate_lu_barcode()) + print(create_staging_table()) + try: attributes = ['lulPrimaryAffiliation', 'cn', 'mail', 'givenName', 'sn', 'lulColleagueId', 'preferredLanguage'] con.simple_bind_s(luauth.dn, luauth.pw) @@ -395,4 +408,7 @@ if __name__ == '__main__': finally: con.unbind() + print(update_existing_users()) + print(insert_new_users()) + # vim: et:ts=4:sw=4:tw=78: