Beispiel #1
0
def main():
    global verbose, ou, db, co, logger, gen_groups, group, \
        old_aff, include_delete, no_name
    verbose = 0
    gen_groups = False
    include_delete = False
    logger = Factory.get_logger("cronjob")
    opts, args = getopt.getopt(sys.argv[1:], 'vp:s:gdf', [
        'verbose', 'person-file=', 'studieprogram-file=',
        'generate-groups', 'include-delete', ])

    personfile = default_personfile
    studieprogramfile = default_studieprogramfile
    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 ('-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")
    db = Factory.get('Database')()
    db.cl_init(change_program='import_FS')
    ou = Factory.get('OU')(db)
    co = Factory.get('Constants')(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')

    if include_delete:
        old_aff = _load_cere_aff()
    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")
Beispiel #2
0
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")
Beispiel #3
0
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:o:gdf', [
        'verbose',
        'person-file=',
        'studieprogram-file=',
        'ou-file=',
        'generate-groups',
        'include-delete',
    ])

    personfile = default_personfile
    studieprogramfile = default_studieprogramfile
    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 ('-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')

    # 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")
Beispiel #4
0
def main():
    # parsing
    parser = argparse.ArgumentParser()
    parser = add_commit_args(parser, default=True)
    parser.add_argument(
        '-v', '--verbose',
        action='count')
    parser.add_argument(
        '-p', '--person-file',
        dest='personfile',
        default=pj(cereconf.FS_DATA_DIR, "merged_persons.xml"))
    parser.add_argument(
        '-s', '--studieprogram-file',
        dest='studieprogramfile',
        default=pj(cereconf.FS_DATA_DIR, "studieprog.xml"))
    parser.add_argument(
        '-e', '--emne-file',
        dest='emnefile',
        default=pj(cereconf.FS_DATA_DIR, "emner.xml"))
    parser.add_argument(
        '-g', '--generate-groups',
        dest='gen_groups',
        action='store_true')
    parser.add_argument(
        '-d', '--include-delete',
        dest='include_delete',
        action='store_true')

    Cerebrum.logutils.options.install_subparser(parser)
    args = parser.parse_args()
    Cerebrum.logutils.autoconf('cronjob', args)

    source = 'system_sap'
    rules = [
        ('fagperson', ('_arbeide', '_hjemsted', '_besok_adr')),
        ('aktiv', ('_semadr', '_hjemsted', None)),
        ('emnestud', ('_semadr', '_hjemsted', None)),
        ('evu', ('_job', '_hjem', None)),
        ('drgrad', ('_semadr', '_hjemsted', None)),
        ('privatist_emne', ('_semadr', '_hjemsted', None)),
        ('privatist_studieprogram', ('_semadr', '_hjemsted', None)),
        ('opptak', (None, '_hjemsted', None)),
        ]
    rule_map = {
        'aktiv': 'opptak'
    }
    adr_map = {
        '_arbeide': ('adrlin1_arbeide', 'adrlin2_arbeide', 'adrlin3_arbeide',
                     'postnr_arbeide', 'adresseland_arbeide'),
        '_hjemsted': ('adrlin1_hjemsted', 'adrlin2_hjemsted',
                      'adrlin3_hjemsted', 'postnr_hjemsted',
                      'adresseland_hjemsted'),
        '_semadr': ('adrlin1_semadr', 'adrlin2_semadr', 'adrlin3_semadr',
                    'postnr_semadr', 'adresseland_semadr'),
        '_job': ('adrlin1_job', 'adrlin2_job', 'adrlin3_job', 'postnr_job',
                 'adresseland_job'),
        '_hjem': ('adrlin1_hjem', 'adrlin2_hjem', 'adrlin3_hjem',
                  'postnr_hjem', 'adresseland_hjem'),
        '_besok_adr': ('institusjonsnr', 'faknr', 'instituttnr', 'gruppenr')
        }

    fs_importer = FsImporterUio(args.gen_groups,
                                args.include_delete, args.commit,
                                args.studieprogramfile, source, rules, adr_map,
                                args.emnefile, rule_map)

    StudentInfo.StudentInfoParser(args.personfile,
                                  fs_importer.process_person_callback,
                                  logger)

    if args.include_delete:
        fs_importer.rem_old_aff()

    if args.commit:
        fs_importer.db.commit()
        logger.info('Changes were committed to the database')
    else:
        fs_importer.db.rollback()
        logger.info('Dry run. Changes to the database were rolled back')

    logger.info("Found %d persons without name.", fs_importer.no_name)
    logger.info("Completed")
