Changeset 503 for trunk


Ignore:
Timestamp:
01/07/11 15:44:00 (13 years ago)
Author:
bas
Message:

changed some code an made an function html_2_text that uses an external program to convert the html to text so we can use it for further processing.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r501 r503  
    1010   * Support for parentdir. Can be used to avoid sections for each project
    1111     or if all projects have a common parent directory, you can leave out
    12      the project drectory setting for each project.
     12     the project drectory setting for each project, eg:
     13      * parentdir: /data/trac/oss/projects
    1314
    1415     If an section defines a project directory then this can NOT be overriden
     
    4445   * Fixed some bugs in function update_ticket_fields:
    4546       - Can not clear values, repoterd by thomas dot moschny add gmx dot de
    46              closes #228
     47     closes #228
    4748       - Values were updated regardless if there are not allowed for the ticket
    48              field.
     49     field.
    4950     Author: Bas van der Vlies
    5051
     
    6061   * Added html conversion via external commmand: eg email2trac.conf
    6162      - html2text_cmd: /usr/bin/html2text -nobs
     63      - html2text_cmd: /usr/bin/w3m -dump
     64      - html2text_cmd: /usr/bin/lynx -dump
     65      - html2text_cmd: /usr/bin/links -dump
    6266     closes #218
    6367     Author: Bas van der Vlies
     
    7579     also honour the permission model if set, closes #198
    7680     an example how to use it:
    77         email2trac.conf:
     81    email2trac.conf:
    7882                [project]
    79                 workflow_closed: reopen
    80                 workflow_infoneeded: provideinfo
    81 
    82         trac.ini:
    83                 [ticket-workflow]
    84                 reopen = closed -> reopened
    85                 reopen.permissions = TICKET_CREATE
    86                 reopen.operations = del_resolution
    87                
    88                 provideinfo = infoneeded -> moreinfo
    89                 provideinfo.permissions = TICKET_CREATE
    90                 provideinfo.name = info provided
     83            workflow_closed: reopen
     84            xworkflow_infoneeded: provideinfo
     85
     86    trac.ini:
     87    [ticket-workflow]
     88    reopen = closed -> reopened
     89    reopen.permissions = TICKET_CREATE
     90    reopen.operations = del_resolution
     91
     92    provideinfo = infoneeded -> moreinfo
     93    provideinfo.permissions = TICKET_CREATE
     94    provideinfo.name = info provided
    9195
    9296     Authors: kroseneg add schmidham dot net and Bas van der Vlies
  • trunk/email2trac.py.in

    r502 r503  
    585585                        self.logger.debug(util.text.unicode_quote(s))
    586586
     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
    587635########## TRAC ticket functions  ###########################################################
    588636
     
    18331881                        if content_type == 'text/html':
    18341882
    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:
    18551885                                        continue
    18561886
Note: See TracChangeset for help on using the changeset viewer.