Changeset 12516 for main/waeup.kofa/trunk/src/waeup/kofa/utils
- Timestamp:
- 27 Jan 2015, 08:31:34 (10 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/utils
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py
r12513 r12516 497 497 raise NotImplementedError 498 498 499 def get_selected(self, site, selected): 500 """Get datasets to export for selected items 501 specified by a list of identifiers. 502 503 Returns an iterable. 504 """ 505 raise NotImplementedError 506 499 507 def export(self, iterable, filepath=None): 500 508 """Export `iterable` as CSV file. … … 521 529 """ 522 530 data = self.get_filtered(site, **kw) 531 return self.export(data, filepath=filepath) 532 533 def export_selected(self, site, filepath=None, **kw): 534 """Export those items specified by a list of identifiers 535 called `selected`. 536 537 If `filepath` is ``None``, a raw string with CSV data should 538 be returned. 539 """ 540 selected = kw.get('selected', []) 541 data = self.get_selected(site, selected) 523 542 return self.export(data, filepath=filepath) 524 543 … … 551 570 if kw == {}: 552 571 exporter.export_all(site, filepath=output_path) 572 elif kw.has_key('selected'): 573 exporter.export_selected(site, filepath=output_path, **kw) 553 574 else: 554 575 exporter.export_filtered(site, filepath=output_path, **kw) -
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_batching.py
r11737 r12516 342 342 # we can pass in positional and keyword args 343 343 exporter = ExporterBase() 344 writer, outfile = exporter.get_csv_writer(filepath=self.workfile)345 344 self.assertRaises(NotImplementedError, exporter.export_filtered, 346 345 'foo', bar='bar') 346 347 def test_export_selected(self): 348 # we can pass in a list of identifiers 349 exporter = ExporterBase() 350 self.assertRaises(NotImplementedError, exporter.export_selected, 351 'foo', selected=[]) 347 352 return 348 353 … … 360 365 def export_filtered(self, site, filepath=None, foo=None, bar=None): 361 366 if foo or bar: 367 open(filepath, 'wb').write(SAMPLE_FILTERED_DATA) 368 return 369 self.export_all(site, filepath=filepath) 370 return 371 372 def export_selected(self, site, filepath=None, selected=None): 373 if selected: 362 374 open(filepath, 'wb').write(SAMPLE_FILTERED_DATA) 363 375 return … … 399 411 # we export filtered sets 400 412 result_path = export_job(None, 'cave_exporter', foo='foo') 413 contents = open(result_path, 'rb').read() 414 shutil.rmtree(os.path.dirname(result_path)) 415 self.assertEqual(contents, SAMPLE_FILTERED_DATA) 416 return 417 418 def test_export_job_selected(self): 419 # we export subsets 420 result_path = export_job(None, 'cave_exporter', selected=['foo']) 401 421 contents = open(result_path, 'rb').read() 402 422 shutil.rmtree(os.path.dirname(result_path))
Note: See TracChangeset for help on using the changeset viewer.