Ajout script mise a jour de tracker
[auf_roundup.git] / scripts / add-issue
CommitLineData
c638d827
CR
1#! /usr/bin/env python
2# $Id: add-issue,v 1.2 2003-04-30 01:28:37 richard Exp $
3
4'''
5Usage: %s <tracker home> <priority> <issue title>
6
7Create a new issue in the given tracker. Input is taken from STDIN to
8create the initial issue message (which may be empty). Issues will be
9created as the current user (%s) if they exist as a Roundup
10user, or "admin" otherwise.
11'''
12
13import sys, os, pwd
14
15from roundup import instance, mailgw, date
16
17# open the instance
18username = pwd.getpwuid(os.getuid())[0]
19if len(sys.argv) < 3:
20 print "Error: Not enough arguments"
21 print __doc__.strip()%(sys.argv[0], username)
22 sys.exit(1)
23tracker_home = sys.argv[1]
24issue_priority = sys.argv[2]
25issue_title = ' '.join(sys.argv[3:])
26
27# get the message, if any
28message_text = sys.stdin.read().strip()
29
30# open the tracker
31tracker = instance.open(tracker_home)
32db = tracker.open('admin')
33uid = db.user.lookup('admin')
34try:
35 # try to open the tracker as the current user
36 uid = db.user.lookup(username)
37 db.close()
38 db = tracker.open(username)
39except KeyError:
40 pass
41
42try:
43
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]
51
52 # now create the issue
53 db.issue.create(title=issue_title, priority=issue_priority,
54 messages=messages)
55
56 db.commit()
57finally:
58 db.close()
59
60# vim: set filetype=python ts=4 sw=4 et si