[yum-cvs] 4 commits - yum/yumRepo.py
James Antill
james at linux.duke.edu
Thu Jan 10 05:20:18 UTC 2008
yum/yumRepo.py | 140 ++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 90 insertions(+), 50 deletions(-)
New commits:
commit eae7713d6451a5455c3af248117b5540d3a744d9
Author: James Antill <james at and.org>
Date: Thu Jan 10 00:17:21 2008 -0500
Move _check_db_version to YumPackageSack to YumRepository
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 14dcf79..baebb38 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -193,10 +193,7 @@ class YumPackageSack(packageSack.PackageSack):
return result
def _check_db_version(self, repo, mdtype):
- if repo.repoXML.repoData.has_key(mdtype):
- if DBVERSION == repo.repoXML.repoData[mdtype].dbversion:
- return True
- return False
+ return repo._check_db_version(mdtype)
class YumRepository(Repository, config.RepoConf):
"""
@@ -782,6 +779,14 @@ class YumRepository(Repository, config.RepoConf):
self._repoXML = self._parseRepoXML(result)
+ def _check_db_version(self, mdtype, repoXML=None):
+ if repoXML is None:
+ repoXML = self.repoXML
+ if repoXML.repoData.has_key(mdtype):
+ if DBVERSION == repoXML.repoData[mdtype].dbversion:
+ return True
+ return False
+
def _getRepoXML(self):
if self._repoXML:
return self._repoXML
commit edb35b6f0efe8c9d862b0d691afef962f1c745e6
Author: James Antill <james at and.org>
Date: Thu Jan 10 00:15:10 2008 -0500
Add missing MD file from init.
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 2f11a4d..14dcf79 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -234,7 +234,8 @@ class YumRepository(Repository, config.RepoConf):
self.cost = 1000
self.copy_local = 0
# holder for stuff we've grabbed
- self.retrieved = { 'primary':0, 'filelists':0, 'other':0, 'group':0 }
+ self.retrieved = { 'primary':0, 'filelists':0, 'other':0, 'group':0,
+ 'updateinfo':0}
# callbacks
self.callback = None # for the grabber
commit e8fee4107b41164308570a26513568eac09775ee
Author: James Antill <james at and.org>
Date: Thu Jan 10 00:14:16 2008 -0500
Next step for policy MD downloading, convert loadRepoXML() into helper
functions and add "can_fail" parameter options.
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 7ff3e91..2f11a4d 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -147,10 +147,7 @@ class YumPackageSack(packageSack.PackageSack):
db_un_fn = self._check_uncompressed_db(repo, mydbtype)
if not db_un_fn:
- try:
- db_fn = repo.retrieveMD(mydbtype)
- except Errors.RepoMDError, e:
- pass
+ db_fn = repo._retrieveMD(mydbtype, retrieve_can_fail=True)
if db_fn:
db_un_fn = db_fn.replace('.bz2', '')
if not repo.cache:
@@ -219,6 +216,7 @@ class YumRepository(Repository, config.RepoConf):
# eventually want
self.repoMDFile = 'repodata/repomd.xml'
self._repoXML = None
+ self._oldRepoMDFile = None
self.cache = 0
self.mirrorlistparsed = 0
self.yumvar = {} # empty dict of yumvariables for $string replacement
@@ -301,7 +299,7 @@ class YumRepository(Repository, config.RepoConf):
def __str__(self):
return self.id
- def _checksum(self, sumtype, file, CHUNK=2**16):
+ def _checksum(self, sumtype, file, CHUNK=2**16, checksum_can_fail=False):
"""takes filename, hand back Checksum of it
sumtype = md5 or sha
filename = /path/to/file
@@ -309,6 +307,8 @@ class YumRepository(Repository, config.RepoConf):
try:
return misc.checksum(sumtype, file, CHUNK)
except (Errors.MiscError, EnvironmentError), e:
+ if checksum_can_fail:
+ return None
raise Errors.RepoError, 'Error opening file for checksum: %s' % e
def dump(self):
@@ -811,9 +811,16 @@ class YumRepository(Repository, config.RepoConf):
def checkMD(self, fn, mdtype, openchecksum=False):
"""check the metadata type against its checksum"""
-
- thisdata = self.repoXML.getData(mdtype)
-
+ return self._checkMD(fn, mdtype, openchecksum)
+
+ def _checkMD(self, fn, mdtype, openchecksum=False,
+ thisdata=None, check_can_fail=False):
+ """ Internal function, use .checkMD() from outside yum. """
+
+ if thisdata is None:
+ thisdata = self.repoXML.getData(mdtype)
+
+ # Note openchecksum means do it after you've uncompressed the data.
if openchecksum:
(r_ctype, r_csum) = thisdata.openchecksum # get the remote checksum
else:
@@ -827,11 +834,15 @@ class YumRepository(Repository, config.RepoConf):
try:
l_csum = self._checksum(r_ctype, file) # get the local checksum
except Errors.RepoError, e:
+ if check_can_fail:
+ return None
raise URLGrabError(-3, 'Error performing checksum')
if l_csum == r_csum:
return 1
else:
+ if check_can_fail:
+ return None
raise URLGrabError(-1, 'Metadata file does not match checksum')
@@ -840,7 +851,10 @@ class YumRepository(Repository, config.RepoConf):
"""base function to retrieve metadata files from the remote url
returns the path to the local metadata file of a 'mdtype'
mdtype can be 'primary', 'filelists', 'other' or 'group'."""
-
+ return self._retrieveMD(mdtype)
+
+ def _retrieveMD(self, mdtype, retrieve_can_fail=False):
+ """ Internal function, use .retrieveMD() from outside yum. """
thisdata = self.repoXML.getData(mdtype)
(r_base, remote) = thisdata.location
@@ -867,11 +881,7 @@ class YumRepository(Repository, config.RepoConf):
self)
if os.path.exists(local):
- try:
- self.checkMD(local, mdtype)
- except URLGrabError, e:
- pass
- else:
+ if self._checkMD(local, mdtype, check_can_fail=True):
self.retrieved[mdtype] = 1
return local # it's the same return the local one
@@ -880,7 +890,13 @@ class YumRepository(Repository, config.RepoConf):
local = self._getFile(relative=remote, local=local, copy_local=1,
checkfunc=checkfunc, reget=None,
cache=self.http_caching == 'all')
+ except (Errors.NoMoreMirrorsRepoError, Errors.RepoError):
+ if retrieve_can_fail:
+ return None
+ raise
except URLGrabError, e:
+ if retrieve_can_fail:
+ return None
raise Errors.RepoError, \
"Could not retrieve %s matching remote checksum from %s" % (local, self)
else:
@@ -907,12 +923,7 @@ class YumRepository(Repository, config.RepoConf):
def getGroups(self):
"""gets groups and returns group file path for the repository, if there
is none it returns None"""
- try:
- file = self.retrieveMD('group')
- except URLGrabError:
- file = None
-
- return file
+ return self._retrieveMD('group', retrieve_can_fail=True)
def setCallback(self, callback):
self.callback = callback
commit 2c2ccb25fd5e38b6d34d582c33abb43cae6215dd
Author: James Antill <james at and.org>
Date: Wed Jan 9 23:58:52 2008 -0500
Split _loadRepoXML() into helper functions, 1st step toward having configurable
metadata update policies.
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index e78f7fc..7ff3e91 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -723,40 +723,63 @@ class YumRepository(Repository, config.RepoConf):
verbose_logger.log(logginglevels.DEBUG_2, "Disabling media repo for non-media-aware frontend")
self.enabled = False
+ def _cachingRepoXML(self, local):
+ """ Should we cache the current repomd.xml """
+ if self.cache and not os.path.exists(local):
+ raise Errors.RepoError, 'Cannot find repomd.xml file for %s' % self
+ if self.cache or self.withinCacheAge(self.metadata_cookie,
+ self.metadata_expire):
+ return True
+ return False
+
+ def _getFileRepoXML(self, local, text=None, grab_can_fail=None):
+ """ Call _getFile() for the repomd.xml file. """
+ checkfunc = (self._checkRepoXML, (), {})
+ try:
+ result = self._getFile(relative=self.repoMDFile,
+ local=local,
+ copy_local=1,
+ text=text,
+ reget=None,
+ checkfunc=checkfunc,
+ cache=self.http_caching == 'all')
+
+ except URLGrabError, e:
+ if grab_can_fail is None:
+ grab_can_fail = self._oldRepoMDFile
+ if grab_can_fail:
+ return None
+ raise Errors.RepoError, 'Error downloading file %s: %s' % (local, e)
+ return result
+
+ def _parseRepoXML(self, local, parse_can_fail=None):
+ """ Parse the repomd.xml file. """
+ try:
+ return repoMDObject.RepoMD(self.id, local)
+ except Errors.RepoMDError, e:
+ if parse_can_fail is None:
+ parse_can_fail = self._oldRepoMDFile
+ if parse_can_fail:
+ return None
+ raise Errors.RepoError, 'Error importing repomd.xml from %s: %s' % (self, e)
+
def _loadRepoXML(self, text=None):
- """retrieve/check/read in repomd.xml from the repository"""
+ """ Retrieve the new repomd.xml from the repository, then check it
+ and parse it. If it fails at any point everything fails.
+ Traditional behaviour. """
- remote = self.repoMDFile
- local = self.cachedir + '/repomd.xml'
+ local = self.cachedir + '/repomd.xml'
if self._repoXML is not None:
return
- if self.cache or self.withinCacheAge(self.metadata_cookie, self.metadata_expire):
- if not os.path.exists(local):
- raise Errors.RepoError, 'Cannot find repomd.xml file for %s' % (self)
- else:
- result = local
+ if self._cachingRepoXML(local):
+ result = local
else:
- checkfunc = (self._checkRepoXML, (), {})
- try:
- result = self._getFile(relative=remote,
- local=local,
- copy_local=1,
- text=text,
- reget=None,
- checkfunc=checkfunc,
- cache=self.http_caching == 'all')
-
-
- except URLGrabError, e:
- raise Errors.RepoError, 'Error downloading file %s: %s' % (local, e)
+ result = self._getFileRepoXML(local, text)
# if we have a 'fresh' repomd.xml then update the cookie
self.setMetadataCookie()
- try:
- self._repoXML = repoMDObject.RepoMD(self.id, result)
- except Errors.RepoMDError, e:
- raise Errors.RepoError, 'Error importing repomd.xml from %s: %s' % (self, e)
+ self._repoXML = self._parseRepoXML(result)
def _getRepoXML(self):
if self._repoXML:
More information about the Yum-cvs-commits
mailing list