diff options
author | W. Trevor King <wking@drexel.edu> | 2009-12-12 00:31:55 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-12-12 00:31:55 -0500 |
commit | bf3d434b244c57556bec979acbc658c30eb58221 (patch) | |
tree | a31746f74a9aaaf1d95c4bd7e1ef1ae30041f2f8 /libbe/ui/util/__init__.py | |
parent | a153347564e4c6baa0388fda05530f5548d16ac5 (diff) | |
download | bugseverywhere-bf3d434b244c57556bec979acbc658c30eb58221.tar.gz |
Added libbe.command.base (with Command class) and moved list command to new format.
Diffstat (limited to 'libbe/ui/util/__init__.py')
-rw-r--r-- | libbe/ui/util/__init__.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/libbe/ui/util/__init__.py b/libbe/ui/util/__init__.py new file mode 100644 index 0000000..a650d33 --- /dev/null +++ b/libbe/ui/util/__init__.py @@ -0,0 +1,69 @@ +# Copyright + +class Completer (object): + def __init__(self, options): + self.options = options + def __call__(self, bugdir, fragment=None): + return [fragment] + +def complete_status(bugdir, fragment=None): + return [fragment] +def complete_severity(bugdir, fragment=None): + return [fragment] +def complete_assigned(bugdir, fragment=None): + return [fragment] +def complete_extra_strings(bugdir, fragment=None): + return [fragment] + +def select_values(string, possible_values, name="unkown"): + """ + This function allows the user to select values from a list of + possible values. The default is to select all the values: + + >>> select_values(None, ['abc', 'def', 'hij']) + ['abc', 'def', 'hij'] + + The user selects values with a comma-separated limit_string. + Prepending a minus sign to such a list denotes blacklist mode: + + >>> select_values('-abc,hij', ['abc', 'def', 'hij']) + ['def'] + + Without the leading -, the selection is in whitelist mode: + + >>> select_values('abc,hij', ['abc', 'def', 'hij']) + ['abc', 'hij'] + + In either case, appropriate errors are raised if on of the + user-values is not in the list of possible values. The name + parameter lets you make the error message more clear: + + >>> select_values('-xyz,hij', ['abc', 'def', 'hij'], name="foobar") + Traceback (most recent call last): + ... + UserError: Invalid foobar xyz + ['abc', 'def', 'hij'] + >>> select_values('xyz,hij', ['abc', 'def', 'hij'], name="foobar") + Traceback (most recent call last): + ... + UserError: Invalid foobar xyz + ['abc', 'def', 'hij'] + """ + possible_values = list(possible_values) # don't alter the original + if string == None: + pass + elif string.startswith('-'): + blacklisted_values = set(string[1:].split(',')) + for value in blacklisted_values: + if value not in possible_values: + raise UserError('Invalid %s %s\n %s' + % (name, value, possible_values)) + possible_values.remove(value) + else: + whitelisted_values = string.split(',') + for value in whitelisted_values: + if value not in possible_values: + raise UserError('Invalid %s %s\n %s' + % (name, value, possible_values)) + possible_values = whitelisted_values + return possible_values |