repodb: Let check_distribution raise an error
This commit moves the check from cli code to api.py. Check is done at every repo update. Also uses SourceName tag for getting distribution name.
This commit is contained in:
@@ -838,6 +838,8 @@ def __update_repo(repo, force=False):
|
||||
else:
|
||||
return
|
||||
|
||||
repodb.check_distribution(repo)
|
||||
|
||||
try:
|
||||
index.check_signature(repouri, repo)
|
||||
except pisi.file.NoSignatureFound, e:
|
||||
|
||||
@@ -89,8 +89,6 @@ NB: We support only local files (e.g., /a/b/c) and http:// URIs at the moment
|
||||
if not ctx.get_option('no_fetch'):
|
||||
try:
|
||||
pisi.api.update_repo(name)
|
||||
if not ctx.get_option('ignore_check'):
|
||||
self.check_distro(name)
|
||||
except (pisi.fetcher.FetchError, IOError):
|
||||
warning = _("%s repository could not be reached. Removing %s from system.") % (name, name)
|
||||
self.warn_and_remove(warning, name)
|
||||
|
||||
+13
-7
@@ -27,6 +27,9 @@ import pisi.db.lazydb as lazydb
|
||||
class RepoError(pisi.Error):
|
||||
pass
|
||||
|
||||
class IncompatibleRepoError(RepoError):
|
||||
pass
|
||||
|
||||
class Repo:
|
||||
def __init__(self, indexuri):
|
||||
self.indexuri = indexuri
|
||||
@@ -225,19 +228,22 @@ class RepoDB(lazydb.LazyDB):
|
||||
|
||||
def get_distribution(self, name):
|
||||
doc = self.get_repo_doc(name)
|
||||
return doc.getTag("Distribution").getTagData("DistributionName")
|
||||
return doc.getTag("Distribution").getTagData("SourceName")
|
||||
|
||||
def get_distribution_release(self, name):
|
||||
doc = self.get_repo_doc(name)
|
||||
return doc.getTag("Distribution").getTagData("Version")
|
||||
|
||||
def check_distribution(self, name):
|
||||
if ctx.get_option('ignore_check'):
|
||||
return
|
||||
|
||||
dist_name = self.get_distribution(name)
|
||||
dist_release = self.get_distribution_release(name)
|
||||
|
||||
if not dist_name:
|
||||
# If distribution info is not available, ignore for now.
|
||||
return True
|
||||
|
||||
return dist_name == ctx.config.values.general.distribution and \
|
||||
dist_release == ctx.config.values.general.distribution_release
|
||||
if dist_name != ctx.config.values.general.distribution or \
|
||||
dist_release != ctx.config.values.general.distribution_release:
|
||||
self.deactivate_repo(name)
|
||||
raise IncompatibleRepoError(
|
||||
_("Repository '%s' is not compatible with your "
|
||||
"distribution. Repository is disabled.") % name)
|
||||
|
||||
Reference in New Issue
Block a user