#!/usr/bin/python
import sys
import MySQLdb
try:
conn = MySQLdb.connect (host = "localhost",
user = "bugzilla",
passwd = "qLu2hA8r",
db = "bugzilla")
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit (1)
cursor = conn.cursor ()
cursor.execute ("DROP TABLE IF EXISTS rpmpkg")
# Create a table where we will store the package name and version
cursor.execute ("""
CREATE TABLE rpmpkg
(id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
fullname VARCHAR(256),
package VARCHAR(128),
ver VARCHAR(32)
)
""")
# Fetch full package name from bugzilla db
cursor.execute ("SELECT DISTINCT cf_rpmpkg FROM bugs WHERE cf_rpmpkg IS NOT NULL")
while (1):
row = cursor.fetchone ()
if row == None:
break
# Separate the rpm pkackage into package name and version
row[0].strip()
if len(row[0]) > 0 and row[0].find('-') >= 0:
explode = row[0].rsplit('-', 2)
ok = 1
else:
ok = 0
# DEBUG
#print "fullname: %s package: %s | version: %s" % (row[0], explode[0], explode[1])
# Insert the data into the new table
if ok == 1:
newcursor = conn.cursor()
newcursor.execute ("""
INSERT INTO rpmpkg (fullname, package, ver) VALUES
(%s, %s, %s)
""", (row[0], explode[0], explode[1])
)
newcursor.close()
print "Number of rows returned: %d:w" % cursor.rowcount
# Clean up and commit the changes.
cursor.close ()
conn.commit ()
conn.close ()
|