From 5649b03ea7e821f2d4df269de6e4e96592068807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Serdar=20Dalg=C4=B1=C3=A7?= Date: Mon, 14 Dec 2009 11:55:00 +0000 Subject: [PATCH] Add new option to pisi ar : --ignore-check Now, pisi checks distribution release and architecture types of pisi-index.xml files when adding the repository. To skip this feature, use --ignore-check parameter. To use this feature effectively for architectures; while creating distribution.xml files, Architecture tag should be added. Otherwise, Architecture check is skipped. --- pisi/api.py | 8 ++++++++ pisi/cli/addrepo.py | 3 +++ pisi/index.py | 29 +++++++++++++++++++++++++++-- pisi/pxml/autoxml.py | 4 ++-- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/pisi/api.py b/pisi/api.py index add96a0d..6fbd04fa 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -805,6 +805,14 @@ def __update_repo(repo, force=False): index.read_uri_of_repo(repouri, repo, force = force) else: return + except pisi.index.NotCompatibleDistroException, e: + ctx.ui.warning(e) + remove_repo(repo) + return + except pisi.index.NotCompatibleArchException, e: + ctx.ui.warning(e) + remove_repo(repo) + return try: index.check_signature(repouri, repo) diff --git a/pisi/cli/addrepo.py b/pisi/cli/addrepo.py index c9425bae..c700dfbf 100644 --- a/pisi/cli/addrepo.py +++ b/pisi/cli/addrepo.py @@ -45,6 +45,9 @@ NB: We support only local files (e.g., /a/b/c) and http:// URIs at the moment group.add_option("--at", action="store", type="int", default=None, help=_("Add repository at given position (0 is first)")) + group.add_option("--ignore-check", action="store_true", + default=False, + help=_("Ignore distribution release and architecture checks")) self.parser.add_option_group(group) def run(self): diff --git a/pisi/index.py b/pisi/index.py index fec2a68e..510e0c98 100644 --- a/pisi/index.py +++ b/pisi/index.py @@ -34,6 +34,16 @@ import pisi.group as group class Error(pisi.Error): pass +class NotCompatibleDistroException(pisi.Exception): + def __init__(self, repoVersion, curDistro, curDistVersion): + 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): + def __init__(self, repoArch, curArch): + pisi.Exception.__init__(self, "Opps, sorry, repo architecture %s is not compatible with your %s architecture." \ + % (repoArch, curArch)) + class Index(xmlfile.XmlFile): __metaclass__ = autoxml.autoxml @@ -50,7 +60,7 @@ class Index(xmlfile.XmlFile): return self.distribution.name + self.distribution.repositoryname def read_uri(self, uri, tmpdir, force = False): - self.read(uri, tmpDir=tmpdir, sha1sum=not force, + return self.read(uri, tmpDir=tmpdir, sha1sum=not force, compress=pisi.file.File.auto, sign=pisi.file.File.detached, copylocal = True, nodecode = True) # read index for a given repo, force means download even if remote not updated @@ -68,7 +78,11 @@ class Index(xmlfile.XmlFile): urlfile.write(uri) # uri urlfile.close() - self.read_uri(uri, tmpdir, force) + doc = self.read_uri(uri, tmpdir, force) + + # check packages' DistributionReleases and Architecture + if not ctx.get_option('ignore_check'): + self.check_distro_and_arch(doc) if not repo: repo = self.distribution.name() @@ -81,6 +95,17 @@ class Index(xmlfile.XmlFile): tmpdir = os.path.join(ctx.config.index_dir(), repo) pisi.file.File.check_signature(filename, tmpdir) + def check_distro_and_arch(self, doc): + config = pisi.configfile.ConfigurationFile("/etc/pisi/pisi.conf") + if doc.getTag("Distribution").getTagData("Version") != config.get("general", "distribution_release"): + raise NotCompatibleDistroException(doc.getTag("Distribution").getTagData("Version"), \ + config.get("general", "distribution"), config.get("general", "distribution_release")) + 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"): + raise NotCompatibleArchException(doc.getTag("Distribution").getTagData("Architecture"), \ + config.get("general", "architecture")) + def index(self, repo_uri, skip_sources=False): self.repo_dir = repo_uri diff --git a/pisi/pxml/autoxml.py b/pisi/pxml/autoxml.py index 5ca1e792..f381047c 100644 --- a/pisi/pxml/autoxml.py +++ b/pisi/pxml/autoxml.py @@ -440,11 +440,11 @@ class autoxml(oo.autosuper, oo.autoprop): def read(self, uri, keepDoc = False, tmpDir = '/tmp', sha1sum = False, compress = None, sign = None, copylocal = False, nodecode = False): "read XML file and decode it into a python object" - self.readxml(uri, tmpDir, sha1sum=sha1sum, + read_xml = self.readxml(uri, tmpDir, sha1sum=sha1sum, compress=compress, sign=sign, copylocal=copylocal) if nodecode: - return + return read_xml errs = [] self.decode(self.rootNode(), errs)