def __init__(self, db, logger, cfg_file=None, debug=0, studieprogs_file=None, emne_info_file=None, ou_perspective=None): self._logger = logger self.debug = debug self.db = db self.co = Factory.get('Constants')(db) self.disk_tool = DiskTool(db, self.co) if not ou_perspective: self.ou_perspective = self.co.perspective_fs else: self.ou_perspective = ou_perspective self.pc = ProfileConfig.Config(self, logger, debug=debug, cfg_file=cfg_file) logger.debug(self.pc.debug_dump()) self.studieprogramkode2info = {} for sp in StudentInfo.StudieprogDefParser( studieprogs_file=studieprogs_file): self.studieprogramkode2info[sp['studieprogramkode']] = sp self.emnekode2info = {} for emne in StudentInfo.EmneDefParser(emne_info_file): self.emnekode2info[emne['emnekode']] = emne
def _init_emne2sko(self, emnefile): self.emne2sko = {} for e in StudentInfo.EmneDefParser(emnefile): self.emne2sko[e['emnekode']] = self._get_sko( e, 'faknr_reglement', 'instituttnr_reglement', 'gruppenr_reglement')
def main(): global gen_groups, group global old_aff, include_delete global _add_res, _rem_res opts, args = getopt.getopt(sys.argv[1:], 'p:s:e:gdfh', [ 'person-file=', 'studieprogram-file=', 'emne-file=', 'generate-groups', 'include-delete', 'help' ]) personfile = DEFAULT_PERSONFILE studieprogramfile = DEFAULT_STUDIEPROGRAMFILE emnefile = DEFAULT_EMNEFILE for opt, val in opts: if opt in ('-p', '--person-file'): personfile = val elif opt in ('-s', '--studieprogram-file'): studieprogramfile = val elif opt in ('-e', '--emne-file'): emnefile = val elif opt in ('-g', '--generate-groups'): gen_groups = True elif opt in ('-d', '--include-delete'): include_delete = True elif opt in ('-h', '--help'): usage() else: print "Unknown argument: %s" % opt usage(1) if "system_fs" not in cereconf.SYSTEM_LOOKUP_ORDER: print "Check your config, SYSTEM_LOOKUP_ORDER is wrong!" sys.exit(1) logger.info("Started") if getattr(cereconf, "ENABLE_MKTIME_WORKAROUND", 0) == 1: logger.warn("Warning: ENABLE_MKTIME_WORKAROUND is set") # Initialize reservation group if gen_groups: _add_res, _rem_res = init_reservation_group() # Build cache data for s in StudentInfo.StudieprogDefParser(studieprogramfile): studieprog2sko[s['studieprogramkode']] = _get_sko( s, 'faknr_studieansv', 'instituttnr_studieansv', 'gruppenr_studieansv') for e in StudentInfo.EmneDefParser(emnefile): emne2sko[e['emnekode']] = _get_sko(e, 'faknr_reglement', 'instituttnr_reglement', 'gruppenr_reglement') if include_delete: old_aff = _load_cere_aff() # create fnr2person_id mapping, always using fnr from FS when set person = Factory.get('Person')(db) for p in person.list_external_ids(id_type=co.externalid_fodselsnr): if co.system_fs == p['source_system']: fnr2person_id[p['external_id']] = p['entity_id'] elif p['external_id'] not in fnr2person_id: fnr2person_id[p['external_id']] = p['entity_id'] # Start import StudentInfo.StudentInfoParser(personfile, process_person_callback, logger) # Clean old affs if include_delete: rem_old_aff() db.commit() # note that process_person_callback does commit as well logger.info("Found %d persons without name." % no_name) logger.info("Completed")
def main(): global verbose, ou, logger, fnr2person_id, gen_groups, group global old_aff, include_delete, no_name verbose = 0 include_delete = False logger = Factory.get_logger("cronjob") opts, args = getopt.getopt(sys.argv[1:], 'vp:s:e:gdf', [ 'verbose', 'person-file=', 'studieprogram-file=', 'emne-file=', 'generate-groups', 'include-delete', ]) personfile = default_personfile studieprogramfile = default_studieprogramfile emnefile = default_emnefile for opt, val in opts: if opt in ('-v', '--verbose'): verbose += 1 elif opt in ('-p', '--person-file'): personfile = val elif opt in ('-s', '--studieprogram-file'): studieprogramfile = val elif opt in ('-e', '--emne-file'): emnefile = val elif opt in ('-g', '--generate-groups'): gen_groups = True elif opt in ('-d', '--include-delete'): include_delete = True if "system_fs" not in cereconf.SYSTEM_LOOKUP_ORDER: print "Check your config, SYSTEM_LOOKUP_ORDER is wrong!" sys.exit(1) logger.info("Started") ou = Factory.get('OU')(db) group = Factory.get('Group')(db) try: group.find_by_name(group_name) except Errors.NotFoundError: group.clear() ac = Factory.get('Account')(db) ac.find_by_name(cereconf.INITIAL_ACCOUNTNAME) group.populate(ac.entity_id, co.group_visibility_internal, group_name, group_desc) group.write_db() if getattr(cereconf, "ENABLE_MKTIME_WORKAROUND", 0) == 1: logger.warn("Warning: ENABLE_MKTIME_WORKAROUND is set") for s in StudentInfo.StudieprogDefParser(studieprogramfile): studieprog2sko[s['studieprogramkode']] = \ _get_sko(s, 'faknr_studieansv', 'instituttnr_studieansv', 'gruppenr_studieansv') for e in StudentInfo.EmneDefParser(emnefile): emne2sko[e['emnekode']] = \ _get_sko(e, 'faknr_reglement', 'instituttnr_reglement', 'gruppenr_reglement') # create fnr2person_id mapping, always using fnr from FS when set person = Factory.get('Person')(db) if include_delete: old_aff = _load_cere_aff() fnr2person_id = {} for p in person.list_external_ids(id_type=co.externalid_fodselsnr): if co.system_fs == p['source_system']: fnr2person_id[p['external_id']] = p['entity_id'] elif not fnr2person_id.has_key(p['external_id']): fnr2person_id[p['external_id']] = p['entity_id'] StudentInfo.StudentInfoParser(personfile, process_person_callback, logger) if include_delete: rem_old_aff() db.commit() logger.info("Found %d persons without name." % no_name) logger.info("Completed")