Commits

Anonymous committed ccf4bb5

Merged patch from juracy@wsh.com.br (thanks for the patch), for encoding data as UTF8. Closes #487.

  • Participants
  • Parent commits 5c0e38c
  • Branches trunk

Comments (0)

Files changed (2)

 Ivo Looser              ivo.looser@login.ch
 James Moger             jamesm@transonic.com
 Jennifer Murtell        jen@jmurtell.com
+juracy@wsh.com.br
 Nicolas Riley           sabi
 Mark Rowe               mrowe@bluewire.net.nz
 Olliver Rutherfurd      ollie
 Emmeran Seehuber        rototor@rototor.de
 Dmitry Yusupov          dmitry_yus@yahoo.com
 
-The ever so elusive Anonymous
+The ever so elusive Anonymous.
 
 Diggs and Lula (official pawprint contributors)
 

contrib/bugzilla2trac.py

 import MySQLdb.cursors
 import trac.Environment
 
+if not hasattr(sys, 'setdefaultencoding'):
+    reload(sys)
+
+sys.setdefaultencoding('latin1')
+
 class TracDatabase(object):
     def __init__(self, path):
         self.env = trac.Environment.Environment(path)
         for value, i in s:
             print "inserting severity ", value, " ", i
             c.execute("""INSERT INTO enum (type, name, value) VALUES (%s, %s, %s)""",
-                      "severity", value, i)
+                      "severity", value.encode('utf-8'), i)
         self.db().commit()
     
     def setPriorityList(self, s):
             print "inserting priority ", value, " ", i
             c.execute("""INSERT INTO enum (type, name, value) VALUES (%s, %s, %s)""",
                       "priority",
-                      value,
+                      value.encode('utf-8'),
                       i)
         self.db().commit()
 
         for comp in l:
             print "inserting component ", comp[key]
             c.execute("""INSERT INTO component (name) VALUES (%s)""",
-                      comp[key])
+                      comp[key].encode('utf-8'))
         self.db().commit()
     
     def setVersionList(self, v, key):
         for vers in v:
             print "inserting version ", vers[key]
             c.execute("""INSERT INTO version (name) VALUES (%s)""",
-                      vers[key])
+                      vers[key].encode('utf-8'))
         self.db().commit()
         
     def setMilestoneList(self, m, key):
         for ms in m:
             print "inserting milestone ", ms[key]
             c.execute("""INSERT INTO milestone (name) VALUES (%s)""",
-                      ms[key])
+                      ms[key].encode('utf-8'))
         self.db().commit()
     
     def addTicket(self, time, changetime, component,
                                          %s, %s, %s, %s, %s,
                                          %s, %s, %s, %s,
                                          %s, %s, %s)""",
-                  time.strftime('%s'), changetime.strftime('%s'), component,
-                  severity, priority, owner, reporter, cc,
-                  version, milestone, status.lower(), resolution,
-                  summary, '{{{\n%s\n}}}' % (description, ), keywords)
+                  time.strftime('%s'), changetime.strftime('%s'), component.encode('utf-8'),
+                  severity.encode('utf-8'), priority.encode('utf-8'), owner, reporter, cc,
+                  version, milestone.encode('utf-8'), status.lower(), resolution,
+                  summary.encode('utf-8'), '{{{\n%s\n}}}' % (description.encode('utf-8'), ), keywords)
         self.db().commit()
         return self.db().db.sqlite_last_insert_rowid()
     
         c = self.db().cursor()
         c.execute("""INSERT INTO ticket_change (ticket, time, author, field, oldvalue, newvalue)
                                  VALUES        (%s, %s, %s, %s, %s, %s)""",
-                  ticket, time.strftime('%s'), author, 'comment', '', '{{{\n%s\n}}}' % (value, ))
+                  ticket, time.strftime('%s'), author, 'comment', '', '{{{\n%s\n}}}' % (value.encode('utf-8'), ))
         self.db().commit()
 
     def addTicketChange(self, ticket, time, author, field, oldvalue, newvalue):
         c = self.db().cursor()
         c.execute("""INSERT INTO ticket_change (ticket, time, author, field, oldvalue, newvalue)
                                  VALUES        (%s, %s, %s, %s, %s, %s)""",
-                  ticket, time.strftime('%s'), author, field, oldvalue, newvalue)
+                  ticket, time.strftime('%s'), author, field, oldvalue.encode('utf-8'), newvalue.encode('utf-8'))
         self.db().commit()
 
 class TheBugzillaConverter: