[yum-commits] Branch 'yum-3_2_X' - 2 commits - cli.py docs/yum.8 yum/__init__.py

James Antill james at osuosl.org
Thu Aug 19 21:13:36 UTC 2010


 cli.py          |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 docs/yum.8      |   11 +++++++---
 yum/__init__.py |    3 ++
 3 files changed, 65 insertions(+), 8 deletions(-)

New commits:
commit 11db8260419aa7183b98f7f1edb84d18cba412c3
Author: James Antill <james at and.org>
Date:   Thu Aug 19 15:17:09 2010 -0400

     Make our search command a bit more usable, try name/summary only first:
    
    1. yum search all blah -- still does the old thing.
    
    2. yum search yum alias -- just shows name/summary hits for yum+alias.
    
    3. yum search yum smart -- shows name/summary hits for yum, smart and
       "traditional" search for yum+smart.
    
    4. yum search 'USB 802.11a' -- does the same old thing.
    
    ...this drastically reduces the printed results.

diff --git a/cli.py b/cli.py
index 9542b7a..3e837ae 100644
--- a/cli.py
+++ b/cli.py
@@ -931,22 +931,71 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         searchlist = ['name', 'summary', 'description', 'url']
         dups = self.conf.showdupesfromrepos
         args = map(to_unicode, args)
+
+        okeys = set()
+        akeys = set() # All keys, used to see if nothing matched
+        mkeys = set() # "Main" set of keys for N/S search (biggest term. hit).
+        pos   = set()
+
+        def _print_match_section(text):
+            # Print them in the order they were passed
+            used_keys = [arg for arg in args if arg in keys]
+            print self.fmtSection(text % ", ".join(used_keys))
+
+        #  First try just the name/summary fields, and if we get any hits
+        # don't do the other stuff. Unless the user overrides via. "all".
+        if len(args) > 1 and args[0] == 'all':
+            args.pop(0)
+        else:
+            matching = self.searchGenerator(['name', 'summary'], args,
+                                            showdups=dups, keys=True)
+            for (po, keys, matched_value) in matching:
+                if keys != okeys:
+                    if akeys:
+                        if len(mkeys) == len(args):
+                            break
+                        print ""
+                    else:
+                        mkeys = set(keys)
+                    _print_match_section(_('N/S Matched: %s'))
+                    okeys = keys
+                pos.add(po)
+                akeys.update(keys)
+                self.matchcallback(po, matched_value, args)
+
         matching = self.searchGenerator(searchlist, args,
                                         showdups=dups, keys=True)
-        
+
         okeys = set()
-        akeys = set()
+
+        #  If we got a hit with just name/summary then we only care about hits
+        # with _more_ search terms. Thus. if we hit all our search terms. do
+        # nothing.
+        if len(mkeys) == len(args):
+            print ""
+            if len(args) == 1:
+                msg = _('  Name and summary matches %sonly%s, use "search all" for everything.')
+            else:
+                msg = _('  Full name and summary matches %sonly%s, use "search all" for everything.')
+            print msg % (self.term.MODE['bold'], self.term.MODE['normal'])
+            matching = []
+
         for (po, keys, matched_value) in matching:
+            if len(keys) <= len(mkeys) or po in pos:
+                continue # Don't print stuff from N/S...
+
             if keys != okeys:
                 if akeys:
                     print ""
-                # Print them in the order they were passed
-                used_keys = [arg for arg in args if arg in keys]
-                print self.fmtSection(_('Matched: %s') % ", ".join(used_keys))
+                _print_match_section(_('Matched: %s'))
                 okeys = keys
                 akeys.update(keys)
             self.matchcallback(po, matched_value, args)
 
+        if mkeys and len(mkeys) != len(args):
+            print ""
+            print _('  Name and summary matches %smostly%s, use "search all" for everything.') % (self.term.MODE['bold'], self.term.MODE['normal'])
+
         for arg in args:
             if arg not in akeys:
                 self.logger.warning(_('Warning: No matches found for: %s'), arg)
diff --git a/docs/yum.8 b/docs/yum.8
index 281bf17..d21c9fd 100644
--- a/docs/yum.8
+++ b/docs/yum.8
@@ -155,9 +155,14 @@ or file. Just use a specific name or a file-glob-syntax wildcards to list
 the packages available or installed that provide that feature or file\&.
 .IP 
 .IP "\fBsearch\fP"
-Is used to find any packages matching a string in the description, summary
-and package name fields of an rpm. Useful for finding a package
-you do not know by name but know by some word related to it. 
+This is used to find packages when you know something about the package but
+aren't sure of it's name. By default search will try searching just package
+names and summaries, but if that "fails" it will then try descriptions and url.
+
+Yum search orders the results so that those packages matching more terms will
+appear first.
+
+You can force searching everything by specifying "all" as the first argument.
 .IP 
 .IP "\fBinfo\fP"
 Is used to list a description and summary information about available
commit d326fd36118efa04a5c9697cbe62a86e3a358401
Author: James Antill <james at and.org>
Date:   Thu Aug 19 08:48:37 2010 -0400

    If obsoletes processing is off, don't look for obsoletes (mainly local pkgs).

diff --git a/yum/__init__.py b/yum/__init__.py
index 3a9ef88..1ddecc2 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -3111,6 +3111,9 @@ class YumBase(depsolve.Depsolve):
 
     def _find_obsoletees(self, po):
         """ Return the pkgs. that are obsoleted by the po we pass in. """
+        if not self.conf.obsoletes:
+            return
+
         if not isinstance(po, YumLocalPackage):
             for (obstup, inst_tup) in self.up.getObsoletersTuples(name=po.name):
                 if po.pkgtup == obstup:


More information about the Yum-commits mailing list