Hello, after some time of fighting with importing issues from my current
Bugzilla into trac, I came with the solution which seems to work with my
cyrillic database (koi8-r in fact). You may find the patch below.

However now I'm wandering is it possible to import different products from
bugzilla into different trac environments, with creation of these environment
if required?

Thank you in advance!

--- bugzilla2trac.py.orig       2007-04-20 15:41:52.000000000 +0200
+++ bugzilla2trac.py    2007-09-26 13:31:40.000000000 +0200
@@ -329,7 +329,8 @@
         if PRIORITIES_MAP.has_key(priority):
             priority = PRIORITIES_MAP[priority]
 
-        print "  inserting ticket %s -- %s" % (id, summary)
+        #print "  inserting ticket %s -- %s" % (id, summary)
+        print "  inserting ticket %s" % (id)
 
         c.execute("""INSERT INTO ticket (id, type, time, changetime, component,
                                          severity, priority, owner, reporter,
@@ -338,15 +339,15 @@
                                          keywords)
                                  VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s,
                                          %s, %s, %s, %s, %s, %s, %s, %s)""",
-                  (id, type.encode('utf-8'), 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'), desc,
+                  (id, type, time.strftime('%s'),
+                   changetime.strftime('%s'), component,
+                   severity, priority, owner,
+                   reporter, cc, version, milestone,
+                   status.lower(), resolution, summary, desc,
                    keywords))
-        
+       
         self.db().commit()
-        return self.db().get_last_id(c, 'ticket')
+        return id
     
     def addTicketComment(self, ticket, time, author, value):
         comment = value.encode('utf-8')
@@ -395,7 +396,8 @@
         description = a['description'].encode('utf-8')
         id = a['bug_id']
         filename = a['filename'].encode('utf-8')
-        filedata = StringIO.StringIO(a['thedata'].tostring())
+        #filedata = StringIO.StringIO(a['thedata'].tostring())
+        filedata = StringIO.StringIO(a['thedata'])
         filesize = len(filedata.getvalue())
         time = a['creation_ts']
         print "    ->inserting attachment '%s' for ticket %s -- %s" % \
@@ -404,7 +406,10 @@
         attachment = Attachment(self.env, 'ticket', id)
         attachment.author = author
         attachment.description = description
-        attachment.insert(filename, filedata, filesize, time.strftime('%s'))
+       try:
+               attachment.insert(filename, filedata, filesize, 
time.strftime('%s'))
+       except :
+               print "Failed to insert attach"
         del attachment
         
     def getLoginName(self, cursor, userid):
@@ -465,7 +470,8 @@
     print "Bugzilla MySQL('%s':'%s':'%s':'%s'): connecting..." % \
             (_db, _host, _user, ("*" * len(_password)))
     mysql_con = MySQLdb.connect(host=_host, 
-                user=_user, passwd=_password, db=_db, compress=1, 
+                user=_user, passwd=_password, db=_db, compress=1,
+               use_unicode=True,
                 cursorclass=MySQLdb.cursors.DictCursor)
     mysql_cur = mysql_con.cursor()
 
@@ -803,7 +809,7 @@
         ticket['keywords'] = string.join(keywords)                
         ticketid = trac.addTicket(**ticket)
 
-        mysql_cur.execute("SELECT * FROM attachments WHERE bug_id = %s" % 
bugid)
+        mysql_cur.execute("SELECT * FROM attachments left join attach_data on 
attachments.attach_id=attach_data.id WHERE bug_id = %s" % bugid)
         attachments = mysql_cur.fetchall()
         for a in attachments:
             author = trac.getLoginName(mysql_cur, a['submitter_id'])
-- 
Eugene N Dzhurinsky

Attachment: pgpyn8rMdYDM1.pgp
Description: PGP signature

Reply via email to