From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (unknown [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 84B061381FA for ; Tue, 27 May 2014 06:05:02 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6E210E0896; Tue, 27 May 2014 06:05:01 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D18AEE0897 for ; Tue, 27 May 2014 06:05:00 +0000 (UTC) Received: from spoonbill.gentoo.org (unknown [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 7C0DF33FC9F for ; Tue, 27 May 2014 06:04:59 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 30095182D4 for ; Tue, 27 May 2014 06:04:58 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1401170680.75c50245b8bf0d3e50ce217c52f5f12307f62867.dol-sen@gentoo> Subject: [gentoo-commits] proj/portage:repoman commit in: pym/repoman/ X-VCS-Repository: proj/portage X-VCS-Files: pym/repoman/_xml.py pym/repoman/main.py X-VCS-Directories: pym/repoman/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 75c50245b8bf0d3e50ce217c52f5f12307f62867 X-VCS-Branch: repoman Date: Tue, 27 May 2014 06:04:58 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 56bd3d61-eedc-423a-99ea-1fcb9bda39dd X-Archives-Hash: 8851fc2db2b3485063eeb9aff428d880 commit: 75c50245b8bf0d3e50ce217c52f5f12307f62867 Author: Brian Dolbec gentoo org> AuthorDate: Tue May 27 05:03:10 2014 +0000 Commit: Brian Dolbec gmail com> CommitDate: Tue May 27 06:04:40 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=75c50245 repoman/main.py: Create a new XmlLint class Create the new class in _xml.py. Consolodate all the xmllint code in this one class. --- pym/repoman/_xml.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ pym/repoman/main.py | 40 +++++++++++-------------------------- 2 files changed, 68 insertions(+), 29 deletions(-) diff --git a/pym/repoman/_xml.py b/pym/repoman/_xml.py index e59f357..1b98ede 100644 --- a/pym/repoman/_xml.py +++ b/pym/repoman/_xml.py @@ -1,6 +1,15 @@ +import sys import xml +import portage +from portage import os +from portage.output import red +from portage.process import find_binary + +from repoman.metadata import fetch_metadata_dtd +from repoman._subprocess import repoman_getstatusoutput + class _XMLParser(xml.etree.ElementTree.XMLParser): def __init__(self, data, **kwargs): @@ -34,3 +43,51 @@ class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder): """ def doctype(self, name, pubid, system): pass + + +class XmlLint(object): + + def __init__(self, metadata_dtd, options, repolevel, repoman_settings): + self.metadata_dtd = metadata_dtd + self._is_capable = False + self.binary = None + self._check_capable(options, repolevel, repoman_settings) + + + def _check_capable(self, options, repolevel, repoman_settings): + if options.mode == "manifest": + return + self.binary = find_binary('xmllint') + if not self.binary: + print(red("!!! xmllint not found. Can't check metadata.xml.\n")) + if options.xml_parse or repolevel == 3: + print("%s sorry, xmllint is needed. failing\n" % red("!!!")) + sys.exit(1) + else: + if not fetch_metadata_dtd(self.metadata_dtd, repoman_settings): + sys.exit(1) + # this can be problematic if xmllint changes their output + self._is_capable = True + + + @property + def capable(self): + return self._is_capable + + + def check(self, checkdir): + if not self.capable: + return true + # xmlint can produce garbage output even on success, so only dump + # the ouput when it fails. + st, out = repoman_getstatusoutput( + self.binary + " --nonet --noout --dtdvalid %s %s" % ( + portage._shell_quote(self.metadata_dtd), + portage._shell_quote( + os.path.join(checkdir, "metadata.xml")))) + if st != os.EX_OK: + print(red("!!!") + " metadata.xml is invalid:") + for z in out.splitlines(): + print(red("!!! ") + z) + return False + return True diff --git a/pym/repoman/main.py b/pym/repoman/main.py index 836ca1e..e03788f 100755 --- a/pym/repoman/main.py +++ b/pym/repoman/main.py @@ -66,9 +66,9 @@ from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use from repoman.argparser import parse_args from repoman.checks.ebuilds.checks import run_checks, checks_init from repoman.checks.herds.herdbase import make_herd_base -from repoman.metadata import (fetch_metadata_dtd, metadata_xml_encoding, - metadata_doctype_name, metadata_dtd_uri, metadata_xml_declaration) from repoman.errors import err +from repoman.metadata import (metadata_xml_encoding, metadata_doctype_name, + metadata_dtd_uri, metadata_xml_declaration) from repoman.modules import commit from repoman.profile import check_profiles, dev_keywords, setup_profile from repoman.qa_data import (format_qa_output, format_qa_output_column, qahelp, @@ -80,7 +80,7 @@ from repoman._subprocess import repoman_popen, repoman_getstatusoutput from repoman import utilities from repoman.vcs.vcs import (git_supports_gpg_sign, vcs_files_to_cps, vcs_new_changed, VCSSettings) -from repoman._xml import _XMLParser, _MetadataTreeBuilder +from repoman._xml import _XMLParser, _MetadataTreeBuilder, XmlLint if sys.hexversion >= 0x3000000: @@ -261,22 +261,12 @@ for x in qacats: stats[x] = 0 fails[x] = [] -xmllint_capable = False -metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd') +#################### -if options.mode == "manifest": - pass -elif not find_binary('xmllint'): - print(red("!!! xmllint not found. Can't check metadata.xml.\n")) - if options.xml_parse or repolevel == 3: - print("%s sorry, xmllint is needed. failing\n" % red("!!!")) - sys.exit(1) -else: - if not fetch_metadata_dtd(metadata_dtd, repoman_settings): - sys.exit(1) - # this can be problematic if xmllint changes their output - xmllint_capable = True +metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd') +xmllint = XmlLint(metadata_dtd, options, repolevel, repoman_settings) +##################### if options.mode == "manifest": pass @@ -884,22 +874,14 @@ for x in effective_scanlist: fails["metadata.bad"].append("%s/metadata.xml: %s" % (x, e)) del e +################# # Only carry out if in package directory or check forced - if xmllint_capable and not metadata_bad: - # xmlint can produce garbage output even on success, so only dump - # the ouput when it fails. - st, out = repoman_getstatusoutput( - "xmllint --nonet --noout --dtdvalid %s %s" % ( - portage._shell_quote(metadata_dtd), - portage._shell_quote( - os.path.join(checkdir, "metadata.xml")))) - if st != os.EX_OK: - print(red("!!!") + " metadata.xml is invalid:") - for z in out.splitlines(): - print(red("!!! ") + z) + if not metadata_bad: + if not xmllint.check(checkdir): stats["metadata.bad"] += 1 fails["metadata.bad"].append(x + "/metadata.xml") +################# del metadata_bad muselist = frozenset(musedict)