Mercurial > p > roundup > code
comparison scripts/add-issue @ 1626:581aa1853a2f
adding a simple add-issue script
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 30 Apr 2003 01:26:55 +0000 |
| parents | |
| children | e029d625c8f1 |
comparison
equal
deleted
inserted
replaced
| 1625:126d4d0ac89b | 1626:581aa1853a2f |
|---|---|
| 1 #! /usr/bin/env python | |
| 2 # $Id: add-issue,v 1.1 2003-04-30 01:26:55 richard Exp $ | |
| 3 | |
| 4 ''' | |
| 5 Usage: %s: <tracker home> <priority> <issue title> | |
| 6 | |
| 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 ''' | |
| 12 | |
| 13 import sys, os, pwd | |
| 14 | |
| 15 from roundup import instance, mailgw, date | |
| 16 | |
| 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:]) | |
| 26 | |
| 27 # get the message, if any | |
| 28 message_text = sys.stdin.read().strip() | |
| 29 | |
| 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 | |
| 41 | |
| 42 try: | |
| 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() | |
| 57 finally: | |
| 58 db.close() | |
| 59 | |
| 60 # vim: set filetype=python ts=4 sw=4 et si |
