Changeset 555


Ignore:
Timestamp:
08/12/11 16:33:42 (13 years ago)
Author:
bas
Message:

rewrote save_email_for_debug. So no unicode problems and all files have the same prefix, see #247

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/email2trac.py.in

    r554 r555  
    400400########## DEBUG functions  ###########################################################
    401401
    402     def debug_body(self, message_body, temporary_file=False):
    403         if temporary_file:
    404             (fd, body_file) = tempfile.mkstemp('.body_email2trac')
    405             fx = os.fdopen(fd, 'wb')
    406         else:
    407             body_file = os.path.join(self.parameters.tmpdir, 'body.txt')
    408             fx = open(body_file, 'wb')
     402    def debug_body(self, message_body, temp_file):
     403        """
     404        """
     405        self.logger.debug('function debug_body:')
     406
     407        body_file = "%s.body" %(temp_file)
     408        fx = open(body_file, 'wb')
    409409
    410410        if self.parameters.dry_run:
    411             print 'DRY-RUN: not saving body to %s' %(body_file)
     411            self.logger.debug('DRY-RUN: not saving body to %s' %(body_file))
    412412            return
    413413
    414         print 'writing body to %s' %(body_file)
     414        self.logger.debug('writing body to %s' %(body_file))
    415415        if not message_body:
    416416                message_body = '(None)'
     
    425425            pass
    426426
    427     def debug_attachments(self, message_parts):
     427    def debug_attachments(self, message_parts, temp_file):
    428428        """
    429429        """
     
    439439               
    440440            (original, filename, part) = item
     441            self.logger.debug('\t part%d: Content-Type: %s' % (n, part.get_content_type()) )
     442
     443            dummy_filename, ext = os.path.splitext(filename)
    441444
    442445            n = n + 1
    443             print 'part%d: Content-Type: %s' % (n, part.get_content_type())
    444        
    445             s = 'part%d: filename: %s' %(n, filename)
     446            part_name = 'part%d%s' %(n, ext)
     447            part_file = "%s.%s" %(temp_file, part_name)
     448
     449            s = 'writing %s: filename: %s' %(part_file, filename)
    446450            self.print_unicode(s)
    447    
    448             ## Forbidden chars
    449             #
    450             filename = filename.replace('\\', '_')
    451             filename = filename.replace('/', '_')
    452             filename = filename + '.att_email2trac'
    453    
    454             part_file = os.path.join(self.parameters.tmpdir, filename)
    455             s = 'writing part%d (%s)' % (n,part_file)
    456             self.print_unicode(s)
     451
     452            ## Forbidden chars, just write part files instead of names
     453            #
     454            #filename = filename.replace('\\', '_')
     455            #filename = filename.replace('/', '_')
     456            #filename = filename + '.att_email2trac'
     457            # part_file = os.path.join(self.parameters.tmpdir, filename)
     458            #part_file = util.text.unicode_quote(part_file)
     459            #self.print_unicode(part_file)
    457460
    458461            if self.parameters.dry_run:
    459462                print 'DRY_RUN: NOT saving attachments'
    460463                continue
    461 
    462             # trac error with long filenames support
    463             #part_file = util.text.unicode_quote(part_file)
    464             #part_file = repr(part_file)
    465464
    466465            fx = open(part_file, 'wb')
     
    481480
    482481        if self.parameters.dry_run:
    483             print 'DRY_RUN: NOT saving email message'
     482            self.logger.debug('DRY_RUN: NOT saving email message')
    484483            return
    485484
    486485        if create_tempfile:
    487             (fd, msg_file) = tempfile.mkstemp('.%s.email2trac' %project_name)
     486            (fd, tmp_file) = tempfile.mkstemp('.%s.email2trac' %project_name)
    488487            fx = os.fdopen(fd, 'wb')
    489488        else:
    490             msg_file = os.path.join(self.parameters.tmpdir, 'msg.%s.email2trac' %project_name)
    491             fx = open(msg_file, 'wb')
    492 
    493 
    494         print 'saving email to %s' %(msg_file)
     489            tmp_file = os.path.join(self.parameters.tmpdir, 'msg.%s.email2trac' %project_name)
     490            fx = open(tmp_file, 'wb')
     491
     492
     493        self.logger.debug('saving email to %s' %(tmp_file))
    495494        fx.write('%s' % message)
    496495        fx.close()
    497496       
    498497        try:
    499             os.chmod(msg_file,S_IRWXU|S_IRWXG|S_IRWXO)
     498            os.chmod(tmp_file, S_IRWXU|S_IRWXG|S_IRWXO)
    500499        except OSError:
    501500            pass
     
    504503        message_parts = self.unique_attachment_names(message_parts)
    505504        body_text = self.get_body_text(message_parts)
    506         self.debug_body(body_text, True)
    507         self.debug_attachments(message_parts)
     505        self.debug_body(body_text, tmp_file)
     506        self.debug_attachments(message_parts, tmp_file)
    508507
    509508########## Conversion functions  ###########################################################
     
    12461245
    12471246        if self.parameters.dry_run:
    1248             print "DRY_RUN: no attachments attached to tickets"
     1247            self.logger.debug("DRY_RUN: no attachments attached to tickets")
    12491248            return ''
    12501249
Note: See TracChangeset for help on using the changeset viewer.