From 8b4ad37815cbef1e06532179f9ca098588d9cb44 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 12 Dec 2009 01:12:17 -0500 Subject: Moved command completion from libbe.ui.util to libbe.command.util --- libbe/command/util.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 libbe/command/util.py (limited to 'libbe/command/util.py') 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 -- cgit From dff6bd9bf89ca80e2265696a478e540476718c9c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 12 Dec 2009 20:57:59 -0500 Subject: Moved be to libbe.ui.command_line and transitioned to Command format. --- libbe/command/util.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'libbe/command/util.py') diff --git a/libbe/command/util.py b/libbe/command/util.py index a650d33..6ce5cc9 100644 --- a/libbe/command/util.py +++ b/libbe/command/util.py @@ -1,18 +1,45 @@ # Copyright +import glob +import os.path + +import libbe +import libbe.command + class Completer (object): def __init__(self, options): self.options = options def __call__(self, bugdir, fragment=None): return [fragment] -def complete_status(bugdir, fragment=None): +def complete_command(command, argument, fragment=None): + """ + List possible command completions for fragment. + + command argument is not used. + """ + return list(libbe.command.commands()) + +def complete_path(command, argument, fragment=None): + """ + List possible path completions for fragment. + + command argument is not used. + """ + if fragment == None: + fragment = '.' + comps = glob.glob(fragment+'*') + glob.glob(fragment+'/*') + if len(comps) == 1 and os.path.isdir(comps[0]): + comps.extend(glob.glob(comps[0]+'/*')) + return comps + +def complete_status(command, argument, fragment=None): return [fragment] -def complete_severity(bugdir, fragment=None): +def complete_severity(command, argument, fragment=None): return [fragment] -def complete_assigned(bugdir, fragment=None): +def complete_assigned(command, argument, fragment=None): return [fragment] -def complete_extra_strings(bugdir, fragment=None): +def complete_extra_strings(command, argument, fragment=None): return [fragment] def select_values(string, possible_values, name="unkown"): -- cgit From 9b1f9db34189744ded87a28aaa395d9344593df2 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 14 Dec 2009 01:12:08 -0500 Subject: Transitioned assign to Command format --- libbe/command/util.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libbe/command/util.py') diff --git a/libbe/command/util.py b/libbe/command/util.py index 6ce5cc9..98b2081 100644 --- a/libbe/command/util.py +++ b/libbe/command/util.py @@ -41,6 +41,8 @@ def complete_assigned(command, argument, fragment=None): return [fragment] def complete_extra_strings(command, argument, fragment=None): return [fragment] +def complete_bug_id(command, argument, fragment=None): + return [fragment] def select_values(string, possible_values, name="unkown"): """ -- cgit From 19fe0817ba7c2cd04caea3adfa82d4490288a548 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 14 Dec 2009 07:37:51 -0500 Subject: Transitioned comment to Command format --- libbe/command/util.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libbe/command/util.py') diff --git a/libbe/command/util.py b/libbe/command/util.py index 98b2081..4395592 100644 --- a/libbe/command/util.py +++ b/libbe/command/util.py @@ -43,6 +43,8 @@ def complete_extra_strings(command, argument, fragment=None): return [fragment] def complete_bug_id(command, argument, fragment=None): return [fragment] +def complete_bug_comment_id(command, argument, fragment=None): + return [fragment] def select_values(string, possible_values, name="unkown"): """ @@ -96,3 +98,19 @@ def select_values(string, possible_values, name="unkown"): % (name, value, possible_values)) possible_values = whitelisted_values return possible_values + +def bug_comment_from_user_id(bugdir, id): + p = libbe.util.id.parse_user(bugdir, id) + if not p['type'] in ['bug', 'comment']: + raise libbe.command.UserError( + '%s is a %s id, not a bug or comment id' % (id, p['type'])) + if p['bugdir'] != bugdir.uuid: + raise libbe.command.UserError( + "%s doesn't belong to this bugdir (%s)" + % (id, bugdir.uuid)) + bug = bugdir.bug_from_uuid(p['bug']) + if 'comment' in p: + comment = bug.comment_from_uuid(p['comment']) + else: + comment = bug.comment_root + return (bug, comment) -- cgit From df1d5b187ff68dc182a3b04294c3e37a8d580e49 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 14 Dec 2009 08:33:43 -0500 Subject: Transitioned depend to Command format --- libbe/command/util.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libbe/command/util.py') diff --git a/libbe/command/util.py b/libbe/command/util.py index 4395592..f6734d5 100644 --- a/libbe/command/util.py +++ b/libbe/command/util.py @@ -94,8 +94,9 @@ def select_values(string, possible_values, name="unkown"): 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)) + raise libbe.command.UserError( + 'Invalid %s %s\n %s' + % (name, value, possible_values)) possible_values = whitelisted_values return possible_values -- cgit From 58bedebfddbb8e1fc8f0a441163526feaecb753b Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 15 Dec 2009 03:31:48 -0500 Subject: Transition to Command-format complete. Well, except for going through and updating the _long_help() strings. $ python test.py libbe.command succeeds for everything except Diff and Subscribe, which is expected since I haven't fixed up libbe.diff yet. --- libbe/command/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libbe/command/util.py') diff --git a/libbe/command/util.py b/libbe/command/util.py index f6734d5..a4aaf5f 100644 --- a/libbe/command/util.py +++ b/libbe/command/util.py @@ -87,7 +87,7 @@ def select_values(string, possible_values, name="unkown"): blacklisted_values = set(string[1:].split(',')) for value in blacklisted_values: if value not in possible_values: - raise UserError('Invalid %s %s\n %s' + raise libbe.command.UserError('Invalid %s %s\n %s' % (name, value, possible_values)) possible_values.remove(value) else: -- cgit From 89b7a1411e4658e831f5d635534b24355dbb941d Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 15 Dec 2009 06:44:20 -0500 Subject: Fixed libbe.command.diff + ugly BugDir.duplicate_bugdir implementation duplicate_bugdir() works, but for the vcs backends, it could require shelling out for _every_ file read. This could, and probably will, be horribly slow. Still it works ;). I'm not sure what a better implementation would be. The old implementation checked out the entire earlier state into a temporary directory pros: single shell out, simple upgrade implementation cons: wouldn't work well for HTTP backens I think a good solution would run along the lines of the currently commented out code in duplicate_bugdir(), where a VersionedStorage.changed_since(revision) call would give you a list of changed files. diff could work off of that directly, without the need to generate a whole duplicate bugdir. I'm stuck on how to handle upgrades though... Also removed trailing whitespace from all python files. --- libbe/command/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libbe/command/util.py') diff --git a/libbe/command/util.py b/libbe/command/util.py index a4aaf5f..3bd02d0 100644 --- a/libbe/command/util.py +++ b/libbe/command/util.py @@ -32,7 +32,7 @@ def complete_path(command, argument, fragment=None): if len(comps) == 1 and os.path.isdir(comps[0]): comps.extend(glob.glob(comps[0]+'/*')) return comps - + def complete_status(command, argument, fragment=None): return [fragment] def complete_severity(command, argument, fragment=None): -- cgit From 4372a17b4215df25b3da0b68daf4d6b490a8955c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 29 Dec 2009 19:00:40 -0500 Subject: Fixed up the completion helpers in libbe.command.util This entailed a fairly thorough cleanup of libbe.util.id. Remaining unimplemented completion helpers: * complete_assigned() * complete_extra_strings() Since these would require scanning all (active?) bugs to compile lists, and I was feeling lazy... --- libbe/command/util.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 5 deletions(-) (limited to 'libbe/command/util.py') diff --git a/libbe/command/util.py b/libbe/command/util.py index 3bd02d0..a5398cf 100644 --- a/libbe/command/util.py +++ b/libbe/command/util.py @@ -34,17 +34,86 @@ def complete_path(command, argument, fragment=None): return comps def complete_status(command, argument, fragment=None): - return [fragment] + bd = command._get_bugdir() + import libbe.bug + return libbe.bug.status_values + def complete_severity(command, argument, fragment=None): - return [fragment] + bd = command._get_bugdir() + import libbe.bug + return libbe.bug.severity_values + def complete_assigned(command, argument, fragment=None): + if fragment == None: + return [] return [fragment] + def complete_extra_strings(command, argument, fragment=None): + if fragment == None: + return [] return [fragment] + def complete_bug_id(command, argument, fragment=None): - return [fragment] -def complete_bug_comment_id(command, argument, fragment=None): - return [fragment] + return complete_bug_comment_id(command, argument, fragment, + comments=False) + +def complete_bug_comment_id(command, argument, fragment=None, + active_only=True, comments=True): + import libbe.bugdir + import libbe.util.id + bd = command._get_bugdir() + if fragment == None or len(fragment) == 0: + fragment = '/' + try: + p = libbe.util.id.parse_user(bd, fragment) + matches = None + root,residual = (fragment, None) + if not root.endswith('/'): + root += '/' + except libbe.util.id.InvalidIDStructure, e: + return [] + except libbe.util.id.NoIDMatches: + return [] + except libbe.util.id.MultipleIDMatches, e: + if e.common == None: + # choose among bugdirs + return e.matches + common = e.common + matches = e.matches + root,residual = libbe.util.id.residual(common, fragment) + p = libbe.util.id.parse_user(bd, e.common) + bug = None + if matches == None: # fragment was complete, get a list of children uuids + if p['type'] == 'bugdir': + matches = bd.uuids() + common = bd.id.user() + elif p['type'] == 'bug': + if comments == False: + return [fragment] + bug = bd.bug_from_uuid(p['bug']) + matches = bug.uuids() + common = bug.id.user() + else: + assert p['type'] == 'comment', p + return [fragment] + if p['type'] == 'bugdir': + child_fn = bd.bug_from_uuid + elif p['type'] == 'bug': + if comments == False: + return[fragment] + if bug == None: + bug = bd.bug_from_uuid(p['bug']) + child_fn = bug.comment_from_uuid + elif p['type'] == 'comment': + assert matches == None, matches + return [fragment] + possible = [] + common += '/' + for m in matches: + child = child_fn(m) + id = child.id.user() + possible.append(id.replace(common, root)) + return possible def select_values(string, possible_values, name="unkown"): """ -- cgit From 4d4283ecd654f1efb058cd7f7dba6be88b70ee92 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 1 Jan 2010 08:11:08 -0500 Subject: Updated copyright information --- libbe/command/util.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'libbe/command/util.py') diff --git a/libbe/command/util.py b/libbe/command/util.py index a5398cf..c9618ad 100644 --- a/libbe/command/util.py +++ b/libbe/command/util.py @@ -1,4 +1,18 @@ -# Copyright +# Copyright (C) 2009-2010 W. Trevor King +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import glob import os.path -- cgit From 7e8237f5004a86be0bd90c77e0640cd265a61d72 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 20 Jan 2010 12:28:26 -0500 Subject: Add entry points for functionality needed by CFBE (and probably other UIs) --- libbe/command/util.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'libbe/command/util.py') diff --git a/libbe/command/util.py b/libbe/command/util.py index c9618ad..977b596 100644 --- a/libbe/command/util.py +++ b/libbe/command/util.py @@ -34,12 +34,8 @@ def complete_command(command, argument, fragment=None): """ return list(libbe.command.commands()) -def complete_path(command, argument, fragment=None): - """ - List possible path completions for fragment. - - command argument is not used. - """ +def comp_path(fragment=None): + """List possible path completions for fragment.""" if fragment == None: fragment = '.' comps = glob.glob(fragment+'*') + glob.glob(fragment+'/*') @@ -47,6 +43,10 @@ def complete_path(command, argument, fragment=None): comps.extend(glob.glob(comps[0]+'/*')) return comps +def complete_path(command, argument, fragment=None): + """List possible path completions for fragment.""" + return comp_path(fragment) + def complete_status(command, argument, fragment=None): bd = command._get_bugdir() import libbe.bug @@ -57,10 +57,13 @@ def complete_severity(command, argument, fragment=None): import libbe.bug return libbe.bug.severity_values +def assignees(bugdir): + bugdir.load_all_bugs() + return list(set([bug.assigned for bug in bugdir + if bug.assigned != None])) + def complete_assigned(command, argument, fragment=None): - if fragment == None: - return [] - return [fragment] + return assignees(command._get_bugdir()) def complete_extra_strings(command, argument, fragment=None): if fragment == None: -- cgit From 0dd273f8605bc21589a51d3b046a231ff9df6fbb Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 1 Feb 2010 11:36:21 -0500 Subject: Fix command name output of `be --complete`. By adding command_names option to libbe.command.commands. Previous versions of `be --complete` printed "import_xml", not "import-xml". Also fixed libbe.command.base's doctests, so test.py can run them. --- libbe/command/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libbe/command/util.py') diff --git a/libbe/command/util.py b/libbe/command/util.py index 977b596..6e8e36c 100644 --- a/libbe/command/util.py +++ b/libbe/command/util.py @@ -32,7 +32,7 @@ def complete_command(command, argument, fragment=None): command argument is not used. """ - return list(libbe.command.commands()) + return list(libbe.command.commands(command_names=True)) def comp_path(fragment=None): """List possible path completions for fragment.""" -- cgit