In part of my giving back to the Trac community (okay, so it's a little
self-serving too), I spun up the below code to import a CSV file of tickets
into the Trac database.
I don't know if it's a sad reflection on me or a tribute to Python, but the
comments are longer than the code (but took less time to write!)
Will place in /contrib if y'all like it.
Cheers,
:D
--------------------------------------------------------------------
Daragh Fitzpatrick Daragh@UChicago.edu (773) 702-8976
Solutions Architect NSIT Administrative Systems
Renewal Projects and Architecture University of Chicago
--------------------------------------------------------------------
---- cut here ----
"""
csv2trac.py: Import a CSV file into a Trac issue database.
Description:
Imports CSV File with the following format:
id,time,changetime,component,severity,priority,owner,reporter,cc,url,
version,milestone,status,resolution,summary,description,keywords
where:
status = new, assigned, reopened, closed
priority = highest, high, normal, low, lowest
severity = blocker, critical, major, normal, minor, trivial,
enhancement
No smarts, you get to do all the work in the CSV file (sorry!)
Dependencies:
Trac 0.7 from http://trac.edgewall.com/
Python 2.3 from http://www.python.org/
Notes:
NB! This will delete existing tickets with conflicting IDs!
Make sure you have removed ',' & ';' from the source data
To-Do:
Create importer that will load any file using XSLT and a style-sheet for the
import format. Volunteers?
Copyright Daragh Fitzpatrick <daragh@i2i-Tech.com>
"""
import csv
def main():
import optparse
p = optparse.OptionParser('%prog file.csv /path/to/trac/environment')
opt, args = p.parse_args()
if len(args) != 2:
p.error("2 arguments required")
try:
importCSV(csv.reader(file(args[0])), args[1])
except Exception, e:
print 'Error:', e
def importCSV(reader, env):
import trac.Environment
env = trac.Environment.Environment(env)
db = env.get_db_cnx()
db.autocommit = False
for row in reader:
print row[0]
c = db.cursor()
c.execute("""DELETE FROM ticket where id=%s""",row[0])
c.execute("""INSERT INTO ticket (id, time, changetime, component,
severity,
priority, owner, reporter, cc, url, version, milestone,
status,
resolution, summary, description, keywords)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s)""",
row[0], row[1], row[2], row[3], row[4], row[5], row[6],
row[7],row[8],
row[9], row[10], row[11], row[12], row[13], row[14],
row[15], row[16] )
db.commit()
if __name__ == '__main__':
main()
self-serving too), I spun up the below code to import a CSV file of tickets
into the Trac database.
I don't know if it's a sad reflection on me or a tribute to Python, but the
comments are longer than the code (but took less time to write!)
Will place in /contrib if y'all like it.
Cheers,
:D
--------------------------------------------------------------------
Daragh Fitzpatrick Daragh@UChicago.edu (773) 702-8976
Solutions Architect NSIT Administrative Systems
Renewal Projects and Architecture University of Chicago
--------------------------------------------------------------------
---- cut here ----
"""
csv2trac.py: Import a CSV file into a Trac issue database.
Description:
Imports CSV File with the following format:
id,time,changetime,component,severity,priority,owner,reporter,cc,url,
version,milestone,status,resolution,summary,description,keywords
where:
status = new, assigned, reopened, closed
priority = highest, high, normal, low, lowest
severity = blocker, critical, major, normal, minor, trivial,
enhancement
No smarts, you get to do all the work in the CSV file (sorry!)
Dependencies:
Trac 0.7 from http://trac.edgewall.com/
Python 2.3 from http://www.python.org/
Notes:
NB! This will delete existing tickets with conflicting IDs!
Make sure you have removed ',' & ';' from the source data
To-Do:
Create importer that will load any file using XSLT and a style-sheet for the
import format. Volunteers?
Copyright Daragh Fitzpatrick <daragh@i2i-Tech.com>
"""
import csv
def main():
import optparse
p = optparse.OptionParser('%prog file.csv /path/to/trac/environment')
opt, args = p.parse_args()
if len(args) != 2:
p.error("2 arguments required")
try:
importCSV(csv.reader(file(args[0])), args[1])
except Exception, e:
print 'Error:', e
def importCSV(reader, env):
import trac.Environment
env = trac.Environment.Environment(env)
db = env.get_db_cnx()
db.autocommit = False
for row in reader:
print row[0]
c = db.cursor()
c.execute("""DELETE FROM ticket where id=%s""",row[0])
c.execute("""INSERT INTO ticket (id, time, changetime, component,
severity,
priority, owner, reporter, cc, url, version, milestone,
status,
resolution, summary, description, keywords)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s, %s, %s)""",
row[0], row[1], row[2], row[3], row[4], row[5], row[6],
row[7],row[8],
row[9], row[10], row[11], row[12], row[13], row[14],
row[15], row[16] )
db.commit()
if __name__ == '__main__':
main()