Optimized bug loading from becommands/comment with partial-uuid matching.
authorW. Trevor King <wking@drexel.edu>
Fri, 28 Nov 2008 00:35:55 +0000 (19:35 -0500)
committerW. Trevor King <wking@drexel.edu>
Fri, 28 Nov 2008 00:35:55 +0000 (19:35 -0500)
The code is a bit uglier now, but it's a good deal faster :).

becommands/comment.py
completion/be.bash [deleted file]

index 8fdbe429ab98bb8085aaf53b625ea226806e458f..5000588a9ce7d2ed3cea35bffe3982085f6bad64 100644 (file)
@@ -122,12 +122,20 @@ def complete(options, args, parser):
     for pos,value in enumerate(args):
         if value == "--complete":
             if pos == 0: # fist positional argument is a bug or comment id
+                if len(args) >= 2:
+                    partial = args[1].split(':')[0] # take only bugid portion
+                else:
+                    partial = ""
                 ids = []
                 try:
                     bd = bugdir.BugDir(from_disk=True,
                                        manipulate_encodings=False)
-                    bd.load_all_bugs()
-                    bugs = [bug for bug in bd if bug.active == True]
+                    bugs = []
+                    for uuid in bd.list_uuids():
+                        if uuid.startswith(partial):
+                            bug = bd.bug_from_uuid(uuid)
+                            if bug.active == True:
+                                bugs.append(bug)
                     for bug in bugs:
                         shortname = bd.bug_shortname(bug)
                         ids.append(shortname)
diff --git a/completion/be.bash b/completion/be.bash
deleted file mode 100644 (file)
index dbe1214..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/bash
-# Bash completion script for be (Bugs Everywhere)
-#
-# System wide installation:
-#   Copy this file to /etc/bash_completion/be
-# Per-user installation:
-#   Copy this file to ~/.be-completion.sh and source it in your .bashrc:
-#     source ~/.be-completion.sh
-# 
-# For a good intro to Bash completion, see Steve Kemp's article
-#   "An introduction to bash completion: part 2"
-#   http://www.debian-administration.org/articles/317
-
-# Requires:
-#   be [X Y Z] --complete
-#       to print a list of available completions at that point
-_be()
-{
-    local cur prev opts
-    COMPREPLY=()
-    cur="${COMP_WORDS[COMP_CWORD]}"
-    prev="${COMP_WORDS[COMP_CWORD-1]}"
-    
-    if [ $COMP_CWORD -eq 1 ]; then
-       # no command yet, show all commands
-       COMPREPLY=( $( compgen -W "$(be --complete)" -- $cur ) )
-    else
-       # remove the first word (should be "be") for security reasons
-       unset COMP_WORDS[0]
-       # remove the current word and all later words, because they
-       # are not needed for completion.
-       for i in `seq $COMP_CWORD ${#COMP_WORDS[@]}`; do
-           unset COMP_WORDS[$i];
-       done
-       COMPREPLY=( $( compgen -W "$(be "${COMP_WORDS[@]}" --complete)" -- $cur ) )
-    fi
-}
-
-complete -F _be be