[yum-commits] docs/yum-versionlock.1 docs/yum-versionlock.conf.5 plugins/versionlock

James Antill james at osuosl.org
Tue Nov 16 22:19:26 UTC 2010


 docs/yum-versionlock.1             |   22 +++++++++
 docs/yum-versionlock.conf.5        |    2 
 plugins/versionlock/versionlock.py |   88 ++++++++++++++++++++++++++++++-------
 3 files changed, 97 insertions(+), 15 deletions(-)

New commits:
commit ab7d50f8cc3cc653d569cbcca74c01a3714773f4
Author: James Antill <james at and.org>
Date:   Tue Nov 16 17:18:19 2010 -0500

    Add excludes functionality to versionlock. Document command.

diff --git a/docs/yum-versionlock.1 b/docs/yum-versionlock.1
index 5ca7b9f..f68665e 100644
--- a/docs/yum-versionlock.1
+++ b/docs/yum-versionlock.1
@@ -12,6 +12,28 @@ yum-versionlock - Version lock rpm packages
 is a Yum plugin that takes a set of name/versions for packages and excludes all
 other versions of those packages (including optionally following obsoletes).
 This allows you to protect packages from being updated by newer versions.
+.PP
+The plugin provides a command "versionlock" which allows you to view and edit
+the list of locked packages easily.
+.br
+.I  \fR yum versionlock add <package-wildcard>...
+.PP
+Add a versionlock for all of the packages in the rpmdb matching the given
+wildcards.
+.I  \fR yum versionlock exclude <package-wildcard>...
+.PP
+Add a exclude (within versionlock) for the latest versions of the
+packages in the available repos. matching the given wildcards.
+.I  \fR yum versionlock list
+.PP
+List the current versionlock entries.
+.I  \fR yum versionlock delete <entry-wildcard>...
+.PP
+Remove any matching versionlock entries.
+.I  \fR yum versionlock clear
+.PP
+Remove all versionlock entries.
+
 .SH FILES
 .I /etc/yum/pluginconf.d/versionlock.conf
 .RS
diff --git a/docs/yum-versionlock.conf.5 b/docs/yum-versionlock.conf.5
index f5cd674..78a6e49 100644
--- a/docs/yum-versionlock.conf.5
+++ b/docs/yum-versionlock.conf.5
@@ -18,6 +18,8 @@ This is basically the same as doing an exclude for the package name itself (as
 you cannot exclude installed packages), but yum will still see the versions you
 have installed/versionlocked as available so that "yum reinstall" will still
 work, etc.
+It can also work in the opposite way, like a fast exclude, by prefixing a '!'
+character to the version.
 .SH FILES
 .I /etc/yum/pluginconf.d/versionlock.conf
 .SH FILE FORMAT
diff --git a/plugins/versionlock/versionlock.py b/plugins/versionlock/versionlock.py
index 89a6b83..8538b93 100644
--- a/plugins/versionlock/versionlock.py
+++ b/plugins/versionlock/versionlock.py
@@ -19,12 +19,15 @@
 from yum.plugins import PluginYumExit
 from yum.plugins import TYPE_CORE
 from rpmUtils.miscutils import splitFilename
+from yum.packageSack import packagesNewestByName
+
 import urlgrabber
 import urlgrabber.grabber
 
 import os
 import fnmatch
 import tempfile
+import time
 
 requires_api_version = '2.1'
 plugin_type = (TYPE_CORE,)
@@ -32,6 +35,8 @@ plugin_type = (TYPE_CORE,)
 _version_lock_excluder_n      = set()
 _version_lock_excluder_nevr   = set()
 
+_version_lock_excluder_B_nevr = set()
+
 #  In theory we could do full nevra/pkgtup ... but having foo-1.i386 and not
 # foo-1.x86_64 would be pretty weird. So just do "archless".
 # _version_lock_excluder_pkgtup = set()
@@ -58,7 +63,7 @@ class VersionLockCommand:
         return ["versionlock"]
 
     def getUsage(self):
-        return '[PACKAGE-wildcard]'
+        return '[add|exclude|list|delete|clear] [PACKAGE-wildcard]'
 
     def getSummary(self):
         return 'Control package version locks.'
@@ -69,10 +74,16 @@ class VersionLockCommand:
     def doCommand(self, base, basecmd, extcmds):
         cmd = 'list'
         if extcmds:
-            if extcmds[0] not in ('add', 'list', 'del', 'delete', 'clear'):
+            if extcmds[0] not in ('add',
+                                  'exclude', 'add-!', 'add!', 'blacklist',
+                                  'list', 'del', 'delete', 'clear'):
                 cmd = 'add'
             else:
-                cmd = {'del' : 'delete'}.get(extcmds[0], extcmds[0])
+                cmd = {'del'       : 'delete',
+                       'add-!'     : 'exclude',
+                       'add!'      : 'exclude',
+                       'blacklist' : 'exclude',
+                       }.get(extcmds[0], extcmds[0])
                 extcmds = extcmds[1:]
 
         filename = fileurl
