Changeset 4877 for waeup/trunk
- Timestamp:
- 23 Jan 2010, 07:53:55 (15 years ago)
- Location:
- waeup/trunk/src/waeup/utils
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/trunk/src/waeup/utils/batching.py
r4870 r4877 210 210 fd.close() 211 211 return 212 213 def writeFailedRow(self, writer, row, warnings): 214 """Write a row with error messages to error CSV. 215 216 If warnings is a list of strings, they will be concatenated. 217 """ 218 error_col = warnings 219 if isinstance(warnings, list): 220 error_col = ' / '.join(warnings) 221 row['--ERRORS--'] = error_col 222 writer.writerow(row) 223 return 212 224 213 225 def doImport(self, path, headerfields, mode='create', user='Unknown'): … … 223 235 failed_headers = [x for x in mapping.values() 224 236 if x != '--IGNORE--'] 237 failed_headers.append('--ERRORS--') 225 238 failed_writer = csv.DictWriter(open(failed_path, 'wb'), 226 239 failed_headers) … … 237 250 if len(conv_warnings): 238 251 warnings[num] = ', '.join(conv_warnings) 239 failed_writer.writerow(string_row) 252 self.writeFailedRow(failed_writer, string_row, conv_warnings) 253 #failed_writer.writerow(string_row) 240 254 continue 241 255 … … 243 257 if not self.parentsExist(row, site): 244 258 warnings[num] = "Not all parents do exist yet. Skipping" 245 failed_writer.writerow(string_row) 259 self.writeFailedRow( 260 failed_writer, string_row, 261 "Not all parents do exist yet. Skipping") 246 262 continue 247 263 if self.entryExists(row, site): 248 264 warnings[num] = 'This object already exists. Skipping.' 249 failed_writer.writerow(string_row) 265 self.writeFailedRow( 266 failed_writer, string_row, 267 "This object already exists. Skipping.") 250 268 continue 251 269 obj = self.callFactory() … … 256 274 if not self.entryExists(row, site): 257 275 warnings[num] = "Cannot remove: no such entry." 258 failed_writer.writerow(string_row) 276 self.writeFailedRow( 277 failed_writer, string_row, 278 "Cannot remove: no such entry.") 259 279 continue 260 280 self.delEntry(row, site) … … 263 283 if obj is None: 264 284 warnings[num] = "Cannot update: no such entry." 265 failed_writer.writerow(string_row) 285 self.writeFailedRow( 286 failed_writer, string_row, 287 "Cannot update: no such entry.") 266 288 continue 267 289 self.updateEntry(obj, row, site) -
waeup/trunk/src/waeup/utils/batching.txt
r4871 r4877 285 285 286 286 This time a new file was created, which keeps all the rows we could not 287 process :287 process and an additional column with error messages: 288 288 289 289 >>> print open('newcomers.csv.create.pending').read() 290 owner,name,taxpayer,dinoports 291 Barney,Barneys Home,1,2 292 Wilma,Wilmas Asylum,1,1 293 Fred,Freds Dinoburgers,0,10 294 Joey,Joeys Drive-in,0,110 290 owner,name,taxpayer,dinoports,--ERRORS-- 291 Barney,Barneys Home,1,2,This object already exists. Skipping. 292 Wilma,Wilmas Asylum,1,1,This object already exists. Skipping. 293 Fred,Freds Dinoburgers,0,10,This object already exists. Skipping. 294 Joey,Joeys Drive-in,0,110,This object already exists. Skipping. 295 295 296 296 This way we can correct the faulty entries and afterwards retry without
Note: See TracChangeset for help on using the changeset viewer.