1 # Copyright (C) 2005-2012 Aaron Bentley <abentley@panoramicfeedback.com>
2 # Chris Ball <cjb@laptop.org>
3 # Gianluca Montecchi <gian@grys.it>
4 # Marien Zwart <marien.zwart@gmail.com>
5 # Thomas Gerigk <tgerigk@gmx.de>
6 # W. Trevor King <wking@drexel.edu>
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/>.
29 import libbe.command.util
30 from libbe.storage.util.settings_object import EMPTY
33 class Set (libbe.command.Command):
34 """Change bug directory settings
37 >>> import libbe.bugdir
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 >>> ret = ui.run(cmd, args=['target'])
47 >>> ret = ui.run(cmd, args=['target', 'abcdefg'])
48 >>> ret = ui.run(cmd, args=['target'])
50 >>> ret = ui.run(cmd, args=['target', 'none'])
51 >>> ret = ui.run(cmd, args=['target'])
58 def __init__(self, *args, **kwargs):
59 libbe.command.Command.__init__(self, *args, **kwargs)
61 libbe.command.Argument(
62 name='setting', metavar='SETTING', optional=True,
63 completion_callback=complete_bugdir_settings),
64 libbe.command.Argument(
65 name='value', metavar='VALUE', optional=True)
68 def _run(self, **params):
69 bugdir = self._get_bugdir()
70 if params['setting'] == None:
71 keys = bugdir.settings_properties
74 print >> self.stdout, \
75 '%16s: %s' % (key, _value_string(bugdir, key))
77 if params['setting'] not in bugdir.settings_properties:
78 msg = 'Invalid setting %s\n' % params['setting']
79 msg += 'Allowed settings:\n '
80 msg += '\n '.join(bugdir.settings_properties)
81 raise libbe.command.UserError(msg)
82 if params['value'] == None:
83 print _value_string(bugdir, params['setting'])
85 if params['value'] == 'none':
86 params['value'] = EMPTY
87 old_setting = bugdir.settings.get(params['setting'])
88 attr = bugdir._setting_name_to_attr_name(params['setting'])
89 setattr(bugdir, attr, params['value'])
94 Show or change per-tree settings.
96 If name and value are supplied, the name is set to a new value.
97 If no value is specified, the current value is printed.
98 If no arguments are provided, all names and values are listed.
100 To unset a setting, set it to "none".
102 Allowed settings are:
106 Note that this command does not provide a good interface for some of
107 these settings (yet!). You may need to edit the bugdir settings file
108 (`.be/<bugdir>/settings`) manually. Examples for each troublesome
109 setting are given below.
111 Add the following lines to override the default severities and use
116 - The issue is a target or milestone, not a bug.
118 - A feature that could improve usefulness, but not a bug.
120 You may add as many name/description pairs as you wish to have; they
121 are sorted in order from least important at the top, to most important
122 at the bottom. The target severity gets special handling by `be
125 Note that the values here _override_ the defaults. That means that if
126 you like the defaults, and wish to keep them, you will have to copy
127 them here before adding any of your own. See `be severity --help` for
130 Add the following lines to override the default statuses and use your
135 - A possible bug which lacks independent existance confirmation.
137 - A working bug that has not been assigned to a developer.
141 - The bug is no longer relevant.
143 - The bug should no longer occur.
145 You may add as many name/description pairs as you wish to have; they
146 are sorted in order from most important at the top, to least important
149 Note that the values here _override_ the defaults. That means that if
150 you like the defaults, and wish to keep them, you will have to copy
151 them here before adding any of your own. See `be status --help` for
153 """ % ('\n'.join(get_bugdir_settings()),)
155 def get_bugdir_settings():
157 for s in libbe.bugdir.BugDir.settings_properties:
160 documented_settings = []
162 set = getattr(libbe.bugdir.BugDir, s)
163 dstr = set.__doc__.strip()
164 # per-setting comment adjustments
166 lines = dstr.split('\n')
167 while lines[0].startswith('This property defaults to') == False:
169 assert len(lines) != None, \
170 'Unexpected vcs_name docstring:\n "%s"' % dstr
172 0, 'The name of the revision control system to use.\n')
173 dstr = '\n'.join(lines)
174 doc = textwrap.wrap(dstr, width=70, initial_indent=' ',
175 subsequent_indent=' ')
176 documented_settings.append('%s\n%s' % (s, '\n'.join(doc)))
177 return documented_settings
179 def _value_string(bugdir, setting):
180 val = bugdir.settings.get(setting, EMPTY)
182 default = getattr(bugdir, bugdir._setting_name_to_attr_name(setting))
183 if default not in [None, EMPTY]:
184 val = 'None (%s)' % default
189 def complete_bugdir_settings(command, argument, fragment=None):
191 List possible command completions for fragment.
193 Neither the command nor argument arguments are used.
195 return libbe.bugdir.BugDir.settings_properties