Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: bin/
Date: Sat, 02 Mar 2013 03:24:07
Message-Id: 1362194627.02db319dd7a3c5ca3f499e70f4ab922cc3c71717.zmedico@gentoo
1 commit: 02db319dd7a3c5ca3f499e70f4ab922cc3c71717
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sat Mar 2 03:23:47 2013 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sat Mar 2 03:23:47 2013 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=02db319d
7
8 repoman: check metadata.xml doctype, bug #328113
9
10 ---
11 bin/repoman | 30 ++++++++++++++++++++++++++++--
12 1 files changed, 28 insertions(+), 2 deletions(-)
13
14 diff --git a/bin/repoman b/bin/repoman
15 index a77b5de..07f0adc 100755
16 --- a/bin/repoman
17 +++ b/bin/repoman
18 @@ -508,6 +508,7 @@ suspect_virtual = {
19 "dev-libs/libusb-compat":"virtual/libusb",
20 }
21
22 +metadata_doctype_name = 'pkgmetadata'
23 metadata_dtd_uri = 'http://www.gentoo.org/dtd/metadata.dtd'
24 # force refetch if the local copy creation time is older than this
25 metadata_dtd_ctime_interval = 60 * 60 * 24 * 7 # 7 days
26 @@ -1278,8 +1279,12 @@ class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
27 Implements doctype() as required to avoid deprecation warnings with
28 >=python-2.7.
29 """
30 + def __init__(self, data):
31 + xml.etree.ElementTree.TreeBuilder.__init__(self)
32 + self._portage_data = data
33 +
34 def doctype(self, name, pubid, system):
35 - pass
36 + self._portage_data["DOCTYPE"] = (name, pubid, system)
37
38 try:
39 herd_base = make_herd_base(os.path.join(repoman_settings["PORTDIR"], "metadata/herds.xml"))
40 @@ -1638,6 +1643,7 @@ for x in effective_scanlist:
41 # metadata.xml parse check
42 else:
43 metadata_bad = False
44 + xml_info = {}
45
46 # read metadata.xml into memory
47 try:
48 @@ -1645,13 +1651,33 @@ for x in effective_scanlist:
49 _unicode_encode(os.path.join(checkdir, "metadata.xml"),
50 encoding=_encodings['fs'], errors='strict'),
51 parser=xml.etree.ElementTree.XMLParser(
52 - target=_MetadataTreeBuilder()))
53 + target=_MetadataTreeBuilder(xml_info)))
54 except (ExpatError, SyntaxError, EnvironmentError) as e:
55 metadata_bad = True
56 stats["metadata.bad"] += 1
57 fails["metadata.bad"].append("%s/metadata.xml: %s" % (x, e))
58 del e
59 else:
60 + if "DOCTYPE" not in xml_info:
61 + metadata_bad = True
62 + stats["metadata.bad"] += 1
63 + fails["metadata.bad"].append("%s/metadata.xml: %s" % (x,
64 + "DOCTYPE is missing"))
65 + else:
66 + doctype_name, doctype_pubid, doctype_system = \
67 + xml_info["DOCTYPE"]
68 + if doctype_system != metadata_dtd_uri:
69 + stats["metadata.bad"] += 1
70 + fails["metadata.bad"].append("%s/metadata.xml: "
71 + "DOCTYPE: SYSTEM should refer to '%s', not '%s'" %
72 + (x, metadata_dtd_uri, doctype_system))
73 +
74 + if doctype_name != metadata_doctype_name:
75 + stats["metadata.bad"] += 1
76 + fails["metadata.bad"].append("%s/metadata.xml: "
77 + "DOCTYPE: name should be '%s', not '%s'" %
78 + (x, metadata_doctype_name, doctype_name))
79 +
80 # load USE flags from metadata.xml
81 try:
82 musedict = utilities.parse_metadata_use(_metadata_xml)