Changeset 2973 for WAeUP_SRP/base
- Timestamp:
- 3 Jan 2008, 15:27:58 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPTables.py
r2926 r2973 205 205 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 206 206 export_file = "%s/export/%s_%s.csv" % (i_home,self.__name__,current,) 207 print export_file208 207 res_list = [] 209 208 lines = [] … … 215 214 fields.append(f) 216 215 headline = ','.join(fields) 217 #open(export_file,"a").write(headline +'\n')218 216 out = open(export_file,"wb") 219 217 out.write(headline +'\n') … … 221 219 out = open(export_file,"a") 222 220 csv_writer = csv.DictWriter(out,fields,) 223 #format = '"%(' + ')s","%('.join(fields) + ')s"'224 221 records = self() 225 222 nr2export = len(records) … … 235 232 total += 1 236 233 if total and not total % chunk or total == len(records): 237 #open(export_file,"a").write('\n'.join(lines) +'\n')238 234 csv_writer.writerows(lines) 239 235 anz = len(lines) … … 513 509 class PinTable(WAeUPTable): ###( 514 510 from ZODB.POSException import ConflictError 511 security = ClassSecurityInfo() 515 512 meta_type = 'WAeUP Pin Tool' 516 513 name = "portal_pins" … … 521 518 name = self.name 522 519 WAeUPTable.__init__(self, name) 520 521 security.declareProtected(ModifyPortalContent,"dumpAll")###( 522 def dumpAll(self,include_unused=None): 523 """dump all data in the table to a csv""" 524 member = self.portal_membership.getAuthenticatedMember() 525 logger = logging.getLogger('PinTable.dumpAll') 526 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 527 export_file = "%s/export/%s_%s.csv" % (i_home,self.__name__,current,) 528 res_list = [] 529 lines = [] 530 if hasattr(self,"export_keys"): 531 fields = self.export_keys 532 else: 533 fields = [] 534 for f in self.schema(): 535 fields.append(f) 536 headline = ','.join(fields) 537 out = open(export_file,"wb") 538 out.write(headline +'\n') 539 out.close() 540 out = open(export_file,"a") 541 csv_writer = csv.DictWriter(out,fields,) 542 if include_unused is not None and str(member) not in ('admin','joachim'): 543 logger.info('%s tries to dump pintable with unused pins' % (member)) 544 return 545 if include_unused is not None: 546 records = self() 547 else: 548 records = self.evalAdvancedQuery(~Eq('student','')) 549 nr2export = len(records) 550 logger.info('%s starts dumping, %s records to export' % (member,nr2export)) 551 chunk = 2000 552 total = 0 553 start = DateTime.DateTime().timeTime() 554 start_chunk = DateTime.DateTime().timeTime() 555 for record in records: 556 not_all = False 557 d = self.record2dict(fields,record) 558 lines.append(d) 559 total += 1 560 if total and not total % chunk or total == len(records): 561 csv_writer.writerows(lines) 562 anz = len(lines) 563 logger.info("wrote %(anz)d total written %(total)d" % vars()) 564 end_chunk = DateTime.DateTime().timeTime() 565 duration = end_chunk-start_chunk 566 per_record = duration/anz 567 till_now = end_chunk - start 568 avarage_per_record = till_now/total 569 estimated_end = DateTime.DateTime(start + avarage_per_record * nr2export) 570 estimated_end = estimated_end.strftime("%H:%M:%S") 571 logger.info('%(duration)4.1f, %(per_record)4.3f,end %(estimated_end)s' % vars()) 572 start_chunk = DateTime.DateTime().timeTime() 573 lines = [] 574 end = DateTime.DateTime().timeTime() 575 logger.info('total time %6.2f m' % ((end-start)/60)) 576 import os 577 filename, extension = os.path.splitext(export_file) 578 from subprocess import call 579 msg = "wrote %(total)d records to %(export_file)s" % vars() 580 #try: 581 # retcode = call('gzip %s' % (export_file),shell=True) 582 # if retcode == 0: 583 # msg = "wrote %(total)d records to %(export_file)s.gz" % vars() 584 #except OSError, e: 585 # retcode = -99 586 # logger.info("zip failed with %s" % e) 587 logger.info(msg) 588 args = {'portal_status_message': msg} 589 #url = self.REQUEST.get('URL1') + '?' + urlencode(args) 590 url = self.REQUEST.get('URL2') 591 return self.REQUEST.RESPONSE.redirect(url) 592 ###) 593 523 594 524 595
Note: See TracChangeset for help on using the changeset viewer.