Reported bug with utf-8 strings
[be.git] / becommands / new.py
1 # Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc.
2 #                         W. Trevor King <wking@drexel.edu>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 """Create a new bug"""
18 from libbe import cmdutil, bugdir
19 import sys
20 __desc__ = __doc__
21
22 def execute(args, manipulate_encodings=True):
23     """
24     >>> import os, time
25     >>> from libbe import bug
26     >>> bd = bugdir.SimpleBugDir()
27     >>> os.chdir(bd.root)
28     >>> bug.uuid_gen = lambda: "X"
29     >>> execute (["this is a test",], manipulate_encodings=False)
30     Created bug with ID X
31     >>> bd._clear_bugs()
32     >>> bug = bd.bug_from_uuid("X")
33     >>> print bug.summary
34     this is a test
35     >>> bug.time <= int(time.time())
36     True
37     >>> print bug.severity
38     minor
39     >>> bug.target == None
40     True
41     >>> bd.cleanup()
42     """
43     parser = get_parser()
44     options, args = parser.parse_args(args)
45     cmdutil.default_complete(options, args, parser)
46     if len(args) != 1:
47         raise cmdutil.UsageError("Please supply a summary message")
48     bd = bugdir.BugDir(from_disk=True,
49                        manipulate_encodings=manipulate_encodings)
50     if args[0] == '-': # read summary from stdin
51         summary = sys.stdin.readline()
52     else:
53         summary = args[0]
54     bug = bd.new_bug(summary=summary.strip())
55     if options.reporter != None:
56         bug.reporter = options.reporter
57     else:
58         bug.reporter = bug.creator
59     if options.assigned != None:
60         bug.assigned = options.assigned
61     elif bd.default_assignee != None:
62         bug.assigned = bd.default_assignee
63     print "Created bug with ID %s" % bd.bug_shortname(bug)
64
65 def get_parser():
66     parser = cmdutil.CmdOptionParser("be new SUMMARY")
67     parser.add_option("-r", "--reporter", metavar="REPORTER", dest="reporter",
68                       help="The user who reported the bug", default=None)
69     parser.add_option("-a", "--assigned", metavar="ASSIGNED", dest="assigned",
70                       help="The developer in charge of the bug", default=None)
71     return parser
72
73 longhelp="""
74 Create a new bug, with a new ID.  The summary specified on the
75 commandline is a string (only one line) that describes the bug briefly
76 or "-", in which case the string will be read from stdin.
77 """
78
79 def help():
80     return get_parser().help_str() + longhelp