some enhancements for distribution and architecture check

This commit is contained in:
Serdar Dalgıç
2009-12-14 12:59:38 +00:00
parent 269dec8c6b
commit 06c4b64b9d
3 changed files with 14 additions and 20 deletions
+2 -4
View File
@@ -805,12 +805,10 @@ def __update_repo(repo, force=False):
index.read_uri_of_repo(repouri, repo, force = force) index.read_uri_of_repo(repouri, repo, force = force)
else: else:
return return
except pisi.index.NotCompatibleDistroException, e: except pisi.index.DistributionMismatchException:
ctx.ui.warning(e)
remove_repo(repo) remove_repo(repo)
return return
except pisi.index.NotCompatibleArchException, e: except pisi.index.ArchitectureMismatchException:
ctx.ui.warning(e)
remove_repo(repo) remove_repo(repo)
return return
+1 -1
View File
@@ -47,7 +47,7 @@ NB: We support only local files (e.g., /a/b/c) and http:// URIs at the moment
help=_("Add repository at given position (0 is first)")) help=_("Add repository at given position (0 is first)"))
group.add_option("--ignore-check", action="store_true", group.add_option("--ignore-check", action="store_true",
default=False, default=False,
help=_("Ignore distribution release and architecture checks")) help=_("Skip distribution release and architecture check"))
self.parser.add_option_group(group) self.parser.add_option_group(group)
def run(self): def run(self):
+11 -15
View File
@@ -34,15 +34,11 @@ import pisi.group as group
class Error(pisi.Error): class Error(pisi.Error):
pass pass
class NotCompatibleDistroException(pisi.Exception): class DistributionMismatchException(pisi.Exception):
def __init__(self, repoVersion, curDistro, curDistVersion): pass
pisi.Exception.__init__(self, "Opps, sorry, this repository for %s is not compatible with your distribution release %s %s." \
% (repoVersion, curDistro, curDistVersion))
class NotCompatibleArchException(pisi.Exception): class ArchitectureMismatchException(pisi.Exception):
def __init__(self, repoArch, curArch): pass
pisi.Exception.__init__(self, "Opps, sorry, repo architecture %s is not compatible with your %s architecture." \
% (repoArch, curArch))
class Index(xmlfile.XmlFile): class Index(xmlfile.XmlFile):
__metaclass__ = autoxml.autoxml __metaclass__ = autoxml.autoxml
@@ -82,7 +78,7 @@ class Index(xmlfile.XmlFile):
# check packages' DistributionReleases and Architecture # check packages' DistributionReleases and Architecture
if not ctx.get_option('ignore_check'): if not ctx.get_option('ignore_check'):
self.check_distro_and_arch(doc) self.check_distribution_and_architecture(doc)
if not repo: if not repo:
repo = self.distribution.name() repo = self.distribution.name()
@@ -95,16 +91,16 @@ class Index(xmlfile.XmlFile):
tmpdir = os.path.join(ctx.config.index_dir(), repo) tmpdir = os.path.join(ctx.config.index_dir(), repo)
pisi.file.File.check_signature(filename, tmpdir) pisi.file.File.check_signature(filename, tmpdir)
def check_distro_and_arch(self, doc): def check_distribution_and_architecture(self, doc):
config = pisi.configfile.ConfigurationFile("/etc/pisi/pisi.conf") config = pisi.configfile.ConfigurationFile("/etc/pisi/pisi.conf")
if doc.getTag("Distribution").getTagData("Version") != config.get("general", "distribution_release"): if doc.getTag("Distribution").getTagData("Version") != config.get("general", "distribution_release"):
raise NotCompatibleDistroException(doc.getTag("Distribution").getTagData("Version"), \ ctx.ui.error(_("The repository couldn't be added because of distribution release mismatch"))
config.get("general", "distribution"), config.get("general", "distribution_release")) raise DistributionMismatchException
# First check if Architecture tag exists in index.xml; if not, directly skip it ;)
if doc.getTag("Distribution").getTagData("Architecture"): if doc.getTag("Distribution").getTagData("Architecture"):
# First check if Architecture tag exists in index.xml; if not, directly skip it ;)
if doc.getTag("Distribution").getTagData("Architecture") != config.get("general", "architecture"): if doc.getTag("Distribution").getTagData("Architecture") != config.get("general", "architecture"):
raise NotCompatibleArchException(doc.getTag("Distribution").getTagData("Architecture"), \ ctx.ui.error(_("The repository couldn't be added because of distribution architecture mismatch"))
config.get("general", "architecture")) raise ArchitectureMismatchException
def index(self, repo_uri, skip_sources=False): def index(self, repo_uri, skip_sources=False):
self.repo_dir = repo_uri self.repo_dir = repo_uri