[yum-commits] Branch 'yum-3_2_X' - 3 commits - yum/misc.py yum/yumRepo.py yummain.py

James Antill james at osuosl.org
Fri Jan 30 17:58:08 UTC 2009


 yum/misc.py    |    7 +++----
 yum/yumRepo.py |   45 +++++++++++++++++++++++++++++++--------------
 yummain.py     |    2 ++
 3 files changed, 36 insertions(+), 18 deletions(-)

New commits:
commit 042d58461671a24d88ca26d7d61a35206676e00b
Author: James Antill <james at and.org>
Date:   Fri Jan 30 11:27:17 2009 -0500

     Try and get "preload" the MD from multiple places, so we have a much
    better chance of actually getting it.
     Also add "preload" for packages.

diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index ec9876c..1050639 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -201,6 +201,7 @@ class YumPackageSack(packageSack.PackageSack):
 
         result = None
 
+        repo._preload_md_from_system_cache(os.path.basename(db_un_fn))
         if os.path.exists(db_un_fn):
             if skip_old_DBMD_check and repo._using_old_MD:
                 return db_un_fn
@@ -1139,6 +1140,8 @@ class YumRepository(Repository, config.RepoConf):
                 return True
         return False
 
+    # mmdtype is unused, but in theory was == primary
+    # dbmtype == primary_db etc.
     def _groupCheckDataMDValid(self, data, dbmdtype, mmdtype, file_check=False):
         """ Check that we already have this data, and that it's valid. Given
             the DB mdtype and the main mdtype (no _db suffix). """
@@ -1155,7 +1158,10 @@ class YumRepository(Repository, config.RepoConf):
             if not os.path.exists(local):
                 local = local.replace('.bz2', '')
                 compressed = True
-        # if we can, make a copy of the system-wide-cache version of this file
+        #  If we can, make a copy of the system-wide-cache version of this file,
+        # note that we often don't get here. So we also do this in
+        # YumPackageSack.populate ... and we look for the uncompressed versions
+        # in retrieveMD.
         self._preload_md_from_system_cache(os.path.basename(local))
         if not self._checkMD(local, dbmdtype, openchecksum=compressed,
                              data=data, check_can_fail=True):
@@ -1411,7 +1417,8 @@ class YumRepository(Repository, config.RepoConf):
                     "Caching enabled but no local cache of %s from %s" % (local,
                            self)
 
-        if os.path.exists(local):
+        if (os.path.exists(local) or
+            self._preload_md_from_system_cache(os.path.basename(local))):
             if self._checkMD(local, mdtype, check_can_fail=True):
                 self.retrieved[mdtype] = 1
                 return local # it's the same return the local one
@@ -1536,30 +1543,40 @@ class YumRepository(Repository, config.RepoConf):
 
         return returnlist
 
-    def _preload_md_from_system_cache(self, filename):
-        """attempts to download the file from the system-wide cache, if possible"""
+    def _preload_file_from_system_cache(self, filename, subdir=''):
+        """attempts to copy the file from the system-wide cache,
+           if possible"""
         if not hasattr(self, 'old_base_cache_dir'):
-            return
+            return False
         if self.old_base_cache_dir == "":
-            return
+            return False
 
         glob_repo_cache_dir=os.path.join(self.old_base_cache_dir, self.id)
         if not os.path.exists(glob_repo_cache_dir):
-            return
+            return False
         if os.path.normpath(glob_repo_cache_dir) == os.path.normpath(self.cachedir):
-            return
+            return False
 
-        # copy repomd.xml, cachecookie and mirrorlist.txt
-        fn = glob_repo_cache_dir + '/' + filename
-        destfn = self.cachedir + '/' + os.path.basename(filename)
+        # Try to copy whatever file it is
+        fn = glob_repo_cache_dir + '/' + subdir + os.path.basename(filename)
+        destfn = self.cachedir   + '/' + subdir + os.path.basename(filename)
         # don't copy it if the copy in our users dir is newer or equal
         if not os.path.exists(fn):
-            return
+            return False
         if os.path.exists(destfn):
             if os.stat(fn)[stat.ST_CTIME] <= os.stat(destfn)[stat.ST_CTIME]:
-                return
-        #print 'copying %s to %s' % (fn, destfn)
+                return False
         shutil.copy2(fn, destfn)
+        return True
+
+    def _preload_md_from_system_cache(self, filename):
+        """attempts to copy the metadata file from the system-wide cache,
+           if possible"""
+        return self._preload_file_from_system_cache(filename)
+    def _preload_pkg_from_system_cache(self, pkg):
+        """attempts to copy the package from the system-wide cache,
+           if possible"""
+        return self._preload_file_from_system_cache(filename,subdir='packages/')
 
 
 def getMirrorList(mirrorlist, pdict = None):
commit 759542c315c66dfc4c5a45ce926b26b0d6a17c1b
Author: James Antill <james at and.org>
Date:   Fri Jan 30 11:18:42 2009 -0500

    Fixup the sha256 vs. sha1 default to be done once at import time

diff --git a/yum/misc.py b/yum/misc.py
index 409071c..ead141d 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -25,11 +25,13 @@ except ImportError:
 try:
     import hashlib
     _available_checksums = ['md5', 'sha1', 'sha256', 'sha512']
+    _default_checksums = ['sha256']
 except ImportError:
     # Python-2.4.z ... gah!
     import sha
     import md5
     _available_checksums = ['md5', 'sha1']
+    _default_checksums = ['sha1']
     class hashlib:
 
         @staticmethod
@@ -178,10 +180,7 @@ class Checksums:
 
     def __init__(self, checksums=None, ignore_missing=False):
         if checksums is None:
-            if 'sha256' not in _available_checksums:
-                checksums = ['sha1'] # for python 2.4 compat
-            else:
-                checksums = ['sha256']
+            checksums = _default_checksums
         self._sumalgos = []
         self._sumtypes = []
         self._len = 0
commit d97e2e1e3c8cf559026fdf11d8241e2bf2a5deb0
Author: James Antill <james at and.org>
Date:   Wed Jan 28 11:59:59 2009 -0500

    Add check for /proc/stat too, on lock info.

diff --git a/yummain.py b/yummain.py
index 95ae69c..f3639a6 100755
--- a/yummain.py
+++ b/yummain.py
@@ -90,7 +90,9 @@ def main(args):
         if not pid:
             return
 
+        # Maybe true if /proc isn't mounted, or not Linux ... or something.
         if (not os.path.exists("/proc/%d/status" % pid) or
+            not os.path.exists("/proc/stat") or
             not os.path.exists("/proc/%d/stat" % pid)):
             return
 


More information about the Yum-commits mailing list