Migrating from Trac to Launchpad

Published: Sep 1, 2007

I love trac. LOVE it. With the recent exaile.org hack, however, I wanted my bugs and code to be in a place that isn’t going anywhere soon. I chose Launchpad.

I was faced with a problem – all of our bugs were in trac. Lots and lots of bugs. I had to somehow migrate them from trac to Launchpad, so I wrote up a script to do so fairly painlessly. You use it like this:

$ ./trac2lp lpusername lppassword project /path/to/trac.db

Here’s the script:

#!/usr/bin/env python
from pysqlite2 import dbapi2 as sqlite
from mechanize import Browser
import sys

try:
    username = sys.argv[1]
    password = sys.argv[2]
    project = sys.argv[3]
    db_location = sys.argv[4]
except:
    print "Useage: trac2lp.py username password project trac.db"
    sys.exit(1)

br = Browser()
br.open("https://launchpad.net/+login")
br.select_form(name="login")
br["loginpage_email"] = username
br["loginpage_password"] = password
response = br.submit()

db = sqlite.connect(db_location)
cur = db.cursor()
cur.execute("SELECT id, summary, reporter, description FROM "
    "ticket WHERE resolution IS NULL ORDER BY id ASC")

# Here, we can keep track of tickets that have already been processed so that
# if something goes wrong, they don’t get processed again
tickets = []
for line in open("tickets.txt").readlines():
    line = line.strip()
    tickets.append(int(line))

h = open("tickets.txt", "a")

for row in cur.fetchall():
    if int(row[0]) in tickets: continue
    h.write("%d" % row[0])

    try:
        br.open("https://launchpad.net/%s/+filebug" % project)
        br.select_form(nr=2)
        br["field.title"] = row[1]
        response = br.submit()

        br.select_form(nr=2)
        br["field.title"] = row[1]
        br["field.comment"] = "%s\n\n\n%s\n%s" % (row[2],
            "This ticket was migrated from the old trac: re #%d" % row[0],
            "Originally reported by: %s" % row[3])

        try:
            br.find_control("field.actions.this_is_my_bug").disabled = True
            control = br.find_control("field.bug_already_reported_as")
            control.items[len(control.items)  1].selected = True
        except:
            pass
        response = br.submit(id="field.actions.submit_bug")
    except:
        pass

Note: This only migrates open tickets.

vim tip: Ron colorscheme

If you’re like me, you are used to having your terminal being a white foreground on a black background. When using vim in a terminal, I’ve found that the default colorscheme is hard on the eyes, or just plain hard to read with a black background. I tried out all the schemes that Vim comes with, and the winner is Ron. Try it: :colorscheme ron. IMHO, much better on the eyes.

Restored from VimTips archive

This article was restored from the VimTips archive. There's probably missing images and broken links (and even some flash references), but it was still important to me to bring them back.


Filed Under: