code_junkie

How to quickly add tickets in Trac?

Nov 11th, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. '''
  4. trac-bug: add bug/feature to current Trac project, from the command line.
  5. Specify Trac project directory in TRAC_ENV environment variable.
  6. '''
  7.  
  8.  
  9. import os, sys
  10.  
  11. TRAC_ENV = os.environ.get('TRAC_ENV') or os.path.expanduser('~/trac/projectenv')
  12. if not os.path.isdir(TRAC_ENV):
  13. print >>sys.stderr, "Set TRAC_ENV to the Trac project directory."
  14. sys.exit(2)
  15.  
  16. from trac.env import open_environment
  17. from trac.ticket import Ticket
  18. t = Ticket(open_environment(TRAC_ENV))
  19.  
  20. desc = ' '.join(sys.argv[1:])
  21. info = dict(
  22. status='open',
  23. owner=os.environ['USER'], reporter=os.environ['USER'],
  24. description = desc, summary=desc
  25. )
  26.  
  27. t.populate(info)
  28. num = t.insert()
  29. if not num:
  30. print >>sys.stderr, "Ticket not created"
  31. print >>sys.stder, vals
  32. sys.exit(1)
  33.  
  34. print "Ticket #%d: %s" % (num,desc)
  35. sys.exit(0) # all is well
Add Comment
Please, Sign In to add comment