[yum-git] plugins/remove-with-leaves yum-utils.spec
Seth Vidal
skvidal at linux.duke.edu
Mon Sep 8 18:35:28 UTC 2008
plugins/remove-with-leaves/remove-with-leaves.conf | 2
plugins/remove-with-leaves/remove-with-leaves.py | 95 +++++++++++++++++++++
yum-utils.spec | 18 +++
3 files changed, 115 insertions(+)
New commits:
commit 0439adaeaa7c7b623a12bb57cffaa9e930d3c93f
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Mon Sep 8 14:33:31 2008 -0400
add remove-with-leaves plugin and update spec file
diff --git a/plugins/remove-with-leaves/remove-with-leaves.conf b/plugins/remove-with-leaves/remove-with-leaves.conf
new file mode 100644
index 0000000..e7002aa
--- /dev/null
+++ b/plugins/remove-with-leaves/remove-with-leaves.conf
@@ -0,0 +1,2 @@
+[main]
+enabled = 1
diff --git a/plugins/remove-with-leaves/remove-with-leaves.py b/plugins/remove-with-leaves/remove-with-leaves.py
new file mode 100644
index 0000000..38b0bf2
--- /dev/null
+++ b/plugins/remove-with-leaves/remove-with-leaves.py
@@ -0,0 +1,95 @@
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+# Copyright 2008 Red Hat, Inc
+# written by Seth Vidal <skvidal at fedoraproject.org>
+
+"""
+This plugin allows packages to clean up dependencies they pulled in which are
+not in use by any other package.
+"""
+
+
+from yum.plugins import TYPE_CORE, TYPE_INTERACTIVE, PluginYumExit
+from yum.constants import *
+
+requires_api_version = '2.4'
+plugin_type = (TYPE_CORE, TYPE_INTERACTIVE)
+
+_requires_cache = {}
+ignore_list = ['glibc', 'bash', 'libgcc']
+
+
+def _requires_this_package(rpmdb, pkg):
+ if _requires_cache.has_key(pkg):
+ return _requires_cache[pkg]
+
+ requirers = {}
+ for prov in pkg.provides:
+ for req_pkg in rpmdb.getRequires(prov[0], prov[1], prov[2]):
+ if req_pkg == pkg:
+ continue
+ requirers[req_pkg.pkgtup] = 1
+ # do filelists, too :(
+ for prov in pkg.filelist + pkg.dirlist + pkg.ghostlist:
+ for req_pkg in rpmdb.getRequires(prov):
+ if req_pkg == pkg:
+ continue
+ requirers[req_pkg.pkgtup] = 1
+
+ _requires_cache[pkg] = requirers.keys()
+ return requirers.keys()
+
+def postresolve_hook(conduit):
+ # get all the items in
+ tsInfo = conduit.getTsInfo()
+ rpmdb = conduit.getRpmDB()
+ oldlen = 0
+ while oldlen != len(tsInfo):
+ oldlen = len(tsInfo)
+ for txmbr in tsInfo.getMembersWithState(output_states=TS_REMOVE_STATES):
+ if conduit._base.allowedMultipleInstalls(txmbr.po):
+ # these make everything dodgy, skip it
+ continue
+ for req in txmbr.po.requires:
+ if req[0].startswith('rpmlib('):
+ continue
+ for pkg in rpmdb.getProvides(req[0], req[1], req[2]):
+ if pkg.pkgtup in [ txmbr.po.pkgtup for txmbr in tsInfo.getMembersWithState(output_states=TS_REMOVE_STATES) ]:
+ continue # skip ones already marked for remove, kinda pointless
+ if pkg.name in ignore_list: # there are some pkgs which are NEVER going to be leafremovals
+ continue
+ non_removed_requires = []
+ for req_pkgtup in _requires_this_package(rpmdb,pkg):
+ pkgtups = [ txmbr.po.pkgtup for txmbr in tsInfo.getMembersWithState(output_states=TS_REMOVE_STATES) ]
+ if req_pkgtup not in pkgtups:
+ non_removed_requires.append(req_pkgtup)
+
+ #FIXME - go through the non_removed_requires and see if any of them are in the list of
+ # requirements, too
+
+ if not non_removed_requires:
+ conduit.info(2, 'removing %s. It is not required by anything else.' % pkg)
+ conduit._base.remove(pkg)
+
+
+
+
+
+
+
+
+
+
diff --git a/yum-utils.spec b/yum-utils.spec
index 9cd5bc4..615ee31 100644
--- a/yum-utils.spec
+++ b/yum-utils.spec
@@ -261,6 +261,16 @@ Requires: yum >= 3.2.19
This plugin adds the commands keys, keys-info, keys-data and keys-remove. They
allow you to query and remove signing keys.
+%package -n yum-remove-with-leaves
+Summary: Yum plugin to remove dependencies which are no longer used because of a removal
+Group: System Environment/Base
+Requires: yum >= 3.2.19
+
+%description -n yum-remove-with-leaves
+This plugin removes any unused dependencies that were brought in by an install
+but would not normally be removed. It helps to keep a system clean of unused
+libraries and packages.
+
%package -n yum-NetworkManager-dispatcher
Summary: Yum plugin to deal with changing networks with NetworkManager
Group: System Environment/Base
@@ -305,6 +315,7 @@ plugins="\
tmprepo \
verify \
keys \
+ remove-with-leaves \
"
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/yum/pluginconf.d/ $RPM_BUILD_ROOT/usr/lib/yum-plugins/
@@ -498,7 +509,14 @@ fi
%defattr(-, root, root)
/etc/NetworkManager/dispatcher.d/*
+%files -n yum-remove-with-leaves
+%defattr(-, root, root)
+/usr/lib/yum-plugins/remove-with-leaves.*
+
%changelog
+* Mon Sep 8 2008 Seth Vidal <skvidal at fedoraproject.org>
+- add yum-remove-with-leaves plugin
+
* Wed Aug 27 2008 Tim Lauridsen <timlau at fedoraproject.org>
- mark as 1.1.16
* Wed Aug 20 2008 James Antill <james at fedoraproject.org>
More information about the Yum-cvs-commits
mailing list