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:
Fatih Aşıcı
2010-05-20 12:21:40 +00:00
parent ed12a3efbf
commit cb220d98dd
3 changed files with 15 additions and 9 deletions
+2
View File
@@ -838,6 +838,8 @@ def __update_repo(repo, force=False):
else: else:
return return
repodb.check_distribution(repo)
try: try:
index.check_signature(repouri, repo) index.check_signature(repouri, repo)
except pisi.file.NoSignatureFound, e: except pisi.file.NoSignatureFound, e:
-2
View File
@@ -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'): if not ctx.get_option('no_fetch'):
try: try:
pisi.api.update_repo(name) pisi.api.update_repo(name)
if not ctx.get_option('ignore_check'):
self.check_distro(name)
except (pisi.fetcher.FetchError, IOError): except (pisi.fetcher.FetchError, IOError):
warning = _("%s repository could not be reached. Removing %s from system.") % (name, name) warning = _("%s repository could not be reached. Removing %s from system.") % (name, name)
self.warn_and_remove(warning, name) self.warn_and_remove(warning, name)
+13 -7
View File
@@ -27,6 +27,9 @@ import pisi.db.lazydb as lazydb
class RepoError(pisi.Error): class RepoError(pisi.Error):
pass pass
class IncompatibleRepoError(RepoError):
pass
class Repo: class Repo:
def __init__(self, indexuri): def __init__(self, indexuri):
self.indexuri = indexuri self.indexuri = indexuri
@@ -225,19 +228,22 @@ class RepoDB(lazydb.LazyDB):
def get_distribution(self, name): def get_distribution(self, name):
doc = self.get_repo_doc(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): def get_distribution_release(self, name):
doc = self.get_repo_doc(name) doc = self.get_repo_doc(name)
return doc.getTag("Distribution").getTagData("Version") return doc.getTag("Distribution").getTagData("Version")
def check_distribution(self, name): def check_distribution(self, name):
if ctx.get_option('ignore_check'):
return
dist_name = self.get_distribution(name) dist_name = self.get_distribution(name)
dist_release = self.get_distribution_release(name) dist_release = self.get_distribution_release(name)
if not dist_name: if dist_name != ctx.config.values.general.distribution or \
# If distribution info is not available, ignore for now. dist_release != ctx.config.values.general.distribution_release:
return True self.deactivate_repo(name)
raise IncompatibleRepoError(
return dist_name == ctx.config.values.general.distribution and \ _("Repository '%s' is not compatible with your "
dist_release == ctx.config.values.general.distribution_release "distribution. Repository is disabled.") % name)