Commit 2d441de9 authored by Quannah Gibson-Mount's avatar Quannah Gibson-Mount Committed by Dave Miller

Bug 925181: contrib/jb2bz.py was out of date

r=justdave/a=justdave
parent 0b6c84fc
...@@ -17,7 +17,7 @@ This code requires a recent version of Andy Dustman's MySQLdb interface, ...@@ -17,7 +17,7 @@ This code requires a recent version of Andy Dustman's MySQLdb interface,
Share and enjoy. Share and enjoy.
""" """
import rfc822, mimetools, multifile, mimetypes import rfc822, mimetools, multifile, mimetypes, email.utils
import sys, re, glob, StringIO, os, stat, time import sys, re, glob, StringIO, os, stat, time
import MySQLdb, getopt import MySQLdb, getopt
...@@ -91,7 +91,7 @@ def process_reply_file(current, fname): ...@@ -91,7 +91,7 @@ def process_reply_file(current, fname):
reply = open(fname, "r") reply = open(fname, "r")
msg = rfc822.Message(reply) msg = rfc822.Message(reply)
new_note['text'] = "%s\n%s" % (msg['From'], msg.fp.read()) new_note['text'] = "%s\n%s" % (msg['From'], msg.fp.read())
new_note['timestamp'] = rfc822.parsedate_tz(msg['Date']) new_note['timestamp'] = email.utils.parsedate_tz(msg['Date'])
current["notes"].append(new_note) current["notes"].append(new_note)
def add_notes(current): def add_notes(current):
...@@ -129,17 +129,16 @@ def maybe_add_attachment(current, file, submsg): ...@@ -129,17 +129,16 @@ def maybe_add_attachment(current, file, submsg):
def process_mime_body(current, file, submsg): def process_mime_body(current, file, submsg):
data = StringIO.StringIO() data = StringIO.StringIO()
mimetools.decode(file, data, submsg.getencoding()) try:
current['description'] = data.getvalue() mimetools.decode(file, data, submsg.getencoding())
current['description'] = data.getvalue()
except:
return
def process_text_plain(msg, current): def process_text_plain(msg, current):
print "Processing: %d" % current['number']
current['description'] = msg.fp.read() current['description'] = msg.fp.read()
def process_multi_part(file, msg, current): def process_multi_part(file, msg, current):
print "Processing: %d" % current['number']
mf = multifile.MultiFile(file) mf = multifile.MultiFile(file)
mf.push(msg.getparam("boundary")) mf.push(msg.getparam("boundary"))
while mf.next(): while mf.next():
...@@ -160,17 +159,31 @@ def process_jitterbug(filename): ...@@ -160,17 +159,31 @@ def process_jitterbug(filename):
current['date-reported'] = () current['date-reported'] = ()
current['short-description'] = '' current['short-description'] = ''
print "Processing: %d" % current['number']
file = open(filename, "r") file = open(filename, "r")
create_date = os.fstat(file.fileno())
msg = mimetools.Message(file) msg = mimetools.Message(file)
msgtype = msg.gettype() msgtype = msg.gettype()
add_notes(current) add_notes(current)
current['date-reported'] = rfc822.parsedate_tz(msg['Date']) current['date-reported'] = email.utils.parsedate_tz(msg['Date'])
current['short-description'] = msg['Subject'] if current['date-reported'] is None:
current['date-reported'] = time.gmtime(create_date[stat.ST_MTIME])
if current['date-reported'][0] < 1900:
current['date-reported'] = time.gmtime(create_date[stat.ST_MTIME])
if msg.getparam('Subject') is not None:
current['short-description'] = msg['Subject']
else:
current['short-description'] = "Unknown"
if msgtype[:5] == 'text/': if msgtype[:5] == 'text/':
process_text_plain(msg, current) process_text_plain(msg, current)
elif msgtype[:5] == 'text':
process_text_plain(msg, current)
elif msgtype[:10] == "multipart/": elif msgtype[:10] == "multipart/":
process_multi_part(file, msg, current) process_multi_part(file, msg, current)
else: else:
...@@ -200,62 +213,79 @@ def process_jitterbug(filename): ...@@ -200,62 +213,79 @@ def process_jitterbug(filename):
# the resolution will need to be set manually # the resolution will need to be set manually
resolution="" resolution=""
db = MySQLdb.connect(db='bugs',user='root',host='localhost') db = MySQLdb.connect(db='bugs',user='root',host='localhost',passwd='password')
cursor = db.cursor() cursor = db.cursor()
cursor.execute( "INSERT INTO bugs SET " \ try:
"bug_id=%s," \ cursor.execute( "INSERT INTO bugs SET " \
"bug_severity='normal'," \ "bug_id=%s," \
"bug_status=%s," \ "bug_severity='normal'," \
"creation_ts=%s," \ "bug_status=%s," \
"delta_ts=%s," \ "creation_ts=%s," \
"short_desc=%s," \ "delta_ts=%s," \
"product=%s," \ "short_desc=%s," \
"rep_platform='All'," \ "product_id=%s," \
"assigned_to=%s," "rep_platform='All'," \
"reporter=%s," \ "assigned_to=%s," \
"version=%s," \ "reporter=%s," \
"component=%s," \ "version=%s," \
"resolution=%s", "component_id=%s," \
[ current['number'], "resolution=%s",
bug_status, [ current['number'],
time.strftime("%Y-%m-%d %H:%M:%S", current['date-reported'][:9]), bug_status,
time.strftime("%Y-%m-%d %H:%M:%S", current['date-reported'][:9]), time.strftime("%Y-%m-%d %H:%M:%S", current['date-reported'][:9]),
current['short-description'], time.strftime("%Y-%m-%d %H:%M:%S", current['date-reported'][:9]),
product, current['short-description'],
reporter, product,
reporter, reporter,
version, reporter,
component, version,
resolution] ) component,
resolution] )
# This is the initial long description associated with the bug report
cursor.execute( "INSERT INTO longdescs VALUES (%s,%s,%s,%s)", # This is the initial long description associated with the bug report
[ current['number'], cursor.execute( "INSERT INTO longdescs SET " \
reporter, "bug_id=%s," \
time.strftime("%Y-%m-%d %H:%M:%S", current['date-reported'][:9]), "who=%s," \
current['description'] ] ) "bug_when=%s," \
"thetext=%s",
# Add whatever notes are associated with this defect
for n in current['notes']:
cursor.execute( "INSERT INTO longdescs VALUES (%s,%s,%s,%s)",
[current['number'],
reporter,
time.strftime("%Y-%m-%d %H:%M:%S", n['timestamp'][:9]),
n['text']])
# add attachments associated with this defect
for a in current['attachments']:
cursor.execute( "INSERT INTO attachments SET " \
"bug_id=%s, creation_ts=%s, description='', mimetype=%s," \
"filename=%s, submitter_id=%s",
[ current['number'], [ current['number'],
reporter,
time.strftime("%Y-%m-%d %H:%M:%S", current['date-reported'][:9]), time.strftime("%Y-%m-%d %H:%M:%S", current['date-reported'][:9]),
a[1], a[0], reporter ]) current['description'] ] )
cursor.execute( "INSERT INTO attach_data SET " \
"id=LAST_INSERT_ID(), thedata=%s", # Add whatever notes are associated with this defect
[ a[2] ]) for n in current['notes']:
cursor.execute( "INSERT INTO longdescs SET " \
"bug_id=%s," \
"who=%s," \
"bug_when=%s," \
"thetext=%s",
[current['number'],
reporter,
time.strftime("%Y-%m-%d %H:%M:%S", n['timestamp'][:9]),
n['text']])
# add attachments associated with this defect
for a in current['attachments']:
cursor.execute( "INSERT INTO attachments SET " \
"bug_id=%s, creation_ts=%s, description='', mimetype=%s," \
"filename=%s, submitter_id=%s",
[ current['number'],
time.strftime("%Y-%m-%d %H:%M:%S", current['date-reported'][:9]),
a[1], a[0], reporter ])
cursor.execute( "INSERT INTO attach_data SET " \
"id=LAST_INSERT_ID(), thedata=%s",
[ a[2] ])
except MySQLdb.IntegrityError, message:
errorcode = message[0]
if errorcode == 1062: # duplicate
return
else:
raise
cursor.execute("COMMIT")
cursor.close() cursor.close()
db.close() db.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment