aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/command/util.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-12-29 19:00:40 -0500
committerW. Trevor King <wking@drexel.edu>2009-12-29 19:00:40 -0500
commit4372a17b4215df25b3da0b68daf4d6b490a8955c (patch)
tree4464d284fe0653701e43b3dc5a465dd14da056b3 /libbe/command/util.py
parentd0fdc606a0420807cfbde0519d1807bd16f14c37 (diff)
downloadbugseverywhere-4372a17b4215df25b3da0b68daf4d6b490a8955c.tar.gz
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...
Diffstat (limited to 'libbe/command/util.py')
-rw-r--r--libbe/command/util.py79
1 files changed, 74 insertions, 5 deletions
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"):
"""