Bulk changing tickets in Trac

Posted: January 19th, 2010 | Author: | Filed under: Nerdery | Tags: , | No Comments »

At work we use the Trac wiki/ticket/software dev management system. I have ended up as its primary maintainer here. We’ve had a few developers leave, and Trac had lots of tickets orphaned with the ex-employees as owner or polluting the CC list. I whipped together a python script using the XML-RPC plugin from trac-hacks. It leaves a nice comment (polluting the timeline some) but doesn’t send out emails by default.

import xmlrpclib, re
 
#connect
t = xmlrpclib.ServerProxy('https://user:password@tracserver.example/xmlrpc')
 
#regular expression for the CC field. 
byere = re.compile('(?:jamie|dave|brad)(?:@DOMAIN1\.LOCAL|@DOMAIN1\.COM)?,? ?', re.IGNORECASE)
 
#This first loop sets the owner to blank, the status to 'new', and cleans the CC list for any open tickets assigned to Jamie or Dave. Doing the CC fix here makes the timeline a little cleaner.
for ticketid in t.ticket.query('owner=jamie@DOMAIN1.LOCAL&owner=dave@DOMAIN1.LOCAL&status=new&status=accepted&status=assigned&testing&status=planning'):
    ticket = t.ticket.get(ticketid)
    cclist = ticket[3]['cc']
    newcclist = byere.sub('', cclist)
    t.ticket.update(ticketid, '', {'owner' : '', 'status' : 'new', 'cc' : newcclist})
 
#This loop is just for those tickets where they appear on the CC list.
for ticketid in t.ticket.query('cc~=jamie&cc~=dave&cc~=brad&status!=closed'):
    ticket = t.ticket.get(ticketid)
    cclist = ticket[3]['cc']
    newcclist = byere.sub('', cclist)
    t.ticket.update(ticketid, '', {'cc' : newcclist})
No Comments »