Changeset 9362
- Timestamp:
- 19 Oct 2012, 22:59:41 (12 years ago)
- Location:
- main/waeup.kofa/trunk/tools
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/tools/copy_media_files.py
r8924 r9362 28 28 ## The Ids of new students to search for in old portal. 29 29 NEW_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. 34 ID_MAP_CSV = None 35 ID_MAP_CSV = "id_mapping.csv" 30 36 31 37 ## Permissions to be set on new files/dirs. Set OWNER and/or GROUP to … … 79 85 80 86 def copy_file(file_src, file_dst): 81 create_path(os.path.dirname( dst))87 create_path(os.path.dirname(file_dst)) 82 88 print "COPY FILE: %s -> %s" % (file_src, file_dst) 83 89 shutil.copyfile(file_src, file_dst) … … 85 91 return 86 92 93 def 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 113 new_to_old_map = get_new_old_id_mapping() 87 114 removable_dirs = [] 88 115 reader = csv.DictReader(open(NEW_IDS_CSV, 'rb')) 89 116 for row in reader: 90 117 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:]) 92 119 src_folder = os.path.join(SRC_DIR, stud_id[0], stud_id) 93 120 dst_folder = os.path.join(DST_DIR, new_folder_name(stud_id), new_stud_id) -
main/waeup.kofa/trunk/tools/fix_import_file.py
r9270 r9362 36 36 import csv 37 37 import datetime 38 import os 38 39 import re 39 40 import sys … … 159 160 'session_id': 'p_session', 160 161 'type': 'r_company', 162 'old_id': 'old_id', 161 163 } 162 164 … … 177 179 } 178 180 181 # Mapping of special cases, where new id is not deductible from old id 182 # Set to `None`, if no such special cases should be considered. 183 ID_MAP_CSV = None 184 ID_MAP_CSV = "id_mapping.csv" 185 179 186 ## 180 187 ## END OF CONFIG … … 183 190 # Look for the first sequence of numbers 184 191 RE_PHONE = re.compile('[^\d]*(\d*)[^\d]*') 192 193 def get_id_mapping(): 194 """Returns a dict mapping from old (SRP) ids to new ids. 195 196 The dict is read from ID_MAP_CSV file. If this var is set to 197 ``None`` an empty dict is returned. The ID_MAP_CSV contains only 198 the student ids of those students, for which the standard method 199 (new_id=CHAR+old_id) does not work. 200 """ 201 if ID_MAP_CSV is None: 202 return {} 203 if not os.path.isfile(ID_MAP_CSV): 204 raise IOError( 205 "No such file for mapping old to new ids: %s" % ID_MAP_CSV) 206 result = dict() 207 reader = csv.DictReader(open(ID_MAP_CSV, 'rb')) 208 for row in reader: 209 result[row['student_id']] = row['new_id'] 210 return result 211 185 212 186 213 def convert_fieldnames(fieldnames): … … 201 228 """ 202 229 203 @classmethod 204 def student_id(self, value, row): 230 old_new_id_map = get_id_mapping() 231 232 @classmethod 233 def student_id(cls, value, row): 205 234 """ 'A123456' --> 'EA123456' 206 235 """ 236 value = cls.old_new_id_map.get(value, value) 207 237 if len(value) == 7: 208 238 return 'M' + value
Note: See TracChangeset for help on using the changeset viewer.