1 | #!/usr/bin/env python
|
---|
2 |
|
---|
3 | """
|
---|
4 | Import a Bugzilla items into a Trac database.
|
---|
5 |
|
---|
6 | Requires: Trac 0.9b1 from http://trac.edgewall.org/
|
---|
7 | Python 2.3 from http://www.python.org/
|
---|
8 | MySQL >= 3.23 from http://www.mysql.org/
|
---|
9 | or PostGreSQL 8.4 from http://www.postgresql.org/
|
---|
10 | or SQLite 3 from http://www.sqlite.org/
|
---|
11 |
|
---|
12 | Thanks: Mark Rowe <mrowe@bluewire.net.nz>
|
---|
13 | for original TracDatabase class
|
---|
14 |
|
---|
15 | Copyright 2004, Dmitry Yusupov <dmitry_yus@yahoo.com>
|
---|
16 |
|
---|
17 | Many enhancements, Bill Soudan <bill@soudan.net>
|
---|
18 | Other enhancements, Florent Guillaume <fg@nuxeo.com>
|
---|
19 | Reworked, Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
|
---|
20 | Jeff Moreland <hou5e@hotmail.com>
|
---|
21 |
|
---|
22 | $Id: bugzilla2trac.py 9282 2010-02-26 10:06:58Z cboos $
|
---|
23 | """
|
---|
24 |
|
---|
25 | import re
|
---|
26 |
|
---|
27 | ###
|
---|
28 | ### Conversion Settings -- edit these before running if desired
|
---|
29 | ###
|
---|
30 |
|
---|
31 | # Bugzilla version. You can find this in Bugzilla's globals.pl file.
|
---|
32 | #
|
---|
33 | # Currently, the following bugzilla versions are known to work:
|
---|
34 | # 2.11 (2110), 2.16.5 (2165), 2.16.7 (2167), 2.18.3 (2183), 2.19.1 (2191),
|
---|
35 | # 2.23.3 (2233), 3.04.4 (3044)
|
---|
36 | #
|
---|
37 | # If you run this script on a version not listed here and it is successful,
|
---|
38 | # please file a ticket at http://trac.edgewall.org
|
---|
39 | #
|
---|
40 | BZ_VERSION = 3044
|
---|
41 |
|
---|
42 | # MySQL connection parameters for the Bugzilla database. These can also
|
---|
43 | # be specified on the command line.
|
---|
44 | BZ_DB = ""
|
---|
45 | BZ_HOST = ""
|
---|
46 | BZ_USER = ""
|
---|
47 | BZ_PASSWORD = ""
|
---|
48 |
|
---|
49 | # Path to the Trac environment.
|
---|
50 | TRAC_ENV = "/usr/local/trac"
|
---|
51 |
|
---|
52 | # If true, all existing Trac tickets and attachments will be removed
|
---|
53 | # prior to import.
|
---|
54 | TRAC_CLEAN = True
|
---|
55 |
|
---|
56 | # Enclose imported ticket description and comments in a {{{ }}}
|
---|
57 | # preformat block? This formats the text in a fixed-point font.
|
---|
58 | PREFORMAT_COMMENTS = False
|
---|
59 |
|
---|
60 | # Replace bug numbers in comments with #xyz
|
---|
61 | REPLACE_BUG_NO = False
|
---|
62 |
|
---|
63 | # Severities
|
---|
64 | SEVERITIES = [
|
---|
65 | ("blocker", "1"),
|
---|
66 | ("critical", "2"),
|
---|
67 | ("major", "3"),
|
---|
68 | ("normal", "4"),
|
---|
69 | ("minor", "5"),
|
---|
70 | ("trivial", "6")
|
---|
71 | ]
|
---|
72 |
|
---|
73 | # Priorities
|
---|
74 | # If using the default Bugzilla priorities of P1 - P5, do not change anything
|
---|
75 | # here.
|
---|
76 | # If you have other priorities defined please change the P1 - P5 mapping to
|
---|
77 | # the order you want. You can also collapse multiple priorities on bugzilla's
|
---|
78 | # side into the same priority on Trac's side, simply adjust PRIORITIES_MAP.
|
---|
79 | PRIORITIES = [
|
---|
80 | ("highest", "1"),
|
---|
81 | ("high", "2"),
|
---|
82 | ("normal", "3"),
|
---|
83 | ("low", "4"),
|
---|
84 | ("lowest", "5")
|
---|
85 | ]
|
---|
86 |
|
---|
87 | # Bugzilla: Trac
|
---|
88 | # NOTE: Use lowercase.
|
---|
89 | PRIORITIES_MAP = {
|
---|
90 | "p1": "highest",
|
---|
91 | "p2": "high",
|
---|
92 | "p3": "normal",
|
---|
93 | "p4": "low",
|
---|
94 | "p5": "lowest"
|
---|
95 | }
|
---|
96 |
|
---|
97 | # By default, all bugs are imported from Bugzilla. If you add a list
|
---|
98 | # of products here, only bugs from those products will be imported.
|
---|
99 | PRODUCTS = []
|
---|
100 | # These Bugzilla products will be ignored during import.
|
---|
101 | IGNORE_PRODUCTS = []
|
---|
102 |
|
---|
103 | # These milestones are ignored
|
---|
104 | IGNORE_MILESTONES = ["---"]
|
---|
105 |
|
---|
106 | # Don't import user names and passwords into htpassword if
|
---|
107 | # user is disabled in bugzilla? (i.e. profiles.DisabledText<>'')
|
---|
108 | IGNORE_DISABLED_USERS = True
|
---|
109 |
|
---|
110 | # These logins are converted to these user ids
|
---|
111 | LOGIN_MAP = {
|
---|
112 | #'some.user@example.com': 'someuser',
|
---|
113 | }
|
---|
114 |
|
---|
115 | # These emails are removed from CC list
|
---|
116 | IGNORE_CC = [
|
---|
117 | #'loser@example.com',
|
---|
118 | ]
|
---|
119 |
|
---|
120 | # The 'component' field in Trac can come either from the Product or
|
---|
121 | # or from the Component field of Bugzilla. COMPONENTS_FROM_PRODUCTS
|
---|
122 | # switches the behavior.
|
---|
123 | # If COMPONENTS_FROM_PRODUCTS is True:
|
---|
124 | # - Bugzilla Product -> Trac Component
|
---|
125 | # - Bugzilla Component -> Trac Keyword
|
---|
126 | # IF COMPONENTS_FROM_PRODUCTS is False:
|
---|
127 | # - Bugzilla Product -> Trac Keyword
|
---|
128 | # - Bugzilla Component -> Trac Component
|
---|
129 | COMPONENTS_FROM_PRODUCTS = False
|
---|
130 |
|
---|
131 | # If COMPONENTS_FROM_PRODUCTS is True, the default owner for each
|
---|
132 | # Trac component is inferred from a default Bugzilla component.
|
---|
133 | DEFAULT_COMPONENTS = ["default", "misc", "main"]
|
---|
134 |
|
---|
135 | # This mapping can assign keywords in the ticket entry to represent
|
---|
136 | # products or components (depending on COMPONENTS_FROM_PRODUCTS).
|
---|
137 | # The keyword will be ignored if empty.
|
---|
138 | KEYWORDS_MAPPING = {
|
---|
139 | #'Bugzilla_product_or_component': 'Keyword',
|
---|
140 | "default": "",
|
---|
141 | "misc": "",
|
---|
142 | }
|
---|
143 |
|
---|
144 | # If this is True, products or components are all set as keywords
|
---|
145 | # even if not mentionned in KEYWORDS_MAPPING.
|
---|
146 | MAP_ALL_KEYWORDS = True
|
---|
147 |
|
---|
148 | # Custom field mappings
|
---|
149 | CUSTOMFIELD_MAP = {
|
---|
150 | #'Bugzilla_field_name': 'Trac_customfield_name',
|
---|
151 | #'op_sys': 'os',
|
---|
152 | #'cf_featurewantedby': 'wanted_by',
|
---|
153 | #'product': 'product'
|
---|
154 | }
|
---|
155 |
|
---|
156 | # Bug comments that should not be imported. Each entry in list should
|
---|
157 | # be a regular expression.
|
---|
158 | IGNORE_COMMENTS = [
|
---|
159 | "^Created an attachment \(id="
|
---|
160 | ]
|
---|
161 |
|
---|
162 | ###########################################################################
|
---|
163 | ### You probably don't need to change any configuration past this line. ###
|
---|
164 | ###########################################################################
|
---|
165 |
|
---|
166 | # Bugzilla status to Trac status translation map.
|
---|
167 | #
|
---|
168 | # NOTE: bug activity is translated as well, which may cause bug
|
---|
169 | # activity to be deleted (e.g. resolved -> closed in Bugzilla
|
---|
170 | # would translate into closed -> closed in Trac, so we just ignore the
|
---|
171 | # change).
|
---|
172 | #
|
---|
173 | # There is some special magic for open in the code: if there is no
|
---|
174 | # Bugzilla owner, open is mapped to 'new' instead.
|
---|
175 | STATUS_TRANSLATE = {
|
---|
176 | "unconfirmed": "new",
|
---|
177 | "open": "assigned",
|
---|
178 | "resolved": "closed",
|
---|
179 | "verified": "closed",
|
---|
180 | "released": "closed"
|
---|
181 | }
|
---|
182 |
|
---|
183 | # Translate Bugzilla statuses into Trac keywords. This provides a way
|
---|
184 | # to retain the Bugzilla statuses in Trac. e.g. when a bug is marked
|
---|
185 | # 'verified' in Bugzilla it will be assigned a VERIFIED keyword.
|
---|
186 | STATUS_KEYWORDS = {
|
---|
187 | "verified": "VERIFIED",
|
---|
188 | "released": "RELEASED"
|
---|
189 | }
|
---|
190 |
|
---|
191 | # Some fields in Bugzilla do not have equivalents in Trac. Changes in
|
---|
192 | # fields listed here will not be imported into the ticket change history,
|
---|
193 | # otherwise you'd see changes for fields that don't exist in Trac.
|
---|
194 | IGNORED_ACTIVITY_FIELDS = ["everconfirmed"]
|
---|
195 |
|
---|
196 | # Regular expression and its replacement
|
---|
197 | # this expression will update references to bugs 1 - 99999 that
|
---|
198 | # have the form "bug 1" or "bug #1"
|
---|
199 | BUG_NO_RE = re.compile(r"\b(bug #?)([0-9]{1,5})\b", re.I)
|
---|
200 | BUG_NO_REPL = r"#\2"
|
---|
201 |
|
---|
202 | ###
|
---|
203 | ### Script begins here
|
---|
204 | ###
|
---|
205 |
|
---|
206 | import os
|
---|
207 | import sys
|
---|
208 | import string
|
---|
209 | import StringIO
|
---|
210 |
|
---|
211 | import MySQLdb
|
---|
212 | import MySQLdb.cursors
|
---|
213 | try:
|
---|
214 | from trac.env import Environment
|
---|
215 | except:
|
---|
216 | from trac.Environment import Environment
|
---|
217 | from trac.attachment import Attachment
|
---|
218 |
|
---|
219 | if not hasattr(sys, 'setdefaultencoding'):
|
---|
220 | reload(sys)
|
---|
221 |
|
---|
222 | sys.setdefaultencoding('latin1')
|
---|
223 |
|
---|
224 | # simulated Attachment class for trac.add
|
---|
225 | #class Attachment:
|
---|
226 | # def __init__(self, name, data):
|
---|
227 | # self.filename = name
|
---|
228 | # self.file = StringIO.StringIO(data.tostring())
|
---|
229 |
|
---|
230 | # simple field translation mapping. if string not in
|
---|
231 | # mapping, just return string, otherwise return value
|
---|
232 | class FieldTranslator(dict):
|
---|
233 | def __getitem__(self, item):
|
---|
234 | if not dict.has_key(self, item):
|
---|
235 | return item
|
---|
236 |
|
---|
237 | return dict.__getitem__(self, item)
|
---|
238 |
|
---|
239 | statusXlator = FieldTranslator(STATUS_TRANSLATE)
|
---|
240 |
|
---|
241 | class TracDatabase(object):
|
---|
242 | def __init__(self, path):
|
---|
243 | self.env = Environment(path)
|
---|
244 | self._db = self.env.get_db_cnx()
|
---|
245 | self._db.autocommit = False
|
---|
246 | self.loginNameCache = {}
|
---|
247 | self.fieldNameCache = {}
|
---|
248 | from trac.db.api import DatabaseManager
|
---|
249 | self.using_postgres = DatabaseManager(self.env).connection_uri.startswith("postgres:")
|
---|
250 |
|
---|
251 | def db(self):
|
---|
252 | return self._db
|
---|
253 |
|
---|
254 | def hasTickets(self):
|
---|
255 | c = self.db().cursor()
|
---|
256 | c.execute("SELECT count(*) FROM ticket")
|
---|
257 | return int(c.fetchall()[0][0]) > 0
|
---|
258 |
|
---|
259 | def assertNoTickets(self):
|
---|
260 | if self.hasTickets():
|
---|
261 | raise Exception("Will not modify database with existing tickets!")
|
---|
262 |
|
---|
263 | def setSeverityList(self, s):
|
---|
264 | """Remove all severities, set them to `s`"""
|
---|
265 | self.assertNoTickets()
|
---|
266 |
|
---|
267 | c = self.db().cursor()
|
---|
268 | c.execute("DELETE FROM enum WHERE type='severity'")
|
---|
269 | for value, i in s:
|
---|
270 | print " inserting severity '%s' - '%s'" % (value, i)
|
---|
271 | c.execute("""INSERT INTO enum (type, name, value)
|
---|
272 | VALUES (%s, %s, %s)""",
|
---|
273 | ("severity", value.encode('utf-8'), i))
|
---|
274 | self.db().commit()
|
---|
275 |
|
---|
276 | def setPriorityList(self, s):
|
---|
277 | """Remove all priorities, set them to `s`"""
|
---|
278 | self.assertNoTickets()
|
---|
279 |
|
---|
280 | c = self.db().cursor()
|
---|
281 | c.execute("DELETE FROM enum WHERE type='priority'")
|
---|
282 | for value, i in s:
|
---|
283 | print " inserting priority '%s' - '%s'" % (value, i)
|
---|
284 | c.execute("""INSERT INTO enum (type, name, value)
|
---|
285 | VALUES (%s, %s, %s)""",
|
---|
286 | ("priority", value.encode('utf-8'), i))
|
---|
287 | self.db().commit()
|
---|
288 |
|
---|
289 |
|
---|
290 | def setComponentList(self, l, key):
|
---|
291 | """Remove all components, set them to `l`"""
|
---|
292 | self.assertNoTickets()
|
---|
293 |
|
---|
294 | c = self.db().cursor()
|
---|
295 | c.execute("DELETE FROM component")
|
---|
296 | for comp in l:
|
---|
297 | print " inserting component '%s', owner '%s'" % \
|
---|
298 | (comp[key], comp['owner'])
|
---|
299 | c.execute("INSERT INTO component (name, owner) VALUES (%s, %s)",
|
---|
300 | (comp[key].encode('utf-8'),
|
---|
301 | comp['owner'].encode('utf-8')))
|
---|
302 | self.db().commit()
|
---|
303 |
|
---|
304 | def setVersionList(self, v, key):
|
---|
305 | """Remove all versions, set them to `v`"""
|
---|
306 | self.assertNoTickets()
|
---|
307 |
|
---|
308 | c = self.db().cursor()
|
---|
309 | c.execute("DELETE FROM version")
|
---|
310 | for vers in v:
|
---|
311 | print " inserting version '%s'" % (vers[key])
|
---|
312 | c.execute("INSERT INTO version (name) VALUES (%s)",
|
---|
313 | (vers[key].encode('utf-8'),))
|
---|
314 | self.db().commit()
|
---|
315 |
|
---|
316 | def setMilestoneList(self, m, key):
|
---|
317 | """Remove all milestones, set them to `m`"""
|
---|
318 | self.assertNoTickets()
|
---|
319 |
|
---|
320 | c = self.db().cursor()
|
---|
321 | c.execute("DELETE FROM milestone")
|
---|
322 | for ms in m:
|
---|
323 | milestone = ms[key]
|
---|
324 | print " inserting milestone '%s'" % (milestone)
|
---|
325 | c.execute("INSERT INTO milestone (name) VALUES (%s)",
|
---|
326 | (milestone.encode('utf-8'),))
|
---|
327 | self.db().commit()
|
---|
328 |
|
---|
329 | def addTicket(self, id, time, changetime, component, severity, priority,
|
---|
330 | owner, reporter, cc, version, milestone, status, resolution,
|
---|
331 | summary, description, keywords, customfields):
|
---|
332 | c = self.db().cursor()
|
---|
333 |
|
---|
334 | desc = description.encode('utf-8')
|
---|
335 | type = "defect"
|
---|
336 |
|
---|
337 | if SEVERITIES:
|
---|
338 | if severity.lower() == "enhancement":
|
---|
339 | severity = "minor"
|
---|
340 | type = "enhancement"
|
---|
341 |
|
---|
342 | else:
|
---|
343 | if priority.lower() == "enhancement":
|
---|
344 | priority = "minor"
|
---|
345 | type = "enhancement"
|
---|
346 |
|
---|
347 | if PREFORMAT_COMMENTS:
|
---|
348 | desc = '{{{\n%s\n}}}' % desc
|
---|
349 |
|
---|
350 | if REPLACE_BUG_NO:
|
---|
351 | if BUG_NO_RE.search(desc):
|
---|
352 | desc = re.sub(BUG_NO_RE, BUG_NO_REPL, desc)
|
---|
353 |
|
---|
354 | if PRIORITIES_MAP.has_key(priority):
|
---|
355 | priority = PRIORITIES_MAP[priority]
|
---|
356 |
|
---|
357 | print " inserting ticket %s -- %s" % (id, summary)
|
---|
358 |
|
---|
359 | c.execute("""INSERT INTO ticket (id, type, time, changetime, component,
|
---|
360 | severity, priority, owner, reporter,
|
---|
361 | cc, version, milestone, status,
|
---|
362 | resolution, summary, description,
|
---|
363 | keywords)
|
---|
364 | VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s,
|
---|
365 | %s, %s, %s, %s, %s, %s, %s, %s)""",
|
---|
366 | (id, type.encode('utf-8'), datetime2epoch(time),
|
---|
367 | datetime2epoch(changetime), component.encode('utf-8'),
|
---|
368 | severity.encode('utf-8'), priority.encode('utf-8'), owner,
|
---|
369 | reporter, cc, version, milestone.encode('utf-8'),
|
---|
370 | status.lower(), resolution, summary.encode('utf-8'), desc,
|
---|
371 | keywords))
|
---|
372 |
|
---|
373 | self.db().commit()
|
---|
374 | if self.using_postgres:
|
---|
375 | c.execute("""SELECT SETVAL('ticket_id_seq', MAX(id)) FROM ticket;
|
---|
376 | SELECT SETVAL('report_id_seq', MAX(id)) FROM report""")
|
---|
377 | ticket_id = self.db().get_last_id(c, 'ticket')
|
---|
378 |
|
---|
379 | # add all custom fields to ticket
|
---|
380 | for name, value in customfields.iteritems():
|
---|
381 | self.addTicketCustomField(ticket_id, name, value)
|
---|
382 |
|
---|
383 | return ticket_id
|
---|
384 |
|
---|
385 | def addTicketCustomField(self, ticket_id, field_name, field_value):
|
---|
386 | c = self.db().cursor()
|
---|
387 |
|
---|
388 | if field_value == None:
|
---|
389 | return
|
---|
390 |
|
---|
391 | c.execute("""INSERT INTO ticket_custom (ticket, name, value)
|
---|
392 | VALUES (%s, %s, %s)""",
|
---|
393 | (ticket_id, field_name.encode('utf-8'), field_value.encode('utf-8')))
|
---|
394 |
|
---|
395 | self.db().commit()
|
---|
396 |
|
---|
397 | def addTicketComment(self, ticket, time, author, value):
|
---|
398 | comment = value.encode('utf-8')
|
---|
399 |
|
---|
400 | if PREFORMAT_COMMENTS:
|
---|
401 | comment = '{{{\n%s\n}}}' % comment
|
---|
402 |
|
---|
403 | if REPLACE_BUG_NO:
|
---|
404 | if BUG_NO_RE.search(comment):
|
---|
405 | comment = re.sub(BUG_NO_RE, BUG_NO_REPL, comment)
|
---|
406 |
|
---|
407 | c = self.db().cursor()
|
---|
408 | c.execute("""INSERT INTO ticket_change (ticket, time, author, field,
|
---|
409 | oldvalue, newvalue)
|
---|
410 | VALUES (%s, %s, %s, %s, %s, %s)""",
|
---|
411 | (ticket, datetime2epoch(time), author, 'comment', '', comment))
|
---|
412 | self.db().commit()
|
---|
413 |
|
---|
414 | def addTicketChange(self, ticket, time, author, field, oldvalue, newvalue):
|
---|
415 | c = self.db().cursor()
|
---|
416 |
|
---|
417 | if field == "owner":
|
---|
418 | if LOGIN_MAP.has_key(oldvalue):
|
---|
419 | oldvalue = LOGIN_MAP[oldvalue]
|
---|
420 | if LOGIN_MAP.has_key(newvalue):
|
---|
421 | newvalue = LOGIN_MAP[newvalue]
|
---|
422 |
|
---|
423 | if field == "priority":
|
---|
424 | if PRIORITIES_MAP.has_key(oldvalue.lower()):
|
---|
425 | oldvalue = PRIORITIES_MAP[oldvalue.lower()]
|
---|
426 | if PRIORITIES_MAP.has_key(newvalue.lower()):
|
---|
427 | newvalue = PRIORITIES_MAP[newvalue.lower()]
|
---|
428 |
|
---|
429 | # Doesn't make sense if we go from highest -> highest, for example.
|
---|
430 | if oldvalue == newvalue:
|
---|
431 | return
|
---|
432 |
|
---|
433 | c.execute("""INSERT INTO ticket_change (ticket, time, author, field,
|
---|
434 | oldvalue, newvalue)
|
---|
435 | VALUES (%s, %s, %s, %s, %s, %s)""",
|
---|
436 | (ticket, datetime2epoch(time), author, field,
|
---|
437 | oldvalue.encode('utf-8'), newvalue.encode('utf-8')))
|
---|
438 | self.db().commit()
|
---|
439 |
|
---|
440 | def addAttachment(self, author, a):
|
---|
441 | if a['filename'] != '':
|
---|
442 | description = a['description'].encode('utf-8')
|
---|
443 | id = a['bug_id']
|
---|
444 | filename = a['filename'].encode('utf-8')
|
---|
445 | filedata = StringIO.StringIO(a['thedata'])
|
---|
446 | filesize = len(filedata.getvalue())
|
---|
447 | time = a['creation_ts']
|
---|
448 | print " ->inserting attachment '%s' for ticket %s -- %s" % \
|
---|
449 | (filename, id, description)
|
---|
450 | attachment = Attachment(self.env, 'ticket', id)
|
---|
451 | attachment.author = author
|
---|
452 | attachment.description = description
|
---|
453 | attachment.insert(filename, filedata, filesize, datetime2epoch(time))
|
---|
454 | del attachment
|
---|
455 |
|
---|
456 | def getLoginName(self, cursor, userid):
|
---|
457 | if userid not in self.loginNameCache:
|
---|
458 | cursor.execute("SELECT * FROM profiles WHERE userid = %s", (userid))
|
---|
459 | loginName = cursor.fetchall()
|
---|
460 |
|
---|
461 | if loginName:
|
---|
462 | loginName = loginName[0]['login_name']
|
---|
463 | else:
|
---|
464 | print """WARNING: unknown bugzilla userid %d, recording as
|
---|
465 | anonymous""" % (userid)
|
---|
466 | loginName = "anonymous"
|
---|
467 |
|
---|
468 | loginName = LOGIN_MAP.get(loginName, loginName)
|
---|
469 |
|
---|
470 | self.loginNameCache[userid] = loginName
|
---|
471 |
|
---|
472 | return self.loginNameCache[userid]
|
---|
473 |
|
---|
474 | def getFieldName(self, cursor, fieldid):
|
---|
475 | if fieldid not in self.fieldNameCache:
|
---|
476 | # fielddefs.fieldid got changed to fielddefs.id in Bugzilla
|
---|
477 | # 2.23.3.
|
---|
478 | if BZ_VERSION >= 2233:
|
---|
479 | cursor.execute("SELECT * FROM fielddefs WHERE id = %s",
|
---|
480 | (fieldid))
|
---|
481 | else:
|
---|
482 | cursor.execute("SELECT * FROM fielddefs WHERE fieldid = %s",
|
---|
483 | (fieldid))
|
---|
484 | fieldName = cursor.fetchall()
|
---|
485 |
|
---|
486 | if fieldName:
|
---|
487 | fieldName = fieldName[0]['name'].lower()
|
---|
488 | else:
|
---|
489 | print "WARNING: unknown bugzilla fieldid %d, \
|
---|
490 | recording as unknown" % (userid)
|
---|
491 | fieldName = "unknown"
|
---|
492 |
|
---|
493 | self.fieldNameCache[fieldid] = fieldName
|
---|
494 |
|
---|
495 | return self.fieldNameCache[fieldid]
|
---|
496 |
|
---|
497 | def makeWhereClause(fieldName, values, negative=False):
|
---|
498 | if not values:
|
---|
499 | return ''
|
---|
500 | if negative:
|
---|
501 | connector, op = ' AND ', '!='
|
---|
502 | else:
|
---|
503 | connector, op = ' OR ', '='
|
---|
504 | clause = connector.join(["%s %s '%s'" % (fieldName, op, value)
|
---|
505 | for value in values])
|
---|
506 | return ' (' + clause + ')'
|
---|
507 |
|
---|
508 | def convert(_db, _host, _user, _password, _env, _force):
|
---|
509 | activityFields = FieldTranslator()
|
---|
510 |
|
---|
511 | # account for older versions of bugzilla
|
---|
512 | print "Using Bugzilla v%s schema." % BZ_VERSION
|
---|
513 | if BZ_VERSION == 2110:
|
---|
514 | activityFields['removed'] = "oldvalue"
|
---|
515 | activityFields['added'] = "newvalue"
|
---|
516 |
|
---|
517 | # init Bugzilla environment
|
---|
518 | print "Bugzilla MySQL('%s':'%s':'%s':'%s'): connecting..." % \
|
---|
519 | (_db, _host, _user, ("*" * len(_password)))
|
---|
520 | mysql_con = MySQLdb.connect(host=_host,
|
---|
521 | user=_user, passwd=_password, db=_db, compress=1,
|
---|
522 | cursorclass=MySQLdb.cursors.DictCursor)
|
---|
523 | mysql_cur = mysql_con.cursor()
|
---|
524 |
|
---|
525 | # init Trac environment
|
---|
526 | print "Trac SQLite('%s'): connecting..." % (_env)
|
---|
527 | trac = TracDatabase(_env)
|
---|
528 |
|
---|
529 | # force mode...
|
---|
530 | if _force == 1:
|
---|
531 | print "\nCleaning all tickets..."
|
---|
532 | c = trac.db().cursor()
|
---|
533 | c.execute("DELETE FROM ticket_change")
|
---|
534 | trac.db().commit()
|
---|
535 |
|
---|
536 | c.execute("DELETE FROM ticket")
|
---|
537 | trac.db().commit()
|
---|
538 |
|
---|
539 | c.execute("DELETE FROM ticket_custom")
|
---|
540 | trac.db().commit()
|
---|
541 |
|
---|
542 | c.execute("DELETE FROM attachment")
|
---|
543 | attachments_dir = os.path.join(os.path.normpath(trac.env.path),
|
---|
544 | "attachments")
|
---|
545 | # Straight from the Python documentation.
|
---|
546 | for root, dirs, files in os.walk(attachments_dir, topdown=False):
|
---|
547 | for name in files:
|
---|
548 | os.remove(os.path.join(root, name))
|
---|
549 | for name in dirs:
|
---|
550 | os.rmdir(os.path.join(root, name))
|
---|
551 | if not os.stat(attachments_dir):
|
---|
552 | os.mkdir(attachments_dir)
|
---|
553 | trac.db().commit()
|
---|
554 | print "All tickets cleaned..."
|
---|
555 |
|
---|
556 |
|
---|
557 | print "\n0. Filtering products..."
|
---|
558 | if BZ_VERSION >= 2180:
|
---|
559 | mysql_cur.execute("SELECT name FROM products")
|
---|
560 | else:
|
---|
561 | mysql_cur.execute("SELECT product AS name FROM products")
|
---|
562 | products = []
|
---|
563 | for line in mysql_cur.fetchall():
|
---|
564 | product = line['name']
|
---|
565 | if PRODUCTS and product not in PRODUCTS:
|
---|
566 | continue
|
---|
567 | if product in IGNORE_PRODUCTS:
|
---|
568 | continue
|
---|
569 | products.append(product)
|
---|
570 | PRODUCTS[:] = products
|
---|
571 | print " Using products", " ".join(PRODUCTS)
|
---|
572 |
|
---|
573 | print "\n1. Import severities..."
|
---|
574 | trac.setSeverityList(SEVERITIES)
|
---|
575 |
|
---|
576 | print "\n2. Import components..."
|
---|
577 | if not COMPONENTS_FROM_PRODUCTS:
|
---|
578 | if BZ_VERSION >= 2180:
|
---|
579 | sql = """SELECT DISTINCT c.name AS name, c.initialowner AS owner
|
---|
580 | FROM components AS c, products AS p
|
---|
581 | WHERE c.product_id = p.id AND"""
|
---|
582 | sql += makeWhereClause('p.name', PRODUCTS)
|
---|
583 | else:
|
---|
584 | sql = "SELECT value AS name, initialowner AS owner FROM components"
|
---|
585 | sql += " WHERE" + makeWhereClause('program', PRODUCTS)
|
---|
586 | mysql_cur.execute(sql)
|
---|
587 | components = mysql_cur.fetchall()
|
---|
588 | for component in components:
|
---|
589 | component['owner'] = trac.getLoginName(mysql_cur,
|
---|
590 | component['owner'])
|
---|
591 | trac.setComponentList(components, 'name')
|
---|
592 | else:
|
---|
593 | if BZ_VERSION >= 2180:
|
---|
594 | sql = ("SELECT p.name AS product, c.name AS comp, "
|
---|
595 | " c.initialowner AS owner "
|
---|
596 | "FROM components c, products p "
|
---|
597 | "WHERE c.product_id = p.id AND" +
|
---|
598 | makeWhereClause('p.name', PRODUCTS))
|
---|
599 | else:
|
---|
600 | sql = ("SELECT program AS product, value AS comp, "
|
---|
601 | " initialowner AS owner "
|
---|
602 | "FROM components WHERE" +
|
---|
603 | makeWhereClause('program', PRODUCTS))
|
---|
604 | mysql_cur.execute(sql)
|
---|
605 | lines = mysql_cur.fetchall()
|
---|
606 | all_components = {} # product -> components
|
---|
607 | all_owners = {} # product, component -> owner
|
---|
608 | for line in lines:
|
---|
609 | product = line['product']
|
---|
610 | comp = line['comp']
|
---|
611 | owner = line['owner']
|
---|
612 | all_components.setdefault(product, []).append(comp)
|
---|
613 | all_owners[(product, comp)] = owner
|
---|
614 | component_list = []
|
---|
615 | for product, components in all_components.items():
|
---|
616 | # find best default owner
|
---|
617 | default = None
|
---|
618 | for comp in DEFAULT_COMPONENTS:
|
---|
619 | if comp in components:
|
---|
620 | default = comp
|
---|
621 | break
|
---|
622 | if default is None:
|
---|
623 | default = components[0]
|
---|
624 | owner = all_owners[(product, default)]
|
---|
625 | owner_name = trac.getLoginName(mysql_cur, owner)
|
---|
626 | component_list.append({'product': product, 'owner': owner_name})
|
---|
627 | trac.setComponentList(component_list, 'product')
|
---|
628 |
|
---|
629 | print "\n3. Import priorities..."
|
---|
630 | trac.setPriorityList(PRIORITIES)
|
---|
631 |
|
---|
632 | print "\n4. Import versions..."
|
---|
633 | if BZ_VERSION >= 2180:
|
---|
634 | sql = """SELECT DISTINCTROW v.value AS value
|
---|
635 | FROM products p, versions v"""
|
---|
636 | sql += " WHERE v.product_id = p.id AND"
|
---|
637 | sql += makeWhereClause('p.name', PRODUCTS)
|
---|
638 | else:
|
---|
639 | sql = "SELECT DISTINCTROW value FROM versions"
|
---|
640 | sql += " WHERE" + makeWhereClause('program', PRODUCTS)
|
---|
641 | mysql_cur.execute(sql)
|
---|
642 | versions = mysql_cur.fetchall()
|
---|
643 | trac.setVersionList(versions, 'value')
|
---|
644 |
|
---|
645 | print "\n5. Import milestones..."
|
---|
646 | sql = "SELECT DISTINCT value FROM milestones"
|
---|
647 | sql += " WHERE" + makeWhereClause('value', IGNORE_MILESTONES, negative=True)
|
---|
648 | mysql_cur.execute(sql)
|
---|
649 | milestones = mysql_cur.fetchall()
|
---|
650 | trac.setMilestoneList(milestones, 'value')
|
---|
651 |
|
---|
652 | print "\n6. Retrieving bugs..."
|
---|
653 | if BZ_VERSION >= 2180:
|
---|
654 | sql = """SELECT DISTINCT b.*, c.name AS component, p.name AS product
|
---|
655 | FROM bugs AS b, components AS c, products AS p """
|
---|
656 | sql += " WHERE" + makeWhereClause('p.name', PRODUCTS)
|
---|
657 | sql += " AND b.product_id = p.id"
|
---|
658 | sql += " AND b.component_id = c.id"
|
---|
659 | sql += " ORDER BY b.bug_id"
|
---|
660 | else:
|
---|
661 | sql = """SELECT DISTINCT b.*, c.value AS component, p.product AS product
|
---|
662 | FROM bugs AS b, components AS c, products AS p """
|
---|
663 | sql += " WHERE" + makeWhereClause('p.product', PRODUCTS)
|
---|
664 | sql += " AND b.product = p.product"
|
---|
665 | sql += " AND b.component = c.value"
|
---|
666 | sql += " ORDER BY b.bug_id"
|
---|
667 | mysql_cur.execute(sql)
|
---|
668 | bugs = mysql_cur.fetchall()
|
---|
669 |
|
---|
670 |
|
---|
671 | print "\n7. Import bugs and bug activity..."
|
---|
672 | for bug in bugs:
|
---|
673 |
|
---|
674 | bugid = bug['bug_id']
|
---|
675 |
|
---|
676 | ticket = {}
|
---|
677 | keywords = []
|
---|
678 | ticket['id'] = bugid
|
---|
679 | ticket['time'] = bug['creation_ts']
|
---|
680 | ticket['changetime'] = bug['delta_ts']
|
---|
681 | if COMPONENTS_FROM_PRODUCTS:
|
---|
682 | ticket['component'] = bug['product']
|
---|
683 | else:
|
---|
684 | ticket['component'] = bug['component']
|
---|
685 |
|
---|
686 | if SEVERITIES:
|
---|
687 | ticket['severity'] = bug['bug_severity']
|
---|
688 | ticket['priority'] = bug['priority'].lower()
|
---|
689 | else:
|
---|
690 | # use bugzilla severities as trac priorities, and ignore bugzilla
|
---|
691 | # priorities
|
---|
692 | ticket['severity'] = ''
|
---|
693 | ticket['priority'] = bug['bug_severity']
|
---|
694 |
|
---|
695 | ticket['owner'] = trac.getLoginName(mysql_cur, bug['assigned_to'])
|
---|
696 | ticket['reporter'] = trac.getLoginName(mysql_cur, bug['reporter'])
|
---|
697 |
|
---|
698 | # pack bugzilla fields into dictionary of trac custom field
|
---|
699 | # names and values
|
---|
700 | customfields = {}
|
---|
701 | for bugfield, customfield in CUSTOMFIELD_MAP.iteritems():
|
---|
702 | customfields[customfield] = bug[bugfield]
|
---|
703 | ticket['customfields'] = customfields
|
---|
704 |
|
---|
705 | mysql_cur.execute("SELECT * FROM cc WHERE bug_id = %s", bugid)
|
---|
706 | cc_records = mysql_cur.fetchall()
|
---|
707 | cc_list = []
|
---|
708 | for cc in cc_records:
|
---|
709 | cc_list.append(trac.getLoginName(mysql_cur, cc['who']))
|
---|
710 | cc_list = [cc for cc in cc_list if cc not in IGNORE_CC]
|
---|
711 | ticket['cc'] = string.join(cc_list, ', ')
|
---|
712 |
|
---|
713 | ticket['version'] = bug['version']
|
---|
714 |
|
---|
715 | target_milestone = bug['target_milestone']
|
---|
716 | if target_milestone in IGNORE_MILESTONES:
|
---|
717 | target_milestone = ''
|
---|
718 | ticket['milestone'] = target_milestone
|
---|
719 |
|
---|
720 | bug_status = bug['bug_status'].lower()
|
---|
721 | ticket['status'] = statusXlator[bug_status]
|
---|
722 | ticket['resolution'] = bug['resolution'].lower()
|
---|
723 |
|
---|
724 | # a bit of extra work to do open tickets
|
---|
725 | if bug_status == 'open':
|
---|
726 | if owner != '':
|
---|
727 | ticket['status'] = 'assigned'
|
---|
728 | else:
|
---|
729 | ticket['status'] = 'new'
|
---|
730 |
|
---|
731 | ticket['summary'] = bug['short_desc']
|
---|
732 |
|
---|
733 | mysql_cur.execute("SELECT * FROM longdescs WHERE bug_id = %s" % bugid)
|
---|
734 | longdescs = list(mysql_cur.fetchall())
|
---|
735 |
|
---|
736 | # check for empty 'longdescs[0]' field...
|
---|
737 | if len(longdescs) == 0:
|
---|
738 | ticket['description'] = ''
|
---|
739 | else:
|
---|
740 | ticket['description'] = longdescs[0]['thetext']
|
---|
741 | del longdescs[0]
|
---|
742 |
|
---|
743 | for desc in longdescs:
|
---|
744 | ignore = False
|
---|
745 | for comment in IGNORE_COMMENTS:
|
---|
746 | if re.match(comment, desc['thetext']):
|
---|
747 | ignore = True
|
---|
748 |
|
---|
749 | if ignore:
|
---|
750 | continue
|
---|
751 |
|
---|
752 | trac.addTicketComment(ticket=bugid,
|
---|
753 | time = desc['bug_when'],
|
---|
754 | author=trac.getLoginName(mysql_cur, desc['who']),
|
---|
755 | value = desc['thetext'])
|
---|
756 |
|
---|
757 | mysql_cur.execute("""SELECT * FROM bugs_activity WHERE bug_id = %s
|
---|
758 | ORDER BY bug_when""" % bugid)
|
---|
759 | bugs_activity = mysql_cur.fetchall()
|
---|
760 | resolution = ''
|
---|
761 | ticketChanges = []
|
---|
762 | keywords = []
|
---|
763 | for activity in bugs_activity:
|
---|
764 | field_name = trac.getFieldName(mysql_cur, activity['fieldid']).lower()
|
---|
765 |
|
---|
766 | removed = activity[activityFields['removed']]
|
---|
767 | added = activity[activityFields['added']]
|
---|
768 |
|
---|
769 | # statuses and resolutions are in lowercase in trac
|
---|
770 | if field_name == "resolution" or field_name == "bug_status":
|
---|
771 | removed = removed.lower()
|
---|
772 | added = added.lower()
|
---|
773 |
|
---|
774 | # remember most recent resolution, we need this later
|
---|
775 | if field_name == "resolution":
|
---|
776 | resolution = added.lower()
|
---|
777 |
|
---|
778 | add_keywords = []
|
---|
779 | remove_keywords = []
|
---|
780 |
|
---|
781 | # convert bugzilla field names...
|
---|
782 | if field_name == "bug_severity":
|
---|
783 | if SEVERITIES:
|
---|
784 | field_name = "severity"
|
---|
785 | else:
|
---|
786 | field_name = "priority"
|
---|
787 | elif field_name == "assigned_to":
|
---|
788 | field_name = "owner"
|
---|
789 | elif field_name == "bug_status":
|
---|
790 | field_name = "status"
|
---|
791 | if removed in STATUS_KEYWORDS:
|
---|
792 | remove_keywords.append(STATUS_KEYWORDS[removed])
|
---|
793 | if added in STATUS_KEYWORDS:
|
---|
794 | add_keywords.append(STATUS_KEYWORDS[added])
|
---|
795 | added = statusXlator[added]
|
---|
796 | removed = statusXlator[removed]
|
---|
797 | elif field_name == "short_desc":
|
---|
798 | field_name = "summary"
|
---|
799 | elif field_name == "product" and COMPONENTS_FROM_PRODUCTS:
|
---|
800 | field_name = "component"
|
---|
801 | elif ((field_name == "product" and not COMPONENTS_FROM_PRODUCTS) or
|
---|
802 | (field_name == "component" and COMPONENTS_FROM_PRODUCTS)):
|
---|
803 | if MAP_ALL_KEYWORDS or removed in KEYWORDS_MAPPING:
|
---|
804 | kw = KEYWORDS_MAPPING.get(removed, removed)
|
---|
805 | if kw:
|
---|
806 | remove_keywords.append(kw)
|
---|
807 | if MAP_ALL_KEYWORDS or added in KEYWORDS_MAPPING:
|
---|
808 | kw = KEYWORDS_MAPPING.get(added, added)
|
---|
809 | if kw:
|
---|
810 | add_keywords.append(kw)
|
---|
811 | if field_name == "component":
|
---|
812 | # just keep the keyword change
|
---|
813 | added = removed = ""
|
---|
814 | elif field_name == "target_milestone":
|
---|
815 | field_name = "milestone"
|
---|
816 | if added in IGNORE_MILESTONES:
|
---|
817 | added = ""
|
---|
818 | if removed in IGNORE_MILESTONES:
|
---|
819 | removed = ""
|
---|
820 |
|
---|
821 | ticketChange = {}
|
---|
822 | ticketChange['ticket'] = bugid
|
---|
823 | ticketChange['time'] = activity['bug_when']
|
---|
824 | ticketChange['author'] = trac.getLoginName(mysql_cur,
|
---|
825 | activity['who'])
|
---|
826 | ticketChange['field'] = field_name
|
---|
827 | ticketChange['oldvalue'] = removed
|
---|
828 | ticketChange['newvalue'] = added
|
---|
829 |
|
---|
830 | if add_keywords or remove_keywords:
|
---|
831 | # ensure removed ones are in old
|
---|
832 | old_keywords = keywords + [kw for kw in remove_keywords if kw
|
---|
833 | not in keywords]
|
---|
834 | # remove from new
|
---|
835 | keywords = [kw for kw in keywords if kw not in remove_keywords]
|
---|
836 | # add to new
|
---|
837 | keywords += [kw for kw in add_keywords if kw not in keywords]
|
---|
838 | if old_keywords != keywords:
|
---|
839 | ticketChangeKw = ticketChange.copy()
|
---|
840 | ticketChangeKw['field'] = "keywords"
|
---|
841 | ticketChangeKw['oldvalue'] = ' '.join(old_keywords)
|
---|
842 | ticketChangeKw['newvalue'] = ' '.join(keywords)
|
---|
843 | ticketChanges.append(ticketChangeKw)
|
---|
844 |
|
---|
845 | if field_name in IGNORED_ACTIVITY_FIELDS:
|
---|
846 | continue
|
---|
847 |
|
---|
848 | # Skip changes that have no effect (think translation!).
|
---|
849 | if added == removed:
|
---|
850 | continue
|
---|
851 |
|
---|
852 | # Bugzilla splits large summary changes into two records.
|
---|
853 | for oldChange in ticketChanges:
|
---|
854 | if (field_name == "summary"
|
---|
855 | and oldChange['field'] == ticketChange['field']
|
---|
856 | and oldChange['time'] == ticketChange['time']
|
---|
857 | and oldChange['author'] == ticketChange['author']):
|
---|
858 | oldChange['oldvalue'] += " " + ticketChange['oldvalue']
|
---|
859 | oldChange['newvalue'] += " " + ticketChange['newvalue']
|
---|
860 | break
|
---|
861 | # cc and attachments.isobsolete sometime appear
|
---|
862 | # in different activities with same time
|
---|
863 | if ((field_name == "cc" or field_name == "attachments.isobsolete") \
|
---|
864 | and oldChange['time'] == ticketChange['time']):
|
---|
865 | oldChange['newvalue'] += ", " + ticketChange['newvalue']
|
---|
866 | break
|
---|
867 | else:
|
---|
868 | ticketChanges.append (ticketChange)
|
---|
869 |
|
---|
870 | for ticketChange in ticketChanges:
|
---|
871 | trac.addTicketChange (**ticketChange)
|
---|
872 |
|
---|
873 | # For some reason, bugzilla v2.11 seems to clear the resolution
|
---|
874 | # when you mark a bug as closed. Let's remember it and restore
|
---|
875 | # it if the ticket is closed but there's no resolution.
|
---|
876 | if not ticket['resolution'] and ticket['status'] == "closed":
|
---|
877 | ticket['resolution'] = resolution
|
---|
878 |
|
---|
879 | bug_status = bug['bug_status']
|
---|
880 | if bug_status in STATUS_KEYWORDS:
|
---|
881 | kw = STATUS_KEYWORDS[bug_status]
|
---|
882 | if kw not in keywords:
|
---|
883 | keywords.append(kw)
|
---|
884 |
|
---|
885 | product = bug['product']
|
---|
886 | if product in KEYWORDS_MAPPING and not COMPONENTS_FROM_PRODUCTS:
|
---|
887 | kw = KEYWORDS_MAPPING.get(product, product)
|
---|
888 | if kw and kw not in keywords:
|
---|
889 | keywords.append(kw)
|
---|
890 |
|
---|
891 | component = bug['component']
|
---|
892 | if (COMPONENTS_FROM_PRODUCTS and \
|
---|
893 | (MAP_ALL_KEYWORDS or component in KEYWORDS_MAPPING)):
|
---|
894 | kw = KEYWORDS_MAPPING.get(component, component)
|
---|
895 | if kw and kw not in keywords:
|
---|
896 | keywords.append(kw)
|
---|
897 |
|
---|
898 | ticket['keywords'] = string.join(keywords)
|
---|
899 | ticketid = trac.addTicket(**ticket)
|
---|
900 |
|
---|
901 | if BZ_VERSION >= 2210:
|
---|
902 | mysql_cur.execute("SELECT attachments.*, attach_data.thedata "
|
---|
903 | "FROM attachments, attach_data "
|
---|
904 | "WHERE attachments.bug_id = %s AND "
|
---|
905 | "attachments.attach_id = attach_data.id" % bugid)
|
---|
906 | else:
|
---|
907 | mysql_cur.execute("SELECT * FROM attachments WHERE bug_id = %s" %
|
---|
908 | bugid)
|
---|
909 | attachments = mysql_cur.fetchall()
|
---|
910 | for a in attachments:
|
---|
911 | author = trac.getLoginName(mysql_cur, a['submitter_id'])
|
---|
912 | trac.addAttachment(author, a)
|
---|
913 |
|
---|
914 | print "\n8. Importing users and passwords..."
|
---|
915 | if BZ_VERSION >= 2167:
|
---|
916 | selectlogins = "SELECT login_name, cryptpassword FROM profiles";
|
---|
917 | if IGNORE_DISABLED_USERS:
|
---|
918 | selectlogins = selectlogins + " WHERE disabledtext=''"
|
---|
919 | mysql_cur.execute(selectlogins)
|
---|
920 | users = mysql_cur.fetchall()
|
---|
921 | htpasswd = file("htpasswd", 'w')
|
---|
922 | for user in users:
|
---|
923 | if LOGIN_MAP.has_key(user['login_name']):
|
---|
924 | login = LOGIN_MAP[user['login_name']]
|
---|
925 | else:
|
---|
926 | login = user['login_name']
|
---|
927 |
|
---|
928 | htpasswd.write(login + ":" + user['cryptpassword'] + "\n")
|
---|
929 |
|
---|
930 | htpasswd.close()
|
---|
931 | print " Bugzilla users converted to htpasswd format, see 'htpasswd'."
|
---|
932 |
|
---|
933 | print "\nAll tickets converted."
|
---|
934 |
|
---|
935 | def log(msg):
|
---|
936 | print "DEBUG: %s" % (msg)
|
---|
937 |
|
---|
938 | def datetime2epoch(dt) :
|
---|
939 | import time
|
---|
940 | return time.mktime(dt.timetuple())
|
---|
941 |
|
---|
942 | def usage():
|
---|
943 | print """bugzilla2trac - Imports a bug database from Bugzilla into Trac.
|
---|
944 |
|
---|
945 | Usage: bugzilla2trac.py [options]
|
---|
946 |
|
---|
947 | Available Options:
|
---|
948 | --db <MySQL dbname> - Bugzilla's database name
|
---|
949 | --tracenv /path/to/trac/env - Full path to Trac db environment
|
---|
950 | -h | --host <MySQL hostname> - Bugzilla's DNS host name
|
---|
951 | -u | --user <MySQL username> - Effective Bugzilla's database user
|
---|
952 | -p | --passwd <MySQL password> - Bugzilla's user password
|
---|
953 | -c | --clean - Remove current Trac tickets before
|
---|
954 | importing
|
---|
955 | -n | --noseverities - import Bugzilla severities as Trac
|
---|
956 | priorities and forget Bugzilla priorities
|
---|
957 | --help | help - This help info
|
---|
958 |
|
---|
959 | Additional configuration options can be defined directly in the script.
|
---|
960 | """
|
---|
961 | sys.exit(0)
|
---|
962 |
|
---|
963 | def main():
|
---|
964 | global BZ_DB, BZ_HOST, BZ_USER, BZ_PASSWORD, TRAC_ENV, TRAC_CLEAN
|
---|
965 | global SEVERITIES, PRIORITIES, PRIORITIES_MAP
|
---|
966 | if len (sys.argv) > 1:
|
---|
967 | if sys.argv[1] in ['--help','help'] or len(sys.argv) < 4:
|
---|
968 | usage()
|
---|
969 | iter = 1
|
---|
970 | while iter < len(sys.argv):
|
---|
971 | if sys.argv[iter] in ['--db'] and iter+1 < len(sys.argv):
|
---|
972 | BZ_DB = sys.argv[iter+1]
|
---|
973 | iter = iter + 1
|
---|
974 | elif sys.argv[iter] in ['-h', '--host'] and iter+1 < len(sys.argv):
|
---|
975 | BZ_HOST = sys.argv[iter+1]
|
---|
976 | iter = iter + 1
|
---|
977 | elif sys.argv[iter] in ['-u', '--user'] and iter+1 < len(sys.argv):
|
---|
978 | BZ_USER = sys.argv[iter+1]
|
---|
979 | iter = iter + 1
|
---|
980 | elif sys.argv[iter] in ['-p', '--passwd'] and iter+1 < len(sys.argv):
|
---|
981 | BZ_PASSWORD = sys.argv[iter+1]
|
---|
982 | iter = iter + 1
|
---|
983 | elif sys.argv[iter] in ['--tracenv'] and iter+1 < len(sys.argv):
|
---|
984 | TRAC_ENV = sys.argv[iter+1]
|
---|
985 | iter = iter + 1
|
---|
986 | elif sys.argv[iter] in ['-c', '--clean']:
|
---|
987 | TRAC_CLEAN = 1
|
---|
988 | elif sys.argv[iter] in ['-n', '--noseverities']:
|
---|
989 | # treat Bugzilla severites as Trac priorities
|
---|
990 | PRIORITIES = SEVERITIES
|
---|
991 | SEVERITIES = []
|
---|
992 | PRIORITIES_MAP = {}
|
---|
993 | else:
|
---|
994 | print "Error: unknown parameter: " + sys.argv[iter]
|
---|
995 | sys.exit(0)
|
---|
996 | iter = iter + 1
|
---|
997 |
|
---|
998 | convert(BZ_DB, BZ_HOST, BZ_USER, BZ_PASSWORD, TRAC_ENV, TRAC_CLEAN)
|
---|
999 |
|
---|
1000 | if __name__ == '__main__':
|
---|
1001 | main()
|
---|