Ignore:
Timestamp:
19 Oct 2012, 22:59:41 (12 years ago)
Author:
uli
Message:

Update tools to allow new ids in imports. Support for new import col 'old_id'.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/tools/copy_media_files.py

    r8924 r9362  
    2828## The Ids of new students to search for in old portal.
    2929NEW_IDS_CSV = "StudentIds.csv"
     30
     31## The ids of students that will will get a complete new number, not
     32## an updated one. Must contain a mapping of old ids to new ids.
     33## If no such update should be performed, please set the constant to None.
     34ID_MAP_CSV = None
     35ID_MAP_CSV = "id_mapping.csv"
    3036
    3137## Permissions to be set on new files/dirs. Set OWNER and/or GROUP to
     
    7985
    8086def copy_file(file_src, file_dst):
    81     create_path(os.path.dirname(dst))
     87    create_path(os.path.dirname(file_dst))
    8288    print "COPY FILE: %s -> %s" % (file_src, file_dst)
    8389    shutil.copyfile(file_src, file_dst)
     
    8591    return
    8692
     93def get_new_old_id_mapping():
     94    """Returns a dict mapping from _new_ ids to old (SRP) ids.
     95
     96    The dict is read from ID_MAP_CSV file. If this var is set to
     97    ``None`` an empty dict is returned. The ID_MAP_CSV contains only
     98    the student ids of those students, for which the standard method
     99    (new_id=CHAR+old_id) does not work.
     100    """
     101    if ID_MAP_CSV is None:
     102        return {}
     103    if not os.path.isfile(ID_MAP_CSV):
     104        raise IOError(
     105            "No such file for mapping new to old ids: %s" % ID_MAP_CSV)
     106    result = dict()
     107    reader = csv.DictReader(open(ID_MAP_CSV, 'rb'))
     108    for row in reader:
     109        result[row['new_id']] = row['student_id']
     110    return result
     111
     112# special ids not handled in common way
     113new_to_old_map = get_new_old_id_mapping()
    87114removable_dirs = []
    88115reader = csv.DictReader(open(NEW_IDS_CSV, 'rb'))
    89116for row in reader:
    90117    new_stud_id = row['student_id']
    91     stud_id = new_stud_id[1:]
     118    stud_id = new_to_old_map.get(new_stud_id[1:], new_stud_id[1:])
    92119    src_folder = os.path.join(SRC_DIR, stud_id[0], stud_id)
    93120    dst_folder = os.path.join(DST_DIR, new_folder_name(stud_id), new_stud_id)
Note: See TracChangeset for help on using the changeset viewer.