Gentoo Archives: gentoo-commits

From: Brian Dolbec <dolsen@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/repoman/, pym/repoman/modules/scan/metadata/
Date: Fri, 29 Apr 2016 17:25:04
Message-Id: 1461598133.13197c7ce03e7fa88899589bfcfe6f3ebaac9112.dolsen@gentoo
1 commit: 13197c7ce03e7fa88899589bfcfe6f3ebaac9112
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Sun Apr 17 08:06:28 2016 +0000
4 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
5 CommitDate: Mon Apr 25 15:28:53 2016 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=13197c7c
7
8 repoman: Use XML Schema for metadata.xml validation
9
10 pym/repoman/_xml.py | 16 +++++-----
11 pym/repoman/metadata.py | 39 ++++++++++++------------
12 pym/repoman/modules/scan/metadata/__init__.py | 2 +-
13 pym/repoman/modules/scan/metadata/pkgmetadata.py | 6 ++--
14 pym/repoman/scanner.py | 8 ++---
15 5 files changed, 36 insertions(+), 35 deletions(-)
16
17 diff --git a/pym/repoman/_xml.py b/pym/repoman/_xml.py
18 index d55dda5..33a536a 100644
19 --- a/pym/repoman/_xml.py
20 +++ b/pym/repoman/_xml.py
21 @@ -12,7 +12,7 @@ from portage import os
22 from portage.output import red
23 from portage.process import find_binary
24
25 -from repoman.metadata import fetch_metadata_dtd
26 +from repoman.metadata import fetch_metadata_xsd
27 from repoman._subprocess import repoman_getstatusoutput
28
29
30 @@ -53,12 +53,12 @@ class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
31
32 class XmlLint(object):
33
34 - def __init__(self, options, repoman_settings, metadata_dtd=None):
35 - self.metadata_dtd = (metadata_dtd or
36 - os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd'))
37 + def __init__(self, options, repoman_settings, metadata_xsd=None):
38 + self.metadata_xsd = (metadata_xsd or
39 + os.path.join(repoman_settings["DISTDIR"], 'metadata.xsd'))
40 self.options = options
41 self.repoman_settings = repoman_settings
42 - self._is_capable = metadata_dtd is not None
43 + self._is_capable = metadata_xsd is not None
44 self.binary = None
45 self._check_capable()
46
47 @@ -69,7 +69,7 @@ class XmlLint(object):
48 if not self.binary:
49 print(red("!!! xmllint not found. Can't check metadata.xml.\n"))
50 elif not self._is_capable:
51 - if not fetch_metadata_dtd(self.metadata_dtd, self.repoman_settings):
52 + if not fetch_metadata_xsd(self.metadata_xsd, self.repoman_settings):
53 sys.exit(1)
54 # this can be problematic if xmllint changes their output
55 self._is_capable = True
56 @@ -93,8 +93,8 @@ class XmlLint(object):
57 # xmlint can produce garbage output even on success, so only dump
58 # the ouput when it fails.
59 st, out = repoman_getstatusoutput(
60 - self.binary + " --nonet --noout --dtdvalid %s %s" % (
61 - portage._shell_quote(self.metadata_dtd),
62 + self.binary + " --nonet --noout --schema %s %s" % (
63 + portage._shell_quote(self.metadata_xsd),
64 portage._shell_quote(
65 os.path.join(checkdir, "metadata.xml"))))
66 if st != os.EX_OK:
67
68 diff --git a/pym/repoman/metadata.py b/pym/repoman/metadata.py
69 index e95ad41..7a514dc 100644
70 --- a/pym/repoman/metadata.py
71 +++ b/pym/repoman/metadata.py
72 @@ -33,8 +33,9 @@ metadata_xml_declaration = '<?xml version="1.0" encoding="%s"?>' \
73 % (metadata_xml_encoding,)
74 metadata_doctype_name = 'pkgmetadata'
75 metadata_dtd_uri = 'http://www.gentoo.org/dtd/metadata.dtd'
76 +metadata_xsd_uri = 'http://www.gentoo.org/xml-schema/metadata.xsd'
77 # force refetch if the local copy creation time is older than this
78 -metadata_dtd_ctime_interval = 60 * 60 * 24 * 7 # 7 days
79 +metadata_xsd_ctime_interval = 60 * 60 * 24 * 7 # 7 days
80
81
82 def parse_metadata_use(xml_tree):
83 @@ -86,36 +87,36 @@ def parse_metadata_use(xml_tree):
84 return uselist
85
86
87 -def fetch_metadata_dtd(metadata_dtd, repoman_settings):
88 +def fetch_metadata_xsd(metadata_xsd, repoman_settings):
89 """
90 - Fetch metadata.dtd if it doesn't exist or the ctime is older than
91 - metadata_dtd_ctime_interval.
92 + Fetch metadata.xsd if it doesn't exist or the ctime is older than
93 + metadata_xsd_ctime_interval.
94 @rtype: bool
95 @return: True if successful, otherwise False
96 """
97
98 must_fetch = True
99 - metadata_dtd_st = None
100 + metadata_xsd_st = None
101 current_time = int(time.time())
102 try:
103 - metadata_dtd_st = os.stat(metadata_dtd)
104 + metadata_xsd_st = os.stat(metadata_xsd)
105 except EnvironmentError as e:
106 if e.errno not in (errno.ENOENT, errno.ESTALE):
107 raise
108 del e
109 else:
110 - # Trigger fetch if metadata.dtd mtime is old or clock is wrong.
111 - if abs(current_time - metadata_dtd_st.st_ctime) \
112 - < metadata_dtd_ctime_interval:
113 + # Trigger fetch if metadata.xsd mtime is old or clock is wrong.
114 + if abs(current_time - metadata_xsd_st.st_ctime) \
115 + < metadata_xsd_ctime_interval:
116 must_fetch = False
117
118 if must_fetch:
119 print()
120 print(
121 - "%s the local copy of metadata.dtd "
122 + "%s the local copy of metadata.xsd "
123 "needs to be refetched, doing that now" % green("***"))
124 print()
125 - parsed_url = urlparse(metadata_dtd_uri)
126 + parsed_url = urlparse(metadata_xsd_uri)
127 setting = 'FETCHCOMMAND_' + parsed_url.scheme.upper()
128 fcmd = repoman_settings.get(setting)
129 if not fcmd:
130 @@ -125,29 +126,29 @@ def fetch_metadata_dtd(metadata_dtd, repoman_settings):
131 return False
132
133 destdir = repoman_settings["DISTDIR"]
134 - fd, metadata_dtd_tmp = tempfile.mkstemp(
135 - prefix='metadata.dtd.', dir=destdir)
136 + fd, metadata_xsd_tmp = tempfile.mkstemp(
137 + prefix='metadata.xsd.', dir=destdir)
138 os.close(fd)
139
140 try:
141 if not portage.getbinpkg.file_get(
142 - metadata_dtd_uri, destdir, fcmd=fcmd,
143 - filename=os.path.basename(metadata_dtd_tmp)):
144 + metadata_xsd_uri, destdir, fcmd=fcmd,
145 + filename=os.path.basename(metadata_xsd_tmp)):
146 logging.error(
147 - "failed to fetch metadata.dtd from '%s'" % metadata_dtd_uri)
148 + "failed to fetch metadata.xsd from '%s'" % metadata_xsd_uri)
149 return False
150
151 try:
152 portage.util.apply_secpass_permissions(
153 - metadata_dtd_tmp,
154 + metadata_xsd_tmp,
155 gid=portage.data.portage_gid, mode=0o664, mask=0o2)
156 except portage.exception.PortageException:
157 pass
158
159 - shutil.move(metadata_dtd_tmp, metadata_dtd)
160 + shutil.move(metadata_xsd_tmp, metadata_xsd)
161 finally:
162 try:
163 - os.unlink(metadata_dtd_tmp)
164 + os.unlink(metadata_xsd_tmp)
165 except OSError:
166 pass
167
168
169 diff --git a/pym/repoman/modules/scan/metadata/__init__.py b/pym/repoman/modules/scan/metadata/__init__.py
170 index 98df9cf..1a6c0ed 100644
171 --- a/pym/repoman/modules/scan/metadata/__init__.py
172 +++ b/pym/repoman/modules/scan/metadata/__init__.py
173 @@ -18,7 +18,7 @@ module_spec = {
174 'functions': ['check'],
175 'func_desc': {
176 },
177 - 'mod_kwargs': ['repo_settings', 'qatracker', 'options', 'metadata_dtd',
178 + 'mod_kwargs': ['repo_settings', 'qatracker', 'options', 'metadata_xsd',
179 ],
180 'func_kwargs': {
181 'checkdir': (None, None),
182
183 diff --git a/pym/repoman/modules/scan/metadata/pkgmetadata.py b/pym/repoman/modules/scan/metadata/pkgmetadata.py
184 index 9216d77..25907b3 100644
185 --- a/pym/repoman/modules/scan/metadata/pkgmetadata.py
186 +++ b/pym/repoman/modules/scan/metadata/pkgmetadata.py
187 @@ -46,17 +46,17 @@ class PkgMetadata(ScanBase):
188 @param repo_settings: settings instance
189 @param qatracker: QATracker instance
190 @param options: argparse options instance
191 - @param metadata_dtd: path of metadata.dtd
192 + @param metadata_xsd: path of metadata.xsd
193 '''
194 super(PkgMetadata, self).__init__(**kwargs)
195 repo_settings = kwargs.get('repo_settings')
196 self.qatracker = kwargs.get('qatracker')
197 self.options = kwargs.get('options')
198 - metadata_dtd = kwargs.get('metadata_dtd')
199 + metadata_xsd = kwargs.get('metadata_xsd')
200 self.repoman_settings = repo_settings.repoman_settings
201 self.musedict = {}
202 self.xmllint = XmlLint(self.options, self.repoman_settings,
203 - metadata_dtd=metadata_dtd)
204 + metadata_xsd=metadata_xsd)
205
206 def check(self, **kwargs):
207 '''Performs the checks on the metadata.xml for the package
208
209 diff --git a/pym/repoman/scanner.py b/pym/repoman/scanner.py
210 index 74bb7e3..508fedb 100644
211 --- a/pym/repoman/scanner.py
212 +++ b/pym/repoman/scanner.py
213 @@ -56,11 +56,11 @@ class Scanner(object):
214 portage.util.stack_lists([self.categories], incremental=1))
215 self.categories = self.repo_settings.repoman_settings.categories
216
217 - metadata_dtd = None
218 + metadata_xsd = None
219 for path in reversed(self.repo_settings.repo_config.eclass_db.porttrees):
220 - path = os.path.join(path, 'metadata/dtd/metadata.dtd')
221 + path = os.path.join(path, 'metadata/xml-schema/metadata.xsd')
222 if os.path.exists(path):
223 - metadata_dtd = path
224 + metadata_xsd = path
225 break
226
227 self.portdb = repo_settings.portdb
228 @@ -189,7 +189,7 @@ class Scanner(object):
229 "qatracker": self.qatracker,
230 "vcs_settings": self.vcs_settings,
231 "options": self.options,
232 - "metadata_dtd": metadata_dtd,
233 + "metadata_xsd": metadata_xsd,
234 "uselist": uselist,
235 "checks": self.checks,
236 "repo_metadata": self.repo_metadata,