[yum-commits] completion-helper.py etc/yum.bash

Ville Skyttä scop at osuosl.org
Wed Dec 21 20:26:43 UTC 2011


 completion-helper.py |   21 ++++++++++++++++-----
 etc/yum.bash         |    5 ++---
 2 files changed, 18 insertions(+), 8 deletions(-)

New commits:
commit 1fdc7dd8fffc17b8cfbfd4d71f79d5b9bafbd490
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Tue Dec 20 20:30:47 2011 +0200

    Narrow produced completions down inside helper, bypass compgen -W.
    
    Reducing amount of data to process is more effective within yum, and
    compgen -W is slow when there's lots of output.  "yum install f<TAB>"
    before this on my system: 7.5s, after: 0.85s.

diff --git a/completion-helper.py b/completion-helper.py
index 7aecb23..e4164f7 100755
--- a/completion-helper.py
+++ b/completion-helper.py
@@ -18,6 +18,7 @@
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 
+import shlex
 import sys
 
 import cli
@@ -28,7 +29,8 @@ class GroupsCompletionCommand(yumcommands.GroupsCommand):
     def doCommand(self, base, basecmd, extcmds):
         cmd, extcmds = self._grp_cmd(basecmd, extcmds)
         # case insensitivity is fine here because groupinstall etc are that too
-        installed, available = base.doGroupLists()
+        installed, available = base.doGroupLists(
+            patterns=[get_pattern(extcmds)])
         if extcmds[0] in ("installed", "all"):
             for group in installed:
                 print group.ui_name
@@ -38,7 +40,8 @@ class GroupsCompletionCommand(yumcommands.GroupsCommand):
 
 class ListCompletionCommand(yumcommands.ListCommand):
     def doCommand(self, base, basecmd, extcmds):
-        ypl = base.doPackageLists(pkgnarrow=extcmds[0])
+        ypl = base.doPackageLists(pkgnarrow=extcmds[0],
+                                  patterns=[get_pattern(extcmds)])
         if extcmds[0] in ("installed", "all"):
             for pkg in ypl.installed:
                 print pkg.na
@@ -48,13 +51,21 @@ class ListCompletionCommand(yumcommands.ListCommand):
 
 class RepoListCompletionCommand(yumcommands.RepoListCommand):
     def doCommand(self, base, basecmd, extcmds):
+        import fnmatch
+        pattern = get_pattern(extcmds)
         for repo in base.repos.repos.values():
-            if extcmds[0] == "all" \
-                    or (extcmds[0] == "enabled" and repo.isEnabled()) \
-                    or (extcmds[0] == "disabled" and not repo.isEnabled()):
+            if fnmatch.fnmatch(repo.id, pattern) \
+                    and (extcmds[0] == "all" or
+                         (extcmds[0] == "enabled" and repo.isEnabled()) or
+                         (extcmds[0] == "disabled" and not repo.isEnabled())):
                 print repo.id
 
 
+def get_pattern(extcmds):
+    if len(extcmds) > 1 and extcmds[-1]:
+        return shlex.split(extcmds[-1])[0] + "*"
+    return "*"
+
 def main(args):
     base = cli.YumBaseCli()
     base.yum_cli_commands.clear()
diff --git a/etc/yum.bash b/etc/yum.bash
index 82ba03e..30f8fcf 100644
--- a/etc/yum.bash
+++ b/etc/yum.bash
@@ -3,9 +3,8 @@
 _yum_helper()
 {
     local IFS=$'\n'
-    COMPREPLY+=( $( compgen -W "$(
-        /usr/share/yum-cli/completion-helper.py -d 0 -C $@ 2>/dev/null )" \
-            -- "$cur" ) )
+    COMPREPLY+=( $(
+        /usr/share/yum-cli/completion-helper.py -d 0 -C "$@" 2>/dev/null ) )
 }
 
 _yum_list()


More information about the Yum-commits mailing list