[yum-cvs] yum/yum __init__.py, 1.123, 1.124 config.py, 1.65, 1.66 repos.py, 1.75, 1.76

Menno Smits mjs at login.linux.duke.edu
Thu Jun 16 12:23:33 UTC 2005


Update of /home/groups/yum/cvs/yum/yum
In directory login:/tmp/cvs-serv2079/yum

Modified Files:
	__init__.py config.py repos.py 
Log Message:
Added http_caching option to provide control over http caching headers.
This addresses bug #412


Index: __init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -r1.123 -r1.124
--- __init__.py	15 Jun 2005 11:49:46 -0000	1.123
+++ __init__.py	16 Jun 2005 12:23:31 -0000	1.124
@@ -582,7 +582,9 @@
                 mylocal = repo.get(relative=remote,
                                    local=local,
                                    checkfunc=checkfunc,
-                                   text=text)
+                                   text=text,
+                                   cache=repo.http_caching != 'none',
+                                   )
             except Errors.RepoError, e:
                 if not errors.has_key(po):
                     errors[po] = []
@@ -655,8 +657,10 @@
         
         try:
             checkfunc = (self.verifyHeader, (po, 1), {})
-            hdrpath = repo.get(relative=remote, local=local, start=start, reget=None, 
-                               end=end, checkfunc=checkfunc, copy_local=1)
+            hdrpath = repo.get(relative=remote, local=local, start=start,
+                    reget=None, end=end, checkfunc=checkfunc, copy_local=1,
+                    cache=repo.http_caching != 'none',
+                    )
         except Errors.RepoError, e:
             saved_repo_error = e
             try:

Index: config.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/config.py,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- config.py	15 Jun 2005 11:49:46 -0000	1.65
+++ config.py	16 Jun 2005 12:23:31 -0000	1.66
@@ -34,6 +34,7 @@
 from repos import variableReplace, Repository
 from constants import *
 
+HTTP_CACHING_VALS = ('none', 'packages', 'all')
 
 class CFParser(ConfigParser.ConfigParser):
     """wrapper around ConfigParser to provide two simple but useful functions:
@@ -79,6 +80,17 @@
         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), e:            
             return default
 
+    def getselection(self, section, option, default=None, allowed=()):
+        '''Get a string value that is only allowed to take specific values
+
+        Will raise ValueError if the value given is not allowed.
+        '''
+        val = self._getoption(section, option, default)
+        if val not in allowed:
+            raise ValueError('"%s" is not a valid value for %s' % (val, 
+                option))
+        return val
+
     def getbytes(self, section, option, default=None):
         """Get a friendly bytes/bandwidth option as bytes. 
 
@@ -218,7 +230,8 @@
                          ('exactarchlist', ['kernel', 'kernel-smp', 'glibc',
                                             'kernel-hugemem', 'kernel-enterprise',
                                             'kernel-bigmem']),
-                         ('tsflags', [])]
+                         ('tsflags', []),
+                         ]
                          
         optionbools = [('assumeyes', 'False'),
                        ('alwaysprompt', 'True'),
@@ -319,6 +332,11 @@
             self.configdata[option] = value
             setattr(self, option, value)
 
+        # http_caching needs special handling
+        value = self.cfg.getselection('main', 'http_caching', 'all', 
+                HTTP_CACHING_VALS)
+        setattr(self, 'http_caching', value)
+        self.configdata['http_caching'] = value
         
         # weird ones
         for option in ['commands', 'installonlypkgs', 'kernelpkgnames',
@@ -458,6 +476,13 @@
     thisrepo.set('mirrorlistfn', mirrorlistfn)
     thisrepo.set('baseurls', baseurls)
 
+    thisrepo.set('http_caching', cfgparser.getselection(
+            section, 'http_caching', 
+            yumconfig.getConfigOption('http_caching'),
+            HTTP_CACHING_VALS
+            )
+        )
+
     # Parse and check gpgkey URLs
     gpgkeys = cfgparser._getoption(section, 'gpgkey', '')
     gpgkeys = variableReplace(yumconfig.yumvar, gpgkeys)

Index: repos.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/repos.py,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -r1.75 -r1.76
--- repos.py	7 May 2005 04:23:20 -0000	1.75
+++ repos.py	16 Jun 2005 12:23:31 -0000	1.76
@@ -14,8 +14,6 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 # Copyright 2004 Duke University 
 
-
-
 import os
 import os.path
 import types
@@ -533,7 +531,7 @@
         self.setupGrab() # update the grabber for the urls
 
     def get(self, url=None, relative=None, local=None, start=None, end=None,
-            copy_local=0, checkfunc=None, text=None, reget='simple'):
+            copy_local=0, checkfunc=None, text=None, reget='simple', cache=True):
         """retrieve file from the mirrorgroup for the repo
            relative to local, optionally get range from
            start to end, also optionally retrieve from a specific baseurl"""
@@ -544,6 +542,11 @@
         # if url is None do a grab via the mirror group/grab for the repo
         # return the path to the local file
 
+        if cache:
+            headers = None
+        else:
+            headers = (('Pragma', 'no-cache'),)
+
         if local is None or relative is None:
             raise Errors.RepoError, \
                   "get request for Repo %s, gave no source or dest" % self.id
@@ -574,23 +577,18 @@
                             reget = reget,
                             proxies = prxy,
                             failure_callback = self.failure_obj,
-                            timeout = self.timeout,
-                            checkfunc = checkfunc)
+                            timeout=self.timeout,
+                            checkfunc=checkfunc,
+                            http_headers=headers,
+                            )
             
             remote = url + '/' + relative
 
             try:
                 result = ug.urlgrab(remote, local,
-                                    text = text,
-                                    range = (start, end), 
-                                    retry = self.retries,
-                                    copy_local = copy_local,
-                                    reget = reget,
-                                    proxies = prxy,
-                                    failure_callback = self.failure_obj,
-                                    timeout = self.timeout,
-                                    checkfunc = checkfunc)
-                                    
+                                    text=text,
+                                    range=(start, end), 
+                                    )
             except URLGrabError, e:
                 raise Errors.RepoError, \
                     "failed to retrieve %s from %s\nerror was %s" % (relative, self.id, e)
@@ -602,7 +600,9 @@
                                            range = (start, end),
                                            copy_local=copy_local,
                                            reget = reget,
-                                           checkfunc=checkfunc)
+                                           checkfunc=checkfunc,
+                                           http_headers=headers,
+                                           )
             except URLGrabError, e:
                 raise Errors.RepoError, "failure: %s from %s: %s" % (relative, self.id, e)
                 
@@ -625,7 +625,10 @@
         else:
             try:
                 result = self.get(relative=remote, local=local,
-                                  copy_local=1, text=text, reget=None)
+                                  copy_local=1, text=text, reget=None, 
+                                  cache=self.http_caching == 'all',
+                                  )
+
             except URLGrabError, e:
                 raise Errors.RepoError, 'Error downloading file %s: %s' % (local, e)
 
@@ -710,7 +713,8 @@
         try:
             checkfunc = (self._checkMD, (mdtype,), {})
             local = self.get(relative=remote, local=local, copy_local=1,
-                             checkfunc=checkfunc, reget=None)
+                             checkfunc=checkfunc, reget=None, 
+                             cache=self.http_caching == 'all')
         except URLGrabError, e:
             raise Errors.RepoError, \
                 "Could not retrieve %s matching remote checksum from %s" % (local, self)




More information about the Yum-cvs-commits mailing list