[yum-cvs] plugins/upgrade-helper yum-utils.spec

Seth Vidal skvidal at linux.duke.edu
Fri Oct 26 17:00:56 UTC 2007


 plugins/upgrade-helper/remove-stuff.xml    |    4 
 plugins/upgrade-helper/upgrade-helper.conf |    2 
 plugins/upgrade-helper/upgrade-helper.py   |  123 +++++++++++++++++++++++++++++
 yum-utils.spec                             |   16 +++
 4 files changed, 145 insertions(+)

New commits:
commit 77aa524f729805411c4efbc27f4426c1ad0bf44e
Author: Seth Vidal <skvidal at fedoraproject.org>
Date:   Fri Oct 26 12:56:53 2007 -0400

    add upgrade-helper - this _should_ work - but I'll be testing it some more before tagging

diff --git a/plugins/upgrade-helper/remove-stuff.xml b/plugins/upgrade-helper/remove-stuff.xml
new file mode 100644
index 0000000..a3c3826
--- /dev/null
+++ b/plugins/upgrade-helper/remove-stuff.xml
@@ -0,0 +1,4 @@
+<cleanup>
+  <removespec pkgmatch="zsh.i386" on_arch="x86_64"/>
+  <removespec pkgmatch="zvbi"/>
+</cleanup>
diff --git a/plugins/upgrade-helper/upgrade-helper.conf b/plugins/upgrade-helper/upgrade-helper.conf
new file mode 100644
index 0000000..e7002aa
--- /dev/null
+++ b/plugins/upgrade-helper/upgrade-helper.conf
@@ -0,0 +1,2 @@
+[main]
+enabled = 1
diff --git a/plugins/upgrade-helper/upgrade-helper.py b/plugins/upgrade-helper/upgrade-helper.py
new file mode 100644
index 0000000..5c5c9fc
--- /dev/null
+++ b/plugins/upgrade-helper/upgrade-helper.py
@@ -0,0 +1,123 @@
+#!/usr/bin/python -tt
+# 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 2007 Red Hat, Inc
+# Written by Seth Vidal
+
+# upgrade-helper plugin
+# cleans out orphans and impossible-to-update/obsolete-away pkgs
+
+# download list of stuff to kill from each repo, if there
+# parse it and load it into memory
+#  - make sure that any pkgspec matching: a lot of things *? or * or . or what not
+#    will be ignored
+
+
+#format of the file is:
+#<cleanup>
+#  <removespec pkgmatch="zsh.i386" on_arch="x86_64"/>
+#  <removespec pkgmatch="zvbi"/>
+#</cleanup>
+
+# for all the ones for anything in your arch
+#  if something is installed matching it, then add it to the TS to be removed
+# do all this only if:
+   # running as root
+   # the command being run is 'update' or 'install'  (or performing those functions somehow)
+
+from yum.plugins import TYPE_CORE
+from yum.constants import *
+from yum import config
+import rpmUtils.arch
+from yum.repoMDObject import ns_cleanup
+
+import gzip
+
+try:
+    from xml.etree import cElementTree
+except ImportError:
+    import cElementTree
+iterparse = cElementTree.iterparse
+
+
+requires_api_version = '2.5'
+plugin_type = (TYPE_CORE,)
+myarch = rpmUtils.arch.getBaseArch()
+
+def parse_xml(xmlfile):
+    """parse the xml file and hand back the contents in a usable form"""
+    # store results in a dict of on_arch = list_of_pkgs
+    results = {}
+    results[myarch] = []
+    
+    xfo = gzip.open(xmlfile, 'rt')
+    parser = iterparse(xfo)
+    for ev, elem in parser:
+        for child in elem:
+            child_name = ns_cleanup(child.tag)
+            thisarch = myarch
+            if child_name == 'removespec':
+                if child.attrib.has_key('on_arch'):
+                    thisarch = child.attrib.get('on_arch')
+                if child.attrib.has_key('pkgmatch'):
+                    thismatch = child.attrib.get('pkgmatch')
+                    if results.has_key(thisarch):
+                        if thismatch not in results[thisarch]:
+                            results[thisarch].append(thismatch)
+                        else:
+                            results[thisarch] = [thismatch]
+    return results
+    
+def stuff_to_remove(repos):
+    toremove = []
+    
+    # for repo in my repos
+    #  grab the cleanup file
+    #  parse it
+    #  merge all the results for $myarch together
+    #  return them as the toremove list
+
+    for repo in repos.listEnabled():
+        if repo.repoXML.repoData.has_key('cleanup'):
+            trf = repo.retrieveMD('cleanup')
+            tr_dict = parse_xml(trf)
+            # prune out things like *, ?, *.*, *.*.*.*.*
+            # etc
+            badmatches = ['*', '?', '*.*', 'glibc', 'kernel', 'yum', 'rpm']
+            
+            for pm in tr_dict[myarch]:
+                if pm in badmatches:
+                    continue
+                # other tests here?
+                toremove.append(pm)
+    
+    return toremove
+
+def preresolve_hook(conduit):
+    """add all of these into the ts to be removed"""
+    ts = conduit.getTsInfo()
+    # only run it if we're installing/updating something, don't do it if 
+    # we're removing only
+    runme = False
+    for mbr in ts.getMembers():
+        if mbr.output_state in TS_INSTALL_STATES:
+            runme = True
+            break
+    if runme:
+        rpmdb = conduit.getRpmDB()
+        for pkgglob in stuff_to_remove(conduit.getRepos()):
+            for po in rpmdb.matchPackageNames(pkgglob, casematch=True):
+                conduit.info(1, "Setting %s to be removed due to repository metadata in cleanup plugin" % po)
+                ts.addErase(po)
+
diff --git a/yum-utils.spec b/yum-utils.spec
index 18efd64..f246c05 100644
--- a/yum-utils.spec
+++ b/yum-utils.spec
@@ -185,6 +185,15 @@ If you type 'yum install foo' on a x68_64 system, only 'foo-x.y.x86_46.rpm' is i
 If you want to install the foo-x.y.i386.rpm, you have to type 'yum install foo.i386'.
 The plugin only works with 'yum install'.
 
+%package -n yum-upgrade-helper
+Summary: Yum plugin to help upgrades to the next distribution version
+Group: System Environment/Base
+Requires: yum >= 3.0
+
+%description -n yum-upgrade-helper
+this plugin allows yum to erase specific packages on install/update based on an additional
+metadata file in repositories. It is used to simplify distribution upgrade hangups.
+
 
 %prep
 %setup -q
@@ -332,8 +341,15 @@ fi
 %config(noreplace) %{_sysconfdir}/yum/pluginconf.d/basearchonly.conf
 /usr/lib/yum-plugins/basearchonly.*
 
+%files -n yum-upgrade-helper
+%defattr(-, root, root)
+%config(noreplace) %{_sysconfdir}/yum/pluginconf.d/upgrade-helper.conf
+/usr/lib/yum-plugins/upgrade-helper.*
+
 
 %changelog
+* Fri Oct 26 2007 Seth Vidal <skvidal at fedoraproject.org>
+- add upgrade-helper plugin
 * Wed Oct 17 2007 Tim Lauridsen <tla at rasmil.dk>
 - mark as 1.1.8
 * Sun Sep 30 2007 James Bowes <jbowes at redhat.com>



More information about the Yum-cvs-commits mailing list