[yum-cvs] yum/yum config.py,1.78,1.79 repos.py,1.84,1.85

Seth Vidal skvidal at login.linux.duke.edu
Sun Nov 6 21:47:19 UTC 2005


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

Modified Files:
	config.py repos.py 
Log Message:

implement checking for a repomd.xml cookie to allow us to fetch it less
often


Index: config.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/config.py,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -r1.78 -r1.79
--- config.py	25 Oct 2005 12:28:44 -0000	1.78
+++ config.py	6 Nov 2005 21:47:17 -0000	1.79
@@ -355,7 +355,7 @@
     throttle = ThrottleOption(0)
 
     http_caching = SelectionOption('all', ('none', 'packages', 'all'))
-
+    metadata_expire = IntOption(28800)   # time in seconds
 
 class RepoConf(BaseConfig):
    
@@ -381,7 +381,7 @@
     throttle = Inherit(YumConf.throttle)
     timeout = Inherit(YumConf.timeout)
     http_caching = Inherit(YumConf.http_caching)
-
+    metadata_expire = Inherit(YumConf.metadata_expire)
 
 def readMainConfig(configfile, root):
     #XXX: document

Index: repos.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/repos.py,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -r1.84 -r1.85
--- repos.py	25 Oct 2005 12:28:44 -0000	1.84
+++ repos.py	6 Nov 2005 21:47:17 -0000	1.85
@@ -341,6 +341,7 @@
         self.proxy_username = None
         self.proxy = None
         self.proxy_dict = {}
+        self.metadata_cookie = self.cachedir + '/cachecookie'
         
         # throw in some stubs for things that will be set by the config class
         self.basecachedir = ""
@@ -625,6 +626,34 @@
         return result
            
         
+    def metadataCurrent(self):
+        """Check if there is a metadata_cookie and check its age. If the 
+        age of the cookie is less than metadata_expire time then return true
+        else return False"""
+        
+        val = False
+        if os.path.exists(self.metadata_cookie):
+            cookie_info = os.stat(self.metadata_cookie)
+            if cookie_info[8] + self.metadata_expire > time.time():
+                val = True
+        
+        return val
+
+    
+    def setMetadataCookie(self):
+        """if possible, set touch the metadata_cookie file"""
+        
+        check = self.metadata_cookie
+        if os.path.exists(self.metadata_cookie):
+            check = self.cachedir
+        
+        if os.access(check, os.W_OK):
+            fo = open(self.metadata_cookie, 'w+')
+            fo.write()
+            fo.close()
+            del foo
+            
+            
     def getRepoXML(self, text=None):
         """retrieve/check/read in repomd.xml from the repository"""
 
@@ -632,8 +661,8 @@
         local = self.cachedir + '/repomd.xml'
         if self.repoXML is not None:
             return
-            
-        if self.cache == 1:
+
+        if self.cache or self.metadataCurrent():
             if not os.path.exists(local):
                 raise Errors.RepoError, 'Cannot find repomd.xml file for %s' % (self)
             else:
@@ -651,12 +680,15 @@
 
             except URLGrabError, e:
                 raise Errors.RepoError, 'Error downloading file %s: %s' % (local, e)
-        
+            
+            # if we have a 'fresh' repomd.xml then update the cookie
+            self.setMetadataCookie()
+
         try:
             self.repoXML = repoMDObject.RepoMD(self.id, result)
         except mdErrors.RepoMDError, e:
             raise Errors.RepoError, 'Error importing repomd.xml from %s: %s' % (self, e)
-            
+    
     def _checkRepoXML(self, fo):
         if type(fo) is types.InstanceType:
             filepath = fo.filename




More information about the Yum-cvs-commits mailing list