def main(): global LT, xml, verbose personfile = None stedfile = None sid = None user = None fnr_update = None try: opts, args = getopt.getopt(sys.argv[1:], 'vs:u:f:', ['verbose', 'sid=', 'sted-file=', 'person-file=', 'fnr-update=']) except getopt.GetoptError: usage(1) for opt, val in opts: if opt in ('-v', '--verbose'): pass # not currently used elif opt in ('-s', '--sid'): sid = val elif opt in ('-u',): user = val elif opt in ('--sted-file',): stedfile = val elif opt in ('--person-file',): personfile = val elif opt in ('-f', '--fnr-update'): fnr_update = val # fi # od if user is None or sid is None: usage(1) db = Database.connect(user=user, service=sid, DB_driver=cereconf.DB_DRIVER_ORACLE) LT = LT(db) xml = XMLHelper() if stedfile is not None: get_sted_info(stedfile) # fi if personfile is not None: get_person_info(personfile) # fi if fnr_update is not None: get_fnr_update_info(fnr_update)
def main(): global logger logger = Factory.get_logger("cronjob") logger.info("Starting LT sync") try: options, rest = getopt.getopt(sys.argv[1:], "deuh", [ "help", "email", "uname", "dryrun", ]) except getopt.GetoptError: usage() sys.exit(1) # yrt global dryrun dryrun = False email = False uname = False for option, value in options: if option in ("-d", "--dryrun"): dryrun = True elif option in ("-h", "--help"): usage() sys.exit(2) elif option in ("-e", "--email"): logger.debug("Running sync for email") email = True elif option in ("-u", "--uname"): logger.debug("Running sync for uname") uname = True # fi # od lt = LT( Database.connect(user="******", service="LTPROD.uio.no", DB_driver=cereconf.DB_DRIVER_ORACLE)) db = Factory.get("Database")() person = Factory.get("Person")(db) const = Factory.get("Constants")(db) logger.debug("Fetching all people from LT") lt_people = lt.GetAllPersons() logger.debug("done") if email: synchronize_attribute(person.getdict_external_id2mailaddr, lt_people, lt.GetAllPersonsUregEmail, lt.UpdatePriMailAddr, lt.DeletePriMailAddr, lt.InsertPriMailAddr, const, lt) # fi if uname: synchronize_attribute(person.getdict_external_id2primary_account, lt_people, lt.GetAllPersonsUregUser, lt.UpdatePriUser, lt.DeletePriUser, lt.InsertPriUser, const, lt)
elif opt in ('--fs-db-service', ): fs_database = val elif opt in ('--lt-db-user', ): lt_user = val elif opt in ('--lt-db-service', ): lt_database = val elif opt in ('--dryrun', ): dryrun = True if not opts: # enforce atleast one argument to avoid accidential runs usage(1) fs = FS(user=fs_user, database=fs_database) lt_db = Database.connect(user=lt_user, service=lt_database, DB_driver=cereconf.DB_DRIVER_ORACLE) lt = LT(lt_db) if dryrun: fs.db.commit = fs.db.rollback update_lt() def usage(exitcode=0): print """Usage: lt2fsPerson [opsjoner] --fs-db-user name: connect with given database username (FS) --fs-db-service name: connect to given database (FS) --lt-db-user name: connect with given database username (LT) --lt-db-service name: connect to given database (LT) --dryrun : rollback changes to db """ sys.exit(exitcode)