Edgewall Software

Ticket #1462: bugzilla2trac.py.5.diff

File bugzilla2trac.py.5.diff, 3.6 KB (added by eburghar@…, 3 years ago)

support for bugzilla 2.18.1 (#1972)

  • .py

    old new  
    2626# 
    2727# If you run this script on a version not listed here and it is successful, 
    2828# please report it to the Trac mailing list so we can update the list. 
    29 BZ_VERSION = '2.16.5' 
     29BZ_VERSION = '2.18.1' 
    3030 
    3131# MySQL connection parameters for the Bugzilla database.  These can also 
    3232# be specified on the command line. 
     
    138138        self._db = self.env.get_db_cnx() 
    139139        self._db.autocommit = False 
    140140        self.loginNameCache = {} 
     141        self.componentNameCache = {} 
     142        self.productNameCache = {} 
    141143        self.fieldNameCache = {} 
    142144 
    143145    def db(self): 
     
    283285 
    284286        return self.loginNameCache[userid] 
    285287 
     288    def getComponentName(self, cursor, componentid): 
     289        if componentid not in self.componentNameCache: 
     290            cursor.execute("SELECT * FROM components WHERE id = %s" % componentid) 
     291            componentName = cursor.fetchall() 
     292 
     293            if componentName: 
     294                componentName = componentName[0]['name'] 
     295            else: 
     296                print 'warning: unknown bugzilla component id %d, recording as unknown' % componentid 
     297                componentName = 'unknown' 
     298 
     299            self.componentNameCache[componentid] = componentName 
     300 
     301        return self.componentNameCache[componentid] 
     302 
     303    def getProductName(self, cursor, productid): 
     304        if productid not in self.productNameCache: 
     305            cursor.execute("SELECT * FROM products WHERE id = %s" % productid) 
     306            productName = cursor.fetchall() 
     307 
     308            if productName: 
     309                productName = productName[0]['name'] 
     310            else: 
     311                print 'warning: unknown bugzilla product id %d, recording as unknown' % productid 
     312                productName = 'unknown' 
     313 
     314            self.productNameCache[productid] = productName 
     315 
     316        return self.productNameCache[productid] 
     317 
    286318    def getFieldName(self, cursor, fieldid): 
    287319        if fieldid not in self.fieldNameCache: 
    288320            cursor.execute("SELECT * FROM fielddefs WHERE fieldid = %s" % fieldid) 
     
    350382 
    351383    print 
    352384    print "2. import components..." 
    353     sql = "SELECT value, initialowner AS owner FROM components" 
     385    sql = "SELECT name, initialowner AS owner FROM components" 
    354386    if PRODUCTS: 
    355387       sql += " WHERE %s" % productFilter('program', PRODUCTS) 
    356388    mysql_cur.execute(sql) 
    357389    components = mysql_cur.fetchall() 
    358390    for component in components: 
    359391               component['owner'] = trac.getLoginName(mysql_cur, component['owner']) 
    360     trac.setComponentList(components, 'value') 
     392    trac.setComponentList(components, 'name') 
    361393 
    362394    print 
    363395    print "3. import priorities..." 
     
    401433        ticket['id'] = bugid 
    402434        ticket['time'] = bug['creation_ts'] 
    403435        ticket['changetime'] = bug['delta_ts'] 
    404         ticket['component'] = bug['component'] 
     436        ticket['component'] = trac.getComponentName(mysql_cur, bug['component_id']) 
    405437        ticket['severity'] = bug['bug_severity'] 
    406438        ticket['priority'] = bug['priority'] 
    407439 
     
    574606            if kw not in keywords: 
    575607                keywords.append(kw) 
    576608 
    577         if bug['product'] in PRODUCT_KEYWORDS: 
    578             kw = PRODUCT_KEYWORDS[bug['product']] 
     609        productName = trac.getProductName(mysql_cur, bug['product_id']) 
     610        if productName in PRODUCT_KEYWORDS: 
     611            kw = PRODUCT_KEYWORDS[productName] 
    579612            # may have already been added during activity import 
    580613            if kw not in keywords: 
    581614                keywords.append(kw)