Changeset 9362 for main/waeup.kofa/trunk/tools/fix_import_file.py
- Timestamp:
- 19 Oct 2012, 22:59:41 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.