import calendar
import codecs
-try:
- from subprocess import getstatusoutput as subprocess_getstatusoutput
-except ImportError:
- from commands import getstatusoutput as subprocess_getstatusoutput
import errno
import formatter
import logging
import tempfile
import time
import platform
+import xml.etree.ElementTree
+from xml.parsers.expat import ExpatError
try:
from urllib.request import urlopen as urllib_request_urlopen
import portage
portage._disable_legacy_globals()
from portage import os
+from portage import subprocess_getstatusoutput
from portage import _encodings
from portage import _unicode_encode
from portage import StringIO
# Build a regex from thirdpartymirrors for the SRC_URI.mirror check.
thirdpartymirrors = portage.flatten(list(repoman_settings.thirdpartymirrors().values()))
+class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
+ """
+ Implements doctype() as required to avoid deprecation warnings with
+ >=python-2.7.
+ """
+ def doctype(self, name, pubid, system):
+ pass
+
try:
herd_base = make_herd_base(os.path.join(repoman_settings["PORTDIR"], "metadata/herds.xml"))
except (EnvironmentError, ParseError, PermissionDenied) as e:
# read metadata.xml into memory
try:
- f = open(os.path.join(checkdir, "metadata.xml"))
- _metadata_xml = f.read()
- f.close()
- except (EnvironmentError, ) as e:
+ _metadata_xml = xml.etree.ElementTree.parse(
+ os.path.join(checkdir, "metadata.xml"),
+ parser=xml.etree.ElementTree.XMLParser(
+ target=_MetadataTreeBuilder()))
+ except (ExpatError, EnvironmentError) as e:
metadata_bad = True
stats["metadata.bad"] += 1
fails["metadata.bad"].append("%s/metadata.xml: %s" % (x, e))
del e
else:
# load USE flags from metadata.xml
- try:
- utilities.parse_metadata_use(_metadata_xml, muselist)
- except (EnvironmentError, ParseError) as e:
- metadata_bad = True
- stats["metadata.bad"] += 1
- fails["metadata.bad"].append("%s/metadata.xml: %s" % (x, e))
- del e
+ utilities.parse_metadata_use(_metadata_xml, muselist)
# Run other metadata.xml checkers
try:
utilities.check_metadata(_metadata_xml, herd_base)
- except (EnvironmentError, ParseError, utilities.UnknownHerdsError) as e:
+ except (utilities.UnknownHerdsError, ) as e:
metadata_bad = True
stats["metadata.bad"] += 1
fails["metadata.bad"].append("%s/metadata.xml: %s" % (x, e))
import errno
import logging
import sys
-from xml.parsers.expat import ExpatError
-import xml.etree.ElementTree as ET
from portage import os
from portage import subprocess_getstatusoutput
from portage import _encodings
path = normalize_path(path + "/..")
maxdepth -= 1
-def parse_metadata_use(metadata_xml_content, uselist=None):
+def parse_metadata_use(xml_tree, uselist=None):
"""
Records are wrapped in XML as per GLEP 56
returns a dict of the form a list of flags"""
if uselist is None:
uselist = []
- try:
- xml_tree = ET.fromstring(metadata_xml_content)
- except (ExpatError, ) as e:
- raise exception.ParseError("metadata.xml: " + str(e))
-
usetag = xml_tree.findall("use")
if not usetag:
return uselist
if unknown_herds:
raise UnknownHerdsError(unknown_herds)
-
-def check_metadata(metadata_xml_content, herd_base):
- try:
- xml_tree = ET.fromstring(metadata_xml_content)
- except (ExpatError, ) as e:
- raise exception.ParseError("metadata.xml: " + str(e))
-
+def check_metadata(xml_tree, herd_base):
if herd_base is not None:
check_metadata_herds(xml_tree, herd_base)
-
def FindPackagesToScan(settings, startdir, reposplit):
""" Try to find packages that need to be scanned