Gantty learns a trick: Trac to Gantt in 30 seconds flat

Gantty is growing up fast. I don’t know how it happened. One day he was perfectly content to retrieve information about GanttProject charts, and now he’s not happy unless he’s wading through and writing GanttProject files. And with this latest piece of funnery, Gantty shows off what it’s capable of.

Are you using Trac for some project or another? It’s okay, I do too. Not everyone has had the glory of GitHub revealed to them yet. Patience, everybody. Besides, if you’re using Trac, you can check out this awesomeness. So it’s worth it.

First off, grab the latest version of gantty. This is gonna be 0.1.6 (sudo gem install ardekantur-gantty).

Now, emblazon this code into your eyeballs, and write it to a text file while your eyes are closed:

Call the text file trac_to_gantt.rb, imbuing it with magical Ruby powers.

Grab your Trac database (/your/trac/install/db/trac.db) and toss it in the same directory as trac_to_gantt.rb. Now you’re all set!

Run it with no arguments to see what the output will look like. Unless you stare regularly at GanttProject XML (like I do), this won’t be too awesome. Next time, send the output to a file with the .gan extension, and open it up in GanttProject. Voila!

$ ruby trac_to_gantt.rb > trac.gan

Trac to GanttProject XML Output w/ Gantty

All of your tickets, under milestones, assigned to the right people, and beautifully organized in a timeline.

Some notes:

  • Replace the link to example.com with the location of your own Trac website!
  • If you want to see all completed tasks for an unfinished milestone as well, set SHOW_COMPLETED_TICKETS = true on line 20.
  • We figure out lists of collaborators on a task by splitting up the assigned to field by commas.
  • Tasks will have different colors depending on their priority. Priority is kind of flattened out: Blockers and Criticals are high, Major tasks are medium, everything else is low. Clearly you can screw with this to fit your own priority scheme.
  • I’m actually interested in seeing huge Gantt charts as a result of this. So if you have a particularly populous Trac install, send me a link to the Gantt chart it creates so I can marvel at it.

Enjoy!

2 Comments

  1. Radek Krotil posted December 3, 2008, 12:22 pm

    Thank you, this script is very useful!

    Just a few remarks (I never used Ruby before): 1)With @milestone_task.start = Date.today, you can easily get end date before start date and gantty-0.1.8 didn’t like it.

    2) Empty timepoint causes division by zero in @milestone_task.percent_complete = ((uncompleted_tickets.count.to_f / all_tickets.count.to_f) * 100).to_i

    so I fixed it like this:

    if all_tickets.count.to_i != 0 @milestone_task.percent_complete = ((uncompleted_tickets.count.to_f / all_tickets.count.to_f) * 100).to_i else @milestone_task.percent_complete = 0 end

  2. Ardekantur posted December 3, 2008, 2:20 pm

    Radek: Thanks for trying it out! I cleaned up your comments :-) You should get a GitHub account and fork that script. It’d be awesome and useful for everyone.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*