1 # Copyright (C) 2005-2012 Aaron Bentley <abentley@panoramicfeedback.com>
2 # Andrew Cooper <andrew.cooper@hkcreations.org>
3 # Chris Ball <cjb@laptop.org>
4 # Gianluca Montecchi <gian@grys.it>
5 # Niall Douglas (s_sourceforge@nedprod.com) <spam@spamtrap.com>
6 # W. Trevor King <wking@tremily.us>
8 # This file is part of Bugs Everywhere.
10 # Bugs Everywhere is free software: you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by the Free
12 # Software Foundation, either version 2 of the License, or (at your option) any
15 # Bugs Everywhere is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 # You should have received a copy of the GNU General Public License along with
21 # Bugs Everywhere. If not, see <http://www.gnu.org/licenses/>.
25 import libbe.command.util
27 from .assign import parse_assigned as _parse_assigned
30 class New (libbe.command.Command):
36 >>> import libbe.bugdir
37 >>> import libbe.util.id
38 >>> bd = libbe.bugdir.SimpleBugDir(memory=False)
39 >>> io = libbe.command.StringInputOutput()
40 >>> io.stdout = sys.stdout
41 >>> ui = libbe.command.UserInterface(io=io)
42 >>> ui.storage_callbacks.set_storage(bd.storage)
45 >>> uuid_gen = libbe.util.id.uuid_gen
46 >>> libbe.util.id.uuid_gen = lambda: 'X'
47 >>> ui._user_id = u'Fran\\xe7ois'
48 >>> options = {'assigned': 'none'}
49 >>> ret = ui.run(cmd, options=options, args=['this is a test',])
50 Created bug with ID abc/X
51 >>> libbe.util.id.uuid_gen = uuid_gen
53 >>> bug = bd.bug_from_uuid('X')
60 >>> bug.time <= int(time.time())
62 >>> print bug.severity
66 >>> print bug.assigned
73 def __init__(self, *args, **kwargs):
74 libbe.command.Command.__init__(self, *args, **kwargs)
76 libbe.command.Option(name='reporter', short_name='r',
77 help='The user who reported the bug',
78 arg=libbe.command.Argument(
79 name='reporter', metavar='NAME')),
80 libbe.command.Option(name='creator', short_name='c',
81 help='The user who created the bug',
82 arg=libbe.command.Argument(
83 name='creator', metavar='NAME')),
84 libbe.command.Option(name='assigned', short_name='a',
85 help='The developer in charge of the bug',
86 arg=libbe.command.Argument(
87 name='assigned', metavar='NAME',
88 completion_callback=libbe.command.util.complete_assigned)),
89 libbe.command.Option(name='status', short_name='t',
90 help='The bug\'s status level',
91 arg=libbe.command.Argument(
92 name='status', metavar='STATUS',
93 completion_callback=libbe.command.util.complete_status)),
94 libbe.command.Option(name='severity', short_name='s',
95 help='The bug\'s severity',
96 arg=libbe.command.Argument(
97 name='severity', metavar='SEVERITY',
98 completion_callback=libbe.command.util.complete_severity)),
99 libbe.command.Option(name='bugdir', short_name='b',
100 help='Short bugdir UUID for the new bug. You '
101 'only need to set this if you have multiple bugdirs in '
103 arg=libbe.command.Argument(
104 name='bugdir', metavar='ID', default=None,
105 completion_callback=libbe.command.util.complete_bugdir_id)),
106 libbe.command.Option(name='full-uuid', short_name='f',
107 help='Print the full UUID for the new bug')
110 libbe.command.Argument(name='summary', metavar='SUMMARY')
113 def _run(self, **params):
114 if params['summary'] == '-': # read summary from stdin
115 summary = self.stdin.readline()
117 summary = params['summary']
118 storage = self._get_storage()
119 bugdirs = self._get_bugdirs()
121 bugdir = bugdirs[bugdir]
122 elif len(bugdirs) == 1:
123 bugdir = bugdirs.values()[0]
125 raise libbe.command.UserError(
126 'Ambiguous bugdir {}'.format(sorted(bugdirs.values())))
127 storage.writeable = False
128 bug = bugdir.new_bug(summary=summary.strip())
129 if params['creator'] != None:
130 bug.creator = params['creator']
132 bug.creator = self._get_user_id()
133 if params['reporter'] != None:
134 bug.reporter = params['reporter']
136 bug.reporter = bug.creator
137 if params['assigned'] != None:
138 bug.assigned = _parse_assigned(self, params['assigned'])
139 if params['status'] != None:
140 bug.status = params['status']
141 if params['severity'] != None:
142 bug.severity = params['severity']
143 storage.writeable = True
145 if params['full-uuid']:
146 bug_id = bug.id.long_user()
148 bug_id = bug.id.user()
149 self.stdout.write('Created bug with ID %s\n' % (bug_id))
152 def _long_help(self):
154 Create a new bug, with a new ID. The summary specified on the
155 commandline is a string (only one line) that describes the bug briefly
156 or "-", in which case the string will be read from stdin.