yifengyou / rpms / yum

Forked from rpms/yum 3 years ago
Clone

Blame SOURCES/BZ-1212519-exclude-installed.patch

5e9bef
commit d875b67997356e7e1b4509607fec81ca8220c597
5e9bef
Author: James Antill <james@and.org>
5e9bef
Date:   Tue Mar 3 01:54:02 2015 -0500
5e9bef
5e9bef
    Add query_install_excludes conf./docs and use it for list/info/search/provides.
5e9bef
5e9bef
diff --git a/cli.py b/cli.py
5e9bef
index f04fe63..cefc67e 100755
5e9bef
--- a/cli.py
5e9bef
+++ b/cli.py
5e9bef
@@ -2299,7 +2299,8 @@ class YumOptionParser(OptionParser):
5e9bef
             self.base.conf.disable_excludes = self._splitArg(opts.disableexcludes)
5e9bef
             self.base.conf.disable_includes = self._splitArg(opts.disableincludes)
5e9bef
 
5e9bef
-            for exclude in self._splitArg(opts.exclude):
5e9bef
+            self.base.cmdline_excludes = self._splitArg(opts.exclude)
5e9bef
+            for exclude in self.base.cmdline_excludes:
5e9bef
                 try:
5e9bef
                     excludelist = self.base.conf.exclude
5e9bef
                     excludelist.append(exclude)
5e9bef
diff --git a/docs/yum.conf.5 b/docs/yum.conf.5
5e9bef
index e0f4c8b..62aa78e 100644
5e9bef
--- a/docs/yum.conf.5
5e9bef
+++ b/docs/yum.conf.5
5e9bef
@@ -156,10 +156,20 @@ This is commonly used so a package isn't upgraded or installed accidentally, but
5e9bef
 can be used to remove packages in any way that "yum list" will show packages.
5e9bef
 Shell globs using wildcards (eg. * and ?) are allowed.
5e9bef
 
5e9bef
-Can be disabled using --disableexcludes.
5e9bef
+Can be disabled using disable_excludes or --disableexcludes.
5e9bef
 Command-line option: \fB\-x\fP
5e9bef
 
5e9bef
 .IP
5e9bef
+\fBdisable_excludes\fR
5e9bef
+A way to permanently set the --disableexcludes command line option.
5e9bef
+
5e9bef
+.IP
5e9bef
+\fBquery_install_excludes\fR
5e9bef
+This applies the command line exclude option (only, not the configuration
5e9bef
+exclude above) to installed packages being shown in some query commands
5e9bef
+(currently: list/info/search/provides).
5e9bef
+
5e9bef
+.IP
5e9bef
 \fBinstallonlypkgs \fR
5e9bef
 List of package provides that should only ever be installed, never updated.
5e9bef
 Kernels in particular fall into this category. Defaults to kernel,
5e9bef
diff --git a/output.py b/output.py
5e9bef
index 2787d86..091b58e 100755
5e9bef
--- a/output.py
5e9bef
+++ b/output.py
5e9bef
@@ -1330,6 +1330,13 @@ class YumOutput:
5e9bef
         :param verbose: whether to output extra verbose information
5e9bef
         :param highlight: highlighting options for the highlighted matches
5e9bef
         """
5e9bef
+        if (po.repo.id == "installed" and
5e9bef
+            self.conf.query_install_excludes and self.cmdline_excludes):
5e9bef
+            # Very similar to _cmdline_exclude from yumcommands
5e9bef
+            e,m,u = yum.packages.parsePackages([po], self.cmdline_excludes)
5e9bef
+            if e or m:
5e9bef
+                return
5e9bef
+
5e9bef
         if self.conf.showdupesfromrepos:
5e9bef
             msg = '%s : ' % po
5e9bef
         else:
5e9bef
diff --git a/yum/config.py b/yum/config.py
5e9bef
index 02061ba..efe7be9 100644
5e9bef
--- a/yum/config.py
5e9bef
+++ b/yum/config.py
5e9bef
@@ -821,6 +821,7 @@ class YumConf(StartupConf):
5e9bef
     # XXX rpm_check_debug is unused, left around for API compatibility for now
5e9bef
     rpm_check_debug = BoolOption(True)
5e9bef
     disable_excludes = ListOption()    
5e9bef
+    query_install_excludes = BoolOption(True)
5e9bef
     skip_broken = BoolOption(False)
5e9bef
     #  Note that "instant" is the old behaviour, but group:primary is very
5e9bef
     # similar but better :).
5e9bef
diff --git a/yumcommands.py b/yumcommands.py
5e9bef
index e77d209..6fa11fa 100644
5e9bef
--- a/yumcommands.py
5e9bef
+++ b/yumcommands.py
5e9bef
@@ -41,6 +41,7 @@ import errno
5e9bef
 
5e9bef
 import yum.config
5e9bef
 from yum import updateinfo
5e9bef
+from yum.packages import parsePackages
5e9bef
 
5e9bef
 def _err_mini_usage(base, basecmd):
5e9bef
     if basecmd not in base.yum_cli_commands:
5e9bef
@@ -584,6 +585,14 @@ def _list_cmd_calc_columns(base, ypl):
5e9bef
     columns = base.calcColumns(data, remainder_column=1)
5e9bef
     return (-columns[0], -columns[1], -columns[2])
5e9bef
 
5e9bef
+def _cmdline_exclude(pkgs, cmdline_excludes):
5e9bef
+    """ Do an extra exclude for installed packages that match the cmd line. """
5e9bef
+    if not cmdline_excludes:
5e9bef
+        return pkgs
5e9bef
+    e,m,u = parsePackages(pkgs, cmdline_excludes)
5e9bef
+    excluded = set(e + m)
5e9bef
+    return [po for po in pkgs if po not in excluded]
5e9bef
+
5e9bef
 class InfoCommand(YumCommand):
5e9bef
     """A class containing methods needed by the cli to execute the
5e9bef
     info command.
5e9bef
@@ -682,6 +691,9 @@ class InfoCommand(YumCommand):
5e9bef
             clin = base.conf.color_list_installed_newer
5e9bef
             clir = base.conf.color_list_installed_reinstall
5e9bef
             clie = base.conf.color_list_installed_extra
5e9bef
+            if base.conf.query_install_excludes:
5e9bef
+                ypl.installed = _cmdline_exclude(ypl.installed,
5e9bef
+                                                 base.cmdline_excludes)
5e9bef
             rip = base.listPkgs(ypl.installed, _('Installed Packages'), basecmd,
5e9bef
                                 highlight_na=update_pkgs, columns=columns,
5e9bef
                                 highlight_modes={'>' : clio, '<' : clin,