[Yum-devel] [PATCH 7/8] Add remove_leaf_only and repopkg* options, use removeReq cb and fix the API.
James Antill
james at and.org
Wed Jan 16 07:26:05 UTC 2013
---
docs/yum.conf.5 | 20 ++++++++++++++++++++
output.py | 9 +++++----
yum/config.py | 2 ++
yum/depsolve.py | 26 +++++++++++++++++++++++++-
yum/transactioninfo.py | 1 +
yumcommands.py | 8 ++++++++
6 files changed, 61 insertions(+), 5 deletions(-)
diff --git a/docs/yum.conf.5 b/docs/yum.conf.5
index 30ac844..17f9bae 100644
--- a/docs/yum.conf.5
+++ b/docs/yum.conf.5
@@ -201,12 +201,32 @@ Default is `true'.
Command-line option: \fB\-\-obsoletes\fP
.IP
+\fBremove_leaf_only \fR
+Either `0' or `1'. Used to determine yum's behaviour when a package is removed.
+If \fBremove_leaf_only\fR is `0' (default) then
+packages, and their deps, will be removed. If \fBremove_leaf_only\fR is
+`1' then only those packages that aren't required by another
+package will be removed.
+
+.IP
+\fBrepopkgsremove_leaf_only \fR
+Either `0' or `1'. Used to determine yum's behaviour when the repo-pkg remove
+command is run. If \fBrepopkgremove_leaf_only\fR is `0' (default) then
+all packages in the repo. will be removed. If \fBrepopkgremove_leaf_only\fR is
+`1' then only those packages in the repo. that aren't required by another
+package will be removed.
+Note that this option does not override remove_leaf_only, so enabling that
+option means this has almost no affect.
+
+.IP
\fBoverwrite_groups \fR
Either `0' or `1'. Used to determine yum's behaviour if two or more
repositories offer the package groups with the same name. If
\fBoverwrite_groups\fR is `1' then the group packages of the last matching
repository will be used. If \fBoverwrite_groups\fR is `0' then the groups
from all matching repositories will be merged together as one large group.
+Note that this option does not override remove_leaf_only, so enabling that
+option means this has almost no affect.
.IP
\fBgroupremove_leaf_only \fR
diff --git a/output.py b/output.py
index 885eb09..26e3928 100755
--- a/output.py
+++ b/output.py
@@ -2827,17 +2827,18 @@ class DepSolveProgressCallBack:
_('--> Processing Dependency: %s for package: %s'), formatted_req,
po)
- def groupRemoveReq(self, po, hits):
+ def removeReq(self, po, deppo, hits):
"""Output a message stating that the given package will not be
- removed. This method is used during leaf-only group remove
- commands to indicate that the package will be kept.
+ removed. This method is used during leaf-only group remove, leaf-only
+ repo-pkg remove and normal remove commands to indicate that the
+ package will be kept.
:param po: the :class:`yum.packages.PackageObject` that will
not be removed
:param hits: unused
"""
self.verbose_logger.log(logginglevels.INFO_2,
- _('---> Keeping package: %s'), po)
+ _('---> Keeping package: %s due to %s'), po, deppo)
def unresolved(self, msg):
"""Output a message stating that there is an unresolved
diff --git a/yum/config.py b/yum/config.py
index 3cdb0fd..5856aa2 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -774,6 +774,8 @@ class YumConf(StartupConf):
obsoletes = BoolOption(True)
showdupesfromrepos = BoolOption(False)
enabled = BoolOption(True)
+ remove_leaf_only = BoolOption(False)
+ repopkgsremove_leaf_only = BoolOption(False)
enablegroups = BoolOption(True)
enable_group_conditionals = BoolOption(True)
groupremove_leaf_only = BoolOption(False)
diff --git a/yum/depsolve.py b/yum/depsolve.py
index a16f1f5..74f9a48 100644
--- a/yum/depsolve.py
+++ b/yum/depsolve.py
@@ -1121,12 +1121,36 @@ class Depsolve(object):
# FIXME: This is probably the best place to fix the postfix rename
# problem long term (post .21) ... see compare_providers.
for pkg, hits in self.tsInfo.getRequires(*prov).iteritems():
- # See the docs, this is to make groupremove "more useful".
+ # See the docs, this is to make remove* "more useful".
+ if (self.conf.repopkgsremove_leaf_only and txmbr.repopkg and
+ txmbr.output_state == TS_ERASE):
+ cb = self.dsCallback
+ if cb and hasattr(cb, 'repoPkgRemoveReq'):
+ cb.repoPkgRemoveReq(txmbr.po, hits)
+ elif cb and hasattr(cb, 'removeReq'):
+ cb.removeReq(txmbr.po, pkg, hits)
+ # We don't undo anything else here ... hopefully that's
+ # fine.
+ self.tsInfo.remove(txmbr.pkgtup)
+ return []
+
if (self.conf.groupremove_leaf_only and txmbr.groups and
txmbr.output_state == TS_ERASE):
cb = self.dsCallback
if cb and hasattr(cb, 'groupRemoveReq'):
cb.groupRemoveReq(pkg, hits)
+ elif cb and hasattr(cb, 'removeReq'):
+ cb.removeReq(txmbr.po, pkg, hits)
+ # We don't undo anything else here ... hopefully that's
+ # fine.
+ self.tsInfo.remove(txmbr.pkgtup)
+ return []
+
+ if (self.conf.remove_leaf_only and
+ txmbr.output_state == TS_ERASE):
+ cb = self.dsCallback
+ if cb and hasattr(cb, 'removeReq'):
+ cb.removeReq(txmbr.po, pkg, hits)
# We don't undo anything else here ... hopefully that's
# fine.
self.tsInfo.remove(txmbr.pkgtup)
diff --git a/yum/transactioninfo.py b/yum/transactioninfo.py
index 2fdd8f0..8545bac 100644
--- a/yum/transactioninfo.py
+++ b/yum/transactioninfo.py
@@ -794,6 +794,7 @@ class TransactionMember:
self.reinstall = False
self.groups = [] # groups it's in
self.environments = [] # Env. groups it's in
+ self.repopkg = None # repo pkg "group" it was removed/installed by
self._poattr = ['pkgtup', 'repoid', 'name', 'arch', 'epoch', 'version',
'release']
diff --git a/yumcommands.py b/yumcommands.py
index 8ad588f..591b541 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -3289,6 +3289,10 @@ class RepoPkgsCommand(YumCommand):
2 = we've got work yet to do, onto the next stage
"""
+ def _add_repopkg2txmbrs(txmbrs, repoid):
+ for txmbr in txmbrs:
+ txmbr.repopkg = repoid
+
repoid = extcmds[0]
cmd = extcmds[1]
args = extcmds[2:]
@@ -3299,6 +3303,7 @@ class RepoPkgsCommand(YumCommand):
elif cmd == 'install': # install is simpler version of installPkgs...
for arg in args:
txmbrs = base.install(pattern=arg, repoid=repoid)
+ _add_repopkg2txmbrs(txmbrs, repoid)
num += len(txmbrs)
if num:
@@ -3308,6 +3313,7 @@ class RepoPkgsCommand(YumCommand):
elif cmd == 'remove': # Also mostly the same...
for arg in args:
txmbrs = base.remove(pattern=arg, repoid=repoid)
+ _add_repopkg2txmbrs(txmbrs, repoid)
num += len(txmbrs)
if num:
@@ -3326,6 +3332,7 @@ class RepoPkgsCommand(YumCommand):
txmbrs += base.install(po=pkg)
break
+ _add_repopkg2txmbrs(txmbrs, repoid)
num += len(txmbrs)
elif cmd == 'remove-or-sync': # Even more complicated...
@@ -3358,6 +3365,7 @@ class RepoPkgsCommand(YumCommand):
txmbrs.remove(txmbr)
txmbrs += base.downgrade(po=toinst)
+ _add_repopkg2txmbrs(txmbrs, repoid)
num += len(txmbrs)
if num:
--
1.7.6.5
More information about the Yum-devel
mailing list