Changeset 172


Ignore:
Timestamp:
07/07/07 12:46:09 (17 years ago)
Author:
bas
Message:

email2trac.py.in:

  • Removed code for trac version 0.8
  • Some layout improvements
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r171 r172  
    2121          Implemented by: basv@sara.nl
    2222
     23        * Dropped support for version trac version 0.8. Removed all 0.8
     24          specific code.
     25          Fixed by: basv@sara.nl
    2326
    24272007-04-27
  • trunk/email2trac.py.in

    r169 r172  
    5858        mailto_cc    : basv@sara.nl    # OPTIONAL, use this address as CC in mailto line
    5959        ticket_update: 1               # OPTIONAL, if set then check if this is an update for a ticket
    60         trac_version : 0.8             # OPTIONAL, default is 0.10
     60        trac_version : 0.9             # OPTIONAL, default is 0.10
    6161
    6262        [jouvin]                       # OPTIONAL project declaration, if set both fields necessary
     
    117117
    118118                self.VERSION = version
    119                 if self.VERSION == 0.8:
    120                         self.get_config = self.env.get_config
    121                 else:
    122                         self.get_config = self.env.config.get
     119                self.get_config = self.env.config.get
    123120
    124121                if parameters.has_key('umask'):
     
    317314                # Look for email address in registered trac users
    318315                #
    319                 if self.VERSION == 0.8:
    320                         users = []
    321                 else:
    322                         users = [ u for (u, n, e) in self.env.get_known_users(self.db)
     316                users = [ u for (u, n, e) in self.env.get_known_users(self.db)
    323317                                if e == self.email_addr ]
    324318
     
    470464                        return False
    471465
    472                 body_text = self.get_body_text(m)
    473 
    474466                # Must we update ticket fields
    475467                #
     
    494486                when = int(time.time())
    495487
    496                 if self.VERSION  == 0.8:
    497                         tkt = Ticket(self.db, ticket_id)
    498                         tkt.save_changes(self.db, self.author, body_text, when)
    499                 else:
    500                         try:
    501                                 tkt = Ticket(self.env, ticket_id, self.db)
    502                         except util.TracError, detail:
    503                                 return False
    504 
    505                         # Must we update some ticket fields properties
    506                         #
     488                try:
     489                        tkt = Ticket(self.env, ticket_id, self.db)
     490                except util.TracError, detail:
     491                        return False
     492
     493                # Must we update some ticket fields properties
     494                #
     495                if update_tkt_fields:
    507496                        self.update_ticket_fields(tkt, update_tkt_fields)
    508497
    509                         tkt.save_changes(self.author, body_text, when)
    510                         tkt['id'] = ticket_id
     498                body_text = self.get_body_text(m)
     499
     500                tkt.save_changes(self.author, body_text, when)
     501                tkt['id'] = ticket_id
    511502
    512503                if self.VERSION  == 0.9:
     
    569560
    570561                when = int(time.time())
    571                 if self.VERSION == 0.8:
    572                         ticket_id = tkt.insert(self.db)
    573                 else:
    574                         ticket_id = tkt.insert()
    575                         tkt['id'] = ticket_id
     562
     563                ticket_id = tkt.insert()
     564                tkt['id'] = ticket_id
    576565
    577566                changed = False
     
    593582
    594583                if changed:
    595                         if self.VERSION  == 0.8:
    596                                 tkt.save_changes(self.db, self.author, comment)
    597                         else:
    598                                 tkt.save_changes(self.author, comment)
    599 
    600                 #print tkt.get_changelog(self.db, when)
     584                        tkt.save_changes(self.author, comment)
     585                        #print tkt.get_changelog(self.db, when)
    601586
    602587                if self.notification:
     
    848833
    849834                        url_filename = urllib.quote(filename)
    850                         if self.VERSION == 0.8:
    851                                 dir = os.path.join(self.env.get_attachments_dir(), 'ticket',
    852                                                         urllib.quote(str(ticket['id'])))
    853                                 if not os.path.exists(dir):
    854                                         mkdir_p(dir, 0755)
    855                         else:
    856                                 dir = '/tmp'
    857 
     835                        #
     836                        # Must be tuneables HvB
     837                        #
     838                        dir = '/tmp'
    858839                        path, fd =  util.create_unique_file(os.path.join(dir, url_filename))
    859840                        text = part.get_payload(decode=1)
     
    879860                                count = count + 1
    880861                                       
    881                         # Insert the attachment it differs for the different TRAC versions
     862                        # Insert the attachment
    882863                        #
    883                         if self.VERSION == 0.8:
    884                                 cursor = self.db.cursor()
    885                                 try:
    886                                         cursor.execute('INSERT INTO attachment VALUES("%s","%s","%s",%d,%d,"%s","%s","%s")'
    887                                                 %('ticket', urllib.quote(str(ticket['id'])), filename + '?format=raw', file_size,
    888                                                 int(time.time()),'', self.author, 'e-mail') )
    889 
    890                                 # Attachment is already known
    891                                 #
    892                                 except sqlite.IntegrityError:   
    893                                         #self.db.close()
    894                                         return count
    895 
    896                                 self.db.commit()
    897 
    898                         else:
    899                                 fd = open(path)
    900                                 att = attachment.Attachment(self.env, 'ticket', ticket['id'])
    901 
    902                                 # This will break the ticket_update system, the body_text is vaporized
    903                                 # ;-(
    904                                 #
    905                                 if not update:
    906                                         att.author = self.author
    907                                         att.description = self.email_to_unicode('Added by email2trac')
    908 
    909                                 att.insert(url_filename, fd, file_size)
    910 
    911                                 #except  util.TracError, detail:
    912                                 #       print detail
    913 
    914                                 fd.close()
     864                        fd = open(path)
     865                        att = attachment.Attachment(self.env, 'ticket', ticket['id'])
     866
     867                        # This will break the ticket_update system, the body_text is vaporized
     868                        # ;-(
     869                        #
     870                        if not update:
     871                                att.author = self.author
     872                                att.description = self.email_to_unicode('Added by email2trac')
     873
     874                        att.insert(url_filename, fd, file_size)
     875                        #except  util.TracError, detail:
     876                        #       print detail
    915877
    916878                        # Remove the created temporary filename
    917879                        #
     880                        fd.close()
    918881                        os.unlink(path)
    919882
     
    1020983       
    1021984        try:
    1022                 if version == 0.8:
    1023                         from trac.Environment import Environment
    1024                         from trac.Ticket import Ticket
    1025                         from trac.Notify import TicketNotifyEmail
    1026                         from trac.Href import Href
    1027                         from trac import util
    1028                         import sqlite
    1029                 elif version == 0.9:
     985                if version == 0.9:
    1030986                        from trac import attachment
    1031987                        from trac.env import Environment
Note: See TracChangeset for help on using the changeset viewer.