1 # Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc.
2 # Chris Ball <cjb@laptop.org>
3 # Marien Zwart <marienz@gentoo.org>
4 # Thomas Gerigk <tgerigk@gmx.de>
5 # W. Trevor King <wking@drexel.edu>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 """Change tree settings"""
22 from libbe import cmdutil, bugdir, rcs, settings_object
25 def _value_string(bd, setting):
26 val = bd.settings.get(setting, settings_object.EMPTY)
27 if val == settings_object.EMPTY:
28 default = getattr(bd, bd._setting_name_to_attr_name(setting))
29 if default not in [None, settings_object.EMPTY]:
30 val = "None (%s)" % default
35 def execute(args, test=False):
38 >>> bd = bugdir.simple_bug_dir()
40 >>> execute(["target"], test=True)
42 >>> execute(["target", "tomorrow"], test=True)
43 >>> execute(["target"], test=True)
45 >>> execute(["target", "none"], test=True)
46 >>> execute(["target"], test=True)
50 options, args = parser.parse_args(args)
51 complete(options, args, parser)
53 raise cmdutil.UsageError, "Too many arguments"
54 bd = bugdir.BugDir(from_disk=True, manipulate_encodings=not test)
56 keys = bd.settings_properties
59 print "%16s: %s" % (key, _value_string(bd, key))
61 print _value_string(bd, args[0])
64 setattr(bd, args[0], settings_object.EMPTY)
66 if args[0] not in bd.settings_properties:
67 msg = "Invalid setting %s\n" % args[0]
68 msg += 'Allowed settings:\n '
69 msg += '\n '.join(bd.settings_properties)
70 raise cmdutil.UserError(msg)
71 old_setting = bd.settings.get(args[0])
72 setattr(bd, args[0], args[1])
75 parser = cmdutil.CmdOptionParser("be set [NAME] [VALUE]")
78 def get_bugdir_settings():
80 for s in bugdir.BugDir.settings_properties:
83 documented_settings = []
85 set = getattr(bugdir.BugDir, s)
86 dstr = set.__doc__.strip()
87 # per-setting comment adjustments
89 lines = dstr.split('\n')
90 while lines[0].startswith("This property defaults to") == False:
92 assert len(lines) != None, \
93 "Unexpected rcs_name docstring:\n '%s'" % dstr
95 0, "The name of the revision control system to use.\n")
96 dstr = '\n'.join(lines)
97 doc = textwrap.wrap(dstr, width=70, initial_indent=' ',
98 subsequent_indent=' ')
99 documented_settings.append("%s\n%s" % (s, '\n'.join(doc)))
100 return documented_settings
103 Show or change per-tree settings.
105 If name and value are supplied, the name is set to a new value.
106 If no value is specified, the current value is printed.
107 If no arguments are provided, all names and values are listed.
109 To unset a setting, set it to "none".
111 Allowed settings are:
113 %s""" % ('\n'.join(get_bugdir_settings()),)
116 return get_parser().help_str() + longhelp
118 def complete(options, args, parser):
119 for option, value in cmdutil.option_value_pairs(options, parser):
120 if value == "--complete":
121 # no argument-options at the moment, so this is future-proofing
122 raise cmdutil.GetCompletions()
123 for pos,value in enumerate(args):
124 if value == "--complete":
125 if pos == 0: # first positional argument is a setting name
126 props = bugdir.BugDir.settings_properties
127 raise cmdutil.GetCompletions(props)
128 raise cmdutil.GetCompletions() # no positional arguments for list