Changeset 6273 for main/waeup.sirp/trunk/src/waeup/sirp/utils/batching.py
- Timestamp:
- 4 Jun 2011, 02:29:21 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/utils/batching.py
r6259 r6273 15 15 from zope.schema import getFields 16 16 from waeup.sirp.interfaces import ( 17 IBatchProcessor, ISchemaTypeConverter, FatalCSVError, DuplicationError) 17 IBatchProcessor, ISchemaTypeConverter, FatalCSVError, DuplicationError, 18 IObjectConverter) 18 19 19 20 class BatchProcessor(grok.GlobalUtility): … … 149 150 warnings.append(msg) 150 151 return (row, warnings) 152 153 def stringFromErrs(self, errors, inv_errors): 154 result = [] 155 for err in errors: 156 fieldname, message = err 157 result.append("%s: %s" % (fieldname, message)) 158 for err in inv_errors: 159 result.append("invariant: %s" % err) 160 return '; '.join(result) 151 161 152 162 def callFactory(self, *args, **kw): … … 239 249 temp_dir = tempfile.mkdtemp() 240 250 241 (base, ext) = os.path.splitext(path) 251 base = os.path.basename(path) 252 (base, ext) = os.path.splitext(base) 242 253 failed_path = os.path.join(temp_dir, "%s.pending%s" % (base, ext)) 243 254 failed_headers = mapping.keys() … … 258 269 num_warns = 0 259 270 site = grok.getSite() 271 converter = IObjectConverter(self.iface) 260 272 for raw_row in reader: 261 273 num += 1 262 274 string_row = self.applyMapping(raw_row, mapping) 263 row, conv_warnings = self.convertToTypes( 264 copy.deepcopy(string_row), converters) 265 if len(conv_warnings): 275 row = dict(string_row.items()) # create deep copy 276 errs, inv_errs, conv_dict = converter.fromStringDict( 277 string_row, self.factory_name) 278 if errs or inv_errs: 266 279 num_warns += 1 267 self.writeFailedRow(failed_writer, raw_row, conv_warnings) 280 conv_warnings = self.stringFromErrs(errs, inv_errs) 281 self.writeFailedRow( 282 failed_writer, raw_row, conv_warnings) 268 283 continue 284 row.update(conv_dict) 269 285 270 286 if mode == 'create': … … 286 302 try: 287 303 self.addEntry(obj, row, site) 288 except DuplicationError, error:289 num_warns += 1 290 self.writeFailedRow( 291 failed_writer, raw_row, 292 "%s Skipping." % error.m sg)304 except KeyError, error: 305 num_warns += 1 306 self.writeFailedRow( 307 failed_writer, raw_row, 308 "%s Skipping." % error.message) 293 309 continue 294 310 elif mode == 'remove':
Note: See TracChangeset for help on using the changeset viewer.