On Fri, 2006-03-17 at 15:50 -0500, Sean Hussey wrote: > Hi everyone, > > We're thinking of installing separate Trac instances, through > InterTrac, to handle different projects, groups, etc. You know, the > way Trac should be run. :) > > What we're worried about, however, is I might have tickets in any > number of those Trac instances. Has anybody hacked something together > to produce a report based on multiple Trac instances? > > To start, it could just be "Show me ALL of my tickets." > > I guess I'll leave it at that so as to not confuse the issue. Has > anybody done this?
Well, this is a hack I threw together to query all my Trac instances for my own tickets. This is not written to handle different users from the same script, but you could use it as a starting point. It's a WSGI app, but it is currently written to use the "fcgi" module for running as a FastCGI application. -- Matthew Good <[EMAIL PROTECTED]>
#!/usr/bin/env python import os import sys from trac.env import Environment from trac.ticket.query import Query from trac.ticket.model import Milestone, Ticket from trac.web.href import Href from trac.util import sorted, format_date proj_dir = '/var/trac' proj_url = 'http://trac.yourhost.com/' def app(env, start_response): envs = [Environment(os.path.join(proj_dir, proj)) for proj in os.listdir(proj_dir)] query_string = "status=new|assigned|reopened&owner=mgood" tickets = [] for proj in os.listdir(proj_dir): env = Environment(os.path.join(proj_dir, proj)) env.href = env.abs_href = Href(proj_url + proj) proj_name = env.config.get('project', 'name') query = Query.from_string(env, query_string) query.order = 'priority' query.cols = ['id'] for ticket_vals in query.execute(): ticket = Ticket(env, ticket_vals['id']) milestone = None if ticket.values.get('milestone'): try: milestone = Milestone(env, ticket['milestone']) except: pass tickets.append({ 'id': ticket.id, 'summary': ticket['summary'], 'project': proj_name, 'milestone': milestone and milestone.name, 'due': milestone and milestone.due, 'time_estimate': ticket.values.get('time_estimate'), 'time_spent': ticket.values.get('time_spent'), 'href': env.href.ticket(ticket.id), }) tickets = sorted(tickets, key=lambda t: t['due'] or sys.maxint) start_response('200 OK', [('Content-type', 'text/html')]) yield ''' <html><body> <table> <thead> <tr> <th scope="col">Project</th> <th scope="col">Ticket</th> <th scope="col">Summary</th> <th scope="col">Milestone</th> <th scope="col">Due Date</th> <th scope="col">Time Estimate</th> <th scope="col">Time Spent</th> </tr> </thead> <tbody> ''' for t in tickets: yield '<tr>' yield '<td>%s</td>' % t['project'] yield '<td><a href="%s">#%s</a></td>' % (t['href'], t['id']) yield '<td>%s</td>' % t['summary'] yield '<td>%s</td>' % t['milestone'] yield '<td>%s</td>' % (t['due'] and format_date(t['due']) or '') yield '<td>%s</td>' % t['time_estimate'] yield '<td>%s</td>' % t['time_spent'] yield '</tr>\n' yield '</tbody></table></body></html>' if __name__ == '__main__': from fcgi import WSGIServer WSGIServer(app).run()
_______________________________________________ Trac mailing list [email protected] http://lists.edgewall.com/mailman/listinfo/trac
