Code

- put all methods for parsing a message into a list and call all in a
[roundup.git] / scripts / add-issue
1 #! /usr/bin/env python
2 # $Id: add-issue,v 1.2 2003-04-30 01:28:37 richard Exp $
4 '''
5 Usage: %s <tracker home> <priority> <issue title>
7 Create a new issue in the given tracker. Input is taken from STDIN to
8 create the initial issue message (which may be empty). Issues will be
9 created as the current user (%s) if they exist as a Roundup
10 user, or "admin" otherwise.
11 '''
13 import sys, os, pwd
15 from roundup import instance, mailgw, date
17 # open the instance
18 username = pwd.getpwuid(os.getuid())[0]
19 if len(sys.argv) < 3:
20     print "Error: Not enough arguments"
21     print __doc__.strip()%(sys.argv[0], username)
22     sys.exit(1)
23 tracker_home = sys.argv[1]
24 issue_priority = sys.argv[2]
25 issue_title = ' '.join(sys.argv[3:])
27 # get the message, if any
28 message_text = sys.stdin.read().strip()
30 # open the tracker
31 tracker = instance.open(tracker_home)
32 db = tracker.open('admin')
33 uid = db.user.lookup('admin')
34 try:
35     # try to open the tracker as the current user
36     uid = db.user.lookup(username)
37     db.close()
38     db = tracker.open(username)
39 except KeyError:
40     pass
42 try:
44     # handle the message
45     messages = []
46     if message_text:
47         summary, x = mailgw.parseContent(message_text, 0, 0)
48         msg = db.msg.create(content=message_text, summary=summary, author=uid,
49             date=date.Date())
50         messages = [msg]
52     # now create the issue
53     db.issue.create(title=issue_title, priority=issue_priority,
54         messages=messages)
56     db.commit()
57 finally:
58     db.close()
60 # vim: set filetype=python ts=4 sw=4 et si