[yum-git] 2 commits - plugins/aliases plugins/tmprepo yum-utils.spec

James Antill james at linux.duke.edu
Tue Jan 29 14:13:48 UTC 2008


 plugins/aliases/aliases.py   |   11 ++++
 plugins/tmprepo/tmprepo.conf |    5 ++
 plugins/tmprepo/tmprepo.py   |  103 +++++++++++++++++++++++++++++++++++++++++++
 yum-utils.spec               |   18 +++++++
 4 files changed, 135 insertions(+), 2 deletions(-)

New commits:
commit e3862e248a05f26a5afe04a3577e830336f1b871
Author: James Antill <james at and.org>
Date:   Mon Jan 28 17:56:27 2008 -0500

    Add --tmprepo as a plugin

diff --git a/plugins/tmprepo/tmprepo.conf b/plugins/tmprepo/tmprepo.conf
new file mode 100644
index 0000000..f5e3b83
--- /dev/null
+++ b/plugins/tmprepo/tmprepo.conf
@@ -0,0 +1,5 @@
+[main]
+enabled=1
+# You can uncomment this to allow tmporary repositories to disable/alter
+# gpg checking. This is not recommended.
+# gpgcheck=false
diff --git a/plugins/tmprepo/tmprepo.py b/plugins/tmprepo/tmprepo.py
new file mode 100644
index 0000000..83e6054
--- /dev/null
+++ b/plugins/tmprepo/tmprepo.py
@@ -0,0 +1,103 @@
+#!/usr/bin/python
+
+# 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 Red Hat Inc. 2007, 2008
+#
+# Author: James Antill <james at fedoraproject.com>
+# Examples:
+#
+# yum --tmprepo=http://example.com/foo/bar.repo ...
+
+import yum
+import types
+from yum.plugins import TYPE_INTERACTIVE
+import logging # for commands
+from yum import logginglevels
+
+import logging
+import urlgrabber.grabber
+import tempfile
+
+requires_api_version = '2.5'
+plugin_type = (TYPE_INTERACTIVE,)
+
+def make_validate(log, gpgcheck):
+    def tvalidate(repo):
+        if gpgcheck:
+    
+            # Don't allow them to set gpgcheck=False
+            if not repo.gpgcheck:
+                log.warn("Repo %s tried to set gpgcheck=false" % repo)
+                return False
+            
+            # Don't allow them to set gpgkey=anything
+            for key in repo.gpgkey:
+                if not key.startswith('file:/'):
+                    log.warn("Repo %s tried to set gpgkey to %s" %
+                             (repo, repo.gpgkey))
+                    return False
+
+        return True
+
+    return tvalidate
+
+def add_repos(base, log, tmp_repos, tvalidate):
+    """ Add temporary repos to yum. """
+    # Don't use self._splitArg()? ... or require URLs without commas?
+    for trepo in tmp_repos:
+        tfo   = tempfile.NamedTemporaryFile()
+        fname = tfo.name
+        grab = urlgrabber.grabber.URLGrabber()
+        try:
+            grab.urlgrab(trepo, fname)
+        except urlgrabber.grabber.URLGrabError, e:
+            log.warn("Failed to retrieve " + trepo)
+            continue
+
+        base.getReposFromConfigFile(fname, validate=tvalidate)
+        added = True
+
+    # Just do it all again...
+    base.setupProgressCallbacks()
+
+my_gpgcheck = True
+def config_hook(conduit):
+    '''
+    Yum Plugin Config Hook: 
+    Add the --tmprepo option.
+    '''
+    global my_gpgcheck
+    
+    parser = conduit.getOptParser()
+    if not parser:
+        return
+
+    parser.values.tmp_repos = []
+    parser.add_option("--tmprepo", action='append',
+                      type='string', dest='tmp_repos', default=[],
+                      help="enable one or more repositories from URLs",
+                      metavar='[url]')
+    my_gpgcheck = conduit.confBool('main', 'gpgcheck', default=True)
+
+def prereposetup_hook(conduit):
+    '''
+    Process the tmp repos from --tmprepos.
+    '''
+
+    opts, args = conduit.getCmdLine()
+    log = logging.getLogger("yum.verbose.main")
+    add_repos(conduit._base, log, opts.tmp_repos,
+              make_validate(log, my_gpgcheck))
diff --git a/yum-utils.spec b/yum-utils.spec
index 7f33b82..ef3f6ce 100644
--- a/yum-utils.spec
+++ b/yum-utils.spec
@@ -212,6 +212,17 @@ Requires: yum >= 3.0.5
 This plugin adds the commands list-vendors, groups, baseurls, packagers,
 buildhosts, licenses and arches.
 
+%package -n yum-tmprepo
+Summary: Yum plugin to add temporary repositories
+Group: System Environment/Base
+Requires: yum >= 3.0.5
+
+%description -n yum-tmprepo
+This plugin adds the option --tmprepo which takes a url to a .repo file
+downloads it and enables it for a single run. This plugin tries to ensure
+that temporary repositories are safe to use, by default, by not allowing
+gpg checking to be disabled.
+
 %prep
 %setup -q
 
@@ -223,7 +234,7 @@ make -C updateonboot DESTDIR=$RPM_BUILD_ROOT install
 # Plugins to install
 plugins="changelog fastestmirror fedorakmod protectbase versionlock tsflags kernel-module \
          downloadonly allowdowngrade skip-broken priorities refresh-updatesd merge-conf \
-         security protect-packages basearchonly upgrade-helper aliases list-data"
+         security protect-packages basearchonly upgrade-helper aliases list-data tmprepo"
 
 mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/yum/pluginconf.d/ $RPM_BUILD_ROOT/usr/lib/yum-plugins/
 
@@ -379,6 +390,11 @@ fi
 %config(noreplace) %{_sysconfdir}/yum/pluginconf.d/list-data.conf
 /usr/lib/yum-plugins/list-data.*
 
+%files -n yum-tmprepo
+%defattr(-, root, root)
+%config(noreplace) %{_sysconfdir}/yum/pluginconf.d/tmprepo.conf
+/usr/lib/yum-plugins/tmprepo.*
+
 
 %changelog
 * Sun Jan 13 2008 Seth Vidal <skvidal at fedoraproject.org>
commit 15720a0fcd7909ba35a21c7e467ef4e1cdd16929
Author: James Antill <james at and.org>
Date:   Mon Jan 28 17:52:23 2008 -0500

    New help info. for aliases

diff --git a/plugins/aliases/aliases.py b/plugins/aliases/aliases.py
index 4fe8470..e17e4a9 100644
--- a/plugins/aliases/aliases.py
+++ b/plugins/aliases/aliases.py
@@ -41,7 +41,10 @@ class AliasedCommand:
         return [self.cmd]
 
     def getUsage(self):
-        return self.getNames()[0]
+        return ''
+
+    def getSummary(self):
+        return ''
 
     # doCheck and doCommand are never called, for aliased commands.
 
@@ -89,6 +92,12 @@ class AliasCommand(AliasedCommand):
     def __init__(self):
         AliasedCommand.__init__(self, "alias")
 
+    def getUsage(self):
+        return "[ALIAS] [expansion]"
+
+    def getSummary(self):
+        return "Adds or lists aliases"
+
     def doCheck(self, base, basecmd, extcmds):
         if len(extcmds) > 1: # Add a new alias
             try:



More information about the Yum-cvs-commits mailing list