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;
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;
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 $$
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;
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)
Then, create their card.
"""
- print """
+ return """
BEGIN;
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)
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
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)
finally:
con.unbind()
+ print(update_existing_users())
+ print(insert_new_users())
+
# vim: et:ts=4:sw=4:tw=78: