diff options
Diffstat (limited to 'libbe')
-rw-r--r-- | libbe/command/base.py | 1 | ||||
-rw-r--r-- | libbe/command/list.py | 21 | ||||
-rw-r--r-- | libbe/command/util.py | 69 | ||||
-rw-r--r-- | libbe/ui/util/__init__.py | 68 |
4 files changed, 79 insertions, 80 deletions
diff --git a/libbe/command/base.py b/libbe/command/base.py index 973b840..d18e070 100644 --- a/libbe/command/base.py +++ b/libbe/command/base.py @@ -5,7 +5,6 @@ import sys import libbe import libbe.util.plugin -import libbe.ui.util.repo class UserError(Exception): pass diff --git a/libbe/command/list.py b/libbe/command/list.py index 508cc70..9527779 100644 --- a/libbe/command/list.py +++ b/libbe/command/list.py @@ -21,10 +21,9 @@ import os import re import libbe -import libbe.command import libbe.bug -import libbe.util.utility -import libbe.ui.util +import libbe.command +import libbe.command.util # get a list of * for cmp_*() comparing two bugs. AVAILABLE_CMPS = [fn[4:] for fn in dir(libbe.bug) if fn[:4] == 'cmp_'] @@ -78,30 +77,30 @@ class List (libbe.command.Command): help='Only show bugs matching the STATUS specifier', arg=libbe.command.Argument( name='status', metavar='STATUS', default='active', - completion_callback=libbe.ui.util.complete_status)), + completion_callback=libbe.command.util.complete_status)), libbe.command.Option(name='severity', help='Only show bugs matching the SEVERITY specifier', arg=libbe.command.Argument( name='severity', metavar='SEVERITY', default='all', - completion_callback=libbe.ui.util.complete_severity)), + completion_callback=libbe.command.util.complete_severity)), libbe.command.Option(name='assigned', short_name='a', help='Only show bugs matching ASSIGNED', arg=libbe.command.Argument( name='assigned', metavar='ASSIGNED', default='all', - completion_callback=libbe.ui.util.complete_assigned)), + completion_callback=libbe.command.util.complete_assigned)), libbe.command.Option(name='extra-strings', short_name='e', help='Only show bugs matching STRINGS, e.g. --extra-strings' ' TAG:working,TAG:xml', arg=libbe.command.Argument( name='extra-strings', metavar='STRINGS', default=None, - completion_callback=libbe.ui.util.complete_extra_strings)), + completion_callback=libbe.command.util.complete_extra_strings)), libbe.command.Option(name='sort', short_name='S', help='Adjust bug-sort criteria with comma-separated list ' 'SORT. e.g. "--sort creator,time". ' 'Available criteria: %s' % ','.join(AVAILABLE_CMPS), arg=libbe.command.Argument( name='sort', metavar='SORT', default=None, - completion_callback=libbe.ui.util.Completer(AVAILABLE_CMPS))), + completion_callback=libbe.command.util.Completer(AVAILABLE_CMPS))), libbe.command.Option(name='uuids', short_name='u', help='Only print the bug UUIDS'), libbe.command.Option(name='xml', short_name='x', @@ -165,7 +164,7 @@ class List (libbe.command.Command): elif params['status'] == 'inactive': status = list(libbe.bug.inactive_status_values) else: - status = libbe.ui.util.select_values( + status = libbe.command.util.select_values( params['status'], libbe.bug.status_values) # select severity if params['severity'] == 'all': @@ -174,7 +173,7 @@ class List (libbe.command.Command): serious = libbe.bug.severity_values.index('serious') severity.append(list(libbe.bug.severity_values[serious:])) else: - severity = libbe.ui.util.select_values( + severity = libbe.command.util.select_values( params['severity'], bug.severity_values) # select assigned if params['assigned'] == "all": @@ -185,7 +184,7 @@ class List (libbe.command.Command): if bug.assigned != None \ and not bug.assigned in possible_assignees: possible_assignees.append(bug.assigned) - assigned = libbe.ui.util.select_values( + assigned = libbe.command.util.select_values( params['assigned'], possible_assignees) for i in range(len(assigned)): if assigned[i] == '-': diff --git a/libbe/command/util.py b/libbe/command/util.py new file mode 100644 index 0000000..a650d33 --- /dev/null +++ b/libbe/command/util.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 diff --git a/libbe/ui/util/__init__.py b/libbe/ui/util/__init__.py index a650d33..b98f164 100644 --- a/libbe/ui/util/__init__.py +++ b/libbe/ui/util/__init__.py @@ -1,69 +1 @@ # 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 |