Beispiel #5
0
 def start_student_callbacks(self, student_file, callback_func):
     StudentInfo.StudentInfoParser(student_file, callback_func,
                                   self._logger)
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser()
    parser = add_commit_args(parser, default=True)
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        help='Be extra verbose in the logs.')
    parser.add_argument('-p',
                        '--person-file',
                        dest='personfile',
                        default=pj(cereconf.FS_DATA_DIR, "merged_persons.xml"),
                        help='Specify where the person file is located.')
    parser.add_argument(
        '-s',
        '--studieprogram-file',
        dest='studieprogramfile',
        default=pj(cereconf.FS_DATA_DIR, "studieprogrammer.xml"),
        help='Specify where the study programs file is located.')
    parser.add_argument('-e',
                        '--emne-file',
                        dest='emnefile',
                        default=pj(cereconf.FS_DATA_DIR, "emner.xml"),
                        help='Specify where the course file is located.')
    parser.add_argument(
        '-g',
        '--generate-groups',
        dest='gen_groups',
        action='store_true',
        help="""If set, the group for accept for being published at uio.no
             gets populated with the students.""")
    parser.add_argument(
        '-d',
        '--include-delete',
        dest='include_delete',
        action='store_true',
        help="""If set, old person affiliations are deleted from the students
             that should not have this anymore.""")

    Cerebrum.logutils.options.install_subparser(parser)
    args = parser.parse_args()
    Cerebrum.logutils.autoconf('cronjob', args)

    source = 'system_fs'
    rules = [
        ('fagperson', ('_arbeide', '_hjemsted', '_besok_adr')),
        ('aktiv', ('_semadr', '_hjemsted', None)),
        ('emnestud', ('_semadr', '_hjemsted', None)),
        ('evu', ('_job', '_hjem', None)),
        ('drgrad', ('_semadr', '_hjemsted', None)),
        ('privatist_emne', ('_semadr', '_hjemsted', None)),
        ('privatist_studieprogram', ('_semadr', '_hjemsted', None)),
        ('opptak', (None, '_hjemsted', None)),
    ]
    rule_map = {'aktiv': 'opptak'}
    adr_map = {
        '_arbeide': ('adrlin1_arbeide', 'adrlin2_arbeide', 'adrlin3_arbeide',
                     'postnr_arbeide', 'adresseland_arbeide'),
        '_hjemsted':
        ('adrlin1_hjemsted', 'adrlin2_hjemsted', 'adrlin3_hjemsted',
         'postnr_hjemsted', 'adresseland_hjemsted'),
        '_semadr': ('adrlin1_semadr', 'adrlin2_semadr', 'adrlin3_semadr',
                    'postnr_semadr', 'adresseland_semadr'),
        '_job': ('adrlin1_job', 'adrlin2_job', 'adrlin3_job', 'postnr_job',
                 'adresseland_job'),
        '_hjem': ('adrlin1_hjem', 'adrlin2_hjem', 'adrlin3_hjem',
                  'postnr_hjem', 'adresseland_hjem'),
        '_besok_adr': ('institusjonsnr', 'faknr', 'instituttnr', 'gruppenr')
    }

    fsimporter = FsImporterUit(args.gen_groups, args.include_delete,
                               args.commit, args.studieprogramfile, source,
                               rules, adr_map, args.emnefile, rule_map)
    StudentInfo.StudentInfoParser(args.personfile,
                                  fsimporter.process_person_callback, logger)
    if args.include_delete:
        fsimporter.rem_old_aff()

    if args.commit:
        fsimporter.db.commit()
        logger.info('Changes were committed to the database')
    else:
        fsimporter.db.rollback()
        logger.info('Dry run. Changes to the database were rolled back')

    logger.info("Found %d persons without name." % fsimporter.no_name)
    logger.info("Completed")