@@ -101,12 +112,39 @@ class VersionLockCommand:
                 done.add((n, a, e, v, r))
 
                 print "Adding versionlock on: %s:%s-%s-%s" % (e, n, v, r)
+                if not count:
+                    fo.write("\n# Added locks on %s\n" % time.ctime())
                 count += 1
                 (n, a, e, v, r) = pkg.pkgtup
                 fo.write("%s:%s-%s-%s.%s\n" % (e, n, v, r, '*'))
 
             return 0, ['versionlock added: ' + str(count)]
 
+        if cmd == 'exclude':
+            pkgs = base.pkgSack.returnPackages(patterns=extcmds)
+            pkgs = packagesNewestByName(pkgs)
+
+            fo = open(filename, 'a')
+            count = 0
+            done = set()
+            for pkg in pkgs:
+                #  We ignore arch, so only add one entry for foo-1.i386 and
+                # foo-1.x86_64.
+                (n, a, e, v, r) = pkg.pkgtup
+                a = '*'
+                if (n, a, e, v, r) in done:
+                    continue
+                done.add((n, a, e, v, r))
+
+                print "Adding exclude on: %s:%s-%s-%s" % (e,n,v,r)
+                if not count:
+                    fo.write("\n# Added excludes on %s\n" % time.ctime())
+                count += 1
+                (n, a, e, v, r) = pkg.pkgtup
+                fo.write("!%s:%s-%s-%s.%s\n" % (e, n, v, r, '*'))
+
+            return 0, ['versionlock added: ' + str(count)]
+
         if cmd == 'clear':
             open(filename, 'w')
             return 0, ['versionlock cleared']
@@ -152,6 +190,25 @@ def config_hook(conduit):
     if hasattr(conduit._base, 'registerCommand'):
         conduit.registerCommand(VersionLockCommand())
 
+def _add_versionlock_whitelist(conduit):
+    if hasattr(conduit, 'registerPackageName'):
+        conduit.registerPackageName("yum-plugin-versionlock")
+    ape = conduit._base.pkgSack.addPackageExcluder
+    exid = 'yum-utils.versionlock.W.'
+    ape(None, exid + str(1), 'wash.marked')
+    ape(None, exid + str(2), 'mark.name.in', _version_lock_excluder_n)
+    ape(None, exid + str(3), 'wash.nevr.in', _version_lock_excluder_nevr)
+    ape(None, exid + str(4), 'exclude.marked')
+
+def _add_versionlock_blacklist(conduit):
+    if hasattr(conduit, 'registerPackageName'):
+        conduit.registerPackageName("yum-plugin-versionlock")
+    ape = conduit._base.pkgSack.addPackageExcluder
+    exid = 'yum-utils.versionlock.B.'
+    ape(None, exid + str(1), 'wash.marked')
+    ape(None, exid + str(2), 'mark.nevr.in', _version_lock_excluder_B_nevr)
+    ape(None, exid + str(3), 'exclude.marked')
+
 def exclude_hook(conduit):
     conduit.info(3, 'Reading version lock configuration')
 
@@ -160,6 +217,10 @@ def exclude_hook(conduit):
 
     pkgs = {}
     for ent in _read_locklist():
+        neg = False
+        if ent and ent[0] == '!':
+            ent = ent[1:]
+            neg = True
         (n, v, r, e, a) = splitFilename(ent)
         n = n.lower()
         v = v.lower()
@@ -167,10 +228,14 @@ def exclude_hook(conduit):
         e = e.lower()
         if e == '': 
             e = '0'
+        if neg:
+            _version_lock_excluder_B_nevr.add("%s-%s:%s-%s" % (n, e, v, r))
+            continue
         _version_lock_excluder_n.add(n)
         _version_lock_excluder_nevr.add("%s-%s:%s-%s" % (n, e, v, r))
 
-    if conduit.confBool('main', 'follow_obsoletes', default=False):
+    if (_version_lock_excluder_n and
+        conduit.confBool('main', 'follow_obsoletes', default=False)):
         #  If anything obsoletes something that we have versionlocked ... then
         # remove all traces of that too.
         for (pkgtup, instTup) in conduit._base.up.getObsoletesTuples():
@@ -178,14 +243,7 @@ def exclude_hook(conduit):
                 continue
             _version_lock_excluder_n.add(pkgtup[0].lower())
 
-    if not _version_lock_excluder_n:
-        return
-
-    if hasattr(conduit, 'registerPackageName'):
-        conduit.registerPackageName("yum-plugin-versionlock")
-    ape = conduit._base.pkgSack.addPackageExcluder
-    exid = 'yum-utils.versionlock.'
-    ape(None, exid + str(1), 'wash.marked')
-    ape(None, exid + str(2), 'mark.name.in', _version_lock_excluder_n)
-    ape(None, exid + str(3), 'wash.nevr.in', _version_lock_excluder_nevr)
-    ape(None, exid + str(4), 'exclude.marked')
+    if _version_lock_excluder_n:
+        _add_versionlock_whitelist(conduit)
+    if _version_lock_excluder_B_nevr:
+        _add_versionlock_blacklist(conduit)


More information about the Yum-commits mailing list