Changeset 503 for trunk/email2trac.py.in
- Timestamp:
- 01/07/11 15:44:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/email2trac.py.in
r502 r503 585 585 self.logger.debug(util.text.unicode_quote(s)) 586 586 587 588 def html_2_txt(self, data): 589 """ 590 Various routines to convert html syntax to valid trac wiki syntax 591 """ 592 self.logger.debug('function html_2_txt') 593 594 ## This routine make an safe html that can be include 595 # in trac, but no further text processing can be done 596 # 597 # try: 598 # from lxml.html.clean import Cleaner 599 # tags_rm = list() 600 # tags_rm.append('body') 601 # 602 # cleaner = Cleaner(remove_tags=tags_rm ) 603 # parsed_data = cleaner.clean_html(data) 604 # parsed_data = '\n{{{\n#!html\n' + parsed_data + '\n}}}\n' 605 # 606 # return parsed_data 607 # 608 # except ImportError:: 609 # pass 610 611 parsed_data = None 612 if self.parameters.html2text_cmd: 613 tmp_file = tempfile.mktemp('email2trac.html') 614 cmd = '%s %s' %(self.parameters.html2text_cmd, tmp_file) 615 self.logger.debug('\t html2text conversion %s'%(cmd)) 616 617 if self.parameters.dry_run: 618 print 'DRY_RUN: html2text conversion command: %s\n' %(cmd) 619 620 else: 621 f = open(tmp_file, "w+") 622 f.write(data) 623 f.close() 624 625 lines = os.popen(cmd).readlines() 626 parsed_data = ''.join(lines) 627 628 os.unlink(tmp_file) 629 630 else: 631 self.logger.debug('\t No html2text conversion tool specified in email2trac.conf') 632 633 return parsed_data 634 587 635 ########## TRAC ticket functions ########################################################### 588 636 … … 1833 1881 if content_type == 'text/html': 1834 1882 1835 if self.parameters.html2text_cmd: 1836 1837 tmp_file = tempfile.mktemp('.email2trac') 1838 cmd = '%s %s' %(self.parameters.html2text_cmd, tmp_file) 1839 self.logger.debug('\t html2text conversion %s'%(cmd)) 1840 1841 if self.parameters.dry_run: 1842 print 'DRY_RUN: html2text conversion command: %s\n' %(cmd) 1843 else: 1844 f = open(tmp_file, "w+") 1845 f.write(body_text) 1846 f.close() 1847 1848 lines = os.popen(cmd).readlines() 1849 body_text = ''.join(lines) 1850 1851 os.unlink(tmp_file) 1852 1853 else: 1854 self.logger.debug('\t No html2text conversion tool specified in email2trac.conf') 1883 body_text = self.html_2_txt(body_text) 1884 if not body_text: 1855 1885 continue 1856 1886
Note: See TracChangeset
for help on using the changeset viewer.