Recently started using Trac and love it, thx :-)
I couldn't find a way to submit a ticket programatically...so i wrote this script - maybe useful to others. If there's a better way gimmie a shout.
cheers,
Paul.
#!/usr/bin/env python
#
# ----------------------------------------------------------------------------
# Copyright (c) 2006 [EMAIL PROTECTED]
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
# ----------------------------------------------------------------------------
# This script is for submitting a ticket to the Trac system
#
# Based on an original trac-post-commit-hook by Stephen Hansen
# http://projects.edgewall.com/trac/browser/branches/0.8-stable/contrib/trac-post-commit-hook
#
# Must be run with sufficient priviledges for the trac.db file
#
# REPOS="$1"
# TRAC_ENV='/somewhere/trac/project/'
# TRAC_URL='http://trac.mysite.com/project/'
#
# python ./addTicket.py
# -p $TRAC_ENV
# -t "A title"
# --reporter "Regression System"
# --priority "minor"
# --description "A descritpion"
# --owner "anon"
# -s $TRAC_URL
#
# On successful completion sends a notification to the owners and prints out the ticket ID
#
import re
import os
import sys
import time
from trac.env import open_environment
from trac.Notify import TicketNotifyEmail
from trac.ticket import Ticket
from trac.web.href import Href
try:
from optparse import OptionParser
except ImportError:
try:
from optik import OptionParser
except ImportError:
raise ImportError, 'Requires Python 2.3 or the Optik option parsing library.'
parser = OptionParser()
parser.add_option('-e', '--require-envelope', dest='env', default='',
help='Require commands to be enclosed in an envelope. If -e[], '
'then commands must be in the form of [closes #4]. Must '
'be two characters.')
parser.add_option('-p', '--project', dest='project',
help='Path to the Trac project.')
parser.add_option('-t', '--title-summary', dest='titleSummary',
help='The ticket title (or summary as trac calls it)')
parser.add_option('-r', '--reporter', dest='reporter',
help='The person or entity raising this ticket (assigner)')
parser.add_option ('-q', '--priority', dest='priority',
help='The ticket priority [minor,major...]')
parser.add_option('-d', '--description', dest='description',
help='Description of the ticket')
parser.add_option('-o', '--owner', dest='owner',
help='Tickets owner (assignee)')
parser.add_option('-s', '--siteurl', dest='url',
help='The base URL to the project\'s trac website (to which '
'/ticket/## is appended). If this is not specified, '
'the project URL from trac.ini will be used.')
(options, args) = parser.parse_args(sys.argv[1:])
if options.env :
leftEnv = '\\' + options.env[0]
rghtEnv = '\\' + options.env[1]
else:
leftEnv = ''
rghtEnv = ''
class OpenTicket:
def __init__(self, project=options.project, reporter=options.reporter ,
title=options.titleSummary,priority=options.priority,
description=options.description, owner=options.owner, url="">
self.reporter = reporter
self.priority = priority
self.description = description
self.owner = owner
self.title=title
self.now = int(time.time())
self.env = open_environment(project)
if url is None:
url = "" 'url')
self.env.href = ""> self.env.abs_href = Href(url)
self._cmdOpen()
def _cmdOpen(self):
try:
ticket = Ticket(self.env)
ticket['reporter'] = self.reporter
ticket['summary'] = self.title
ticket['priority'] = self.priority
ticket['description'] = self.description
ticket['owner'] = self.owner
ticket.insert()
print>>sys.stdout, '%s' % ticket.id
tn = TicketNotifyEmail( self.env)
tn.notify(ticket, newticket=1, modtime=self.now)
except Exception, e:
print>>sys.stderr, 'Unexpected error while processing ticket ' \
'%s' % ( e)
if __name__ == "__main__":
if len(sys.argv) < 5:
print "For usage: %s --help" % (sys.argv[0])
else:
OpenTicket()
_______________________________________________ Trac-dev mailing list [email protected] http://lists.edgewall.com/mailman/listinfo/trac-dev
