Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH] Remove remaining herd support logic and checks
Date: Wed, 07 Feb 2018 09:46:21
Message-Id: 20180207094613.25695-1-mgorny@gentoo.org
1 Herds have been removed 2 years ago. It's time to clean up the remaining
2 bits of their support from Portage code.
3 ---
4 pym/_emerge/EbuildPhase.py | 4 +-
5 pym/portage/xml/metadata.py | 94 +------------------
6 repoman/pym/repoman/checks/herds/__init__.py | 0
7 repoman/pym/repoman/checks/herds/herdbase.py | 135 ---------------------------
8 repoman/pym/repoman/checks/herds/metadata.py | 26 ------
9 5 files changed, 5 insertions(+), 254 deletions(-)
10 delete mode 100644 repoman/pym/repoman/checks/herds/__init__.py
11 delete mode 100644 repoman/pym/repoman/checks/herds/herdbase.py
12 delete mode 100644 repoman/pym/repoman/checks/herds/metadata.py
13
14 diff --git a/pym/_emerge/EbuildPhase.py b/pym/_emerge/EbuildPhase.py
15 index d3fada622..13bedf51b 100644
16 --- a/pym/_emerge/EbuildPhase.py
17 +++ b/pym/_emerge/EbuildPhase.py
18 @@ -83,10 +83,8 @@ class EbuildPhase(CompositeTask):
19 upstr_str = ""
20 metadata_xml_path = os.path.join(os.path.dirname(self.settings['EBUILD']), "metadata.xml")
21 if MetaDataXML is not None and os.path.isfile(metadata_xml_path):
22 - herds_path = os.path.join(self.settings['PORTDIR'],
23 - 'metadata/herds.xml')
24 try:
25 - metadata_xml = MetaDataXML(metadata_xml_path, herds_path)
26 + metadata_xml = MetaDataXML(metadata_xml_path)
27 maint_str = metadata_xml.format_maintainer_string()
28 upstr_str = metadata_xml.format_upstream_string()
29 except SyntaxError:
30 diff --git a/pym/portage/xml/metadata.py b/pym/portage/xml/metadata.py
31 index 9e48dddde..99e0474c1 100644
32 --- a/pym/portage/xml/metadata.py
33 +++ b/pym/portage/xml/metadata.py
34 @@ -1,4 +1,4 @@
35 -# Copyright 2010-2017 Gentoo Foundation
36 +# Copyright 2010-2018 Gentoo Foundation
37 # Distributed under the terms of the GNU General Public License v2
38
39 """Provides an easy-to-use python interface to Gentoo's metadata.xml file.
40 @@ -8,8 +8,6 @@
41 >>> pkg_md = MetaDataXML('/usr/portage/app-misc/gourmet/metadata.xml')
42 >>> pkg_md
43 <MetaDataXML '/usr/portage/app-misc/gourmet/metadata.xml'>
44 - >>> pkg_md.herds()
45 - ['no-herd']
46 >>> for maint in pkg_md.maintainers():
47 ... print "{0} ({1})".format(maint.email, maint.name)
48 ...
49 @@ -198,13 +196,11 @@ class _Upstream(object):
50 class MetaDataXML(object):
51 """Access metadata.xml"""
52
53 - def __init__(self, metadata_xml_path, herds):
54 + def __init__(self, metadata_xml_path):
55 """Parse a valid metadata.xml file.
56
57 @type metadata_xml_path: str
58 @param metadata_xml_path: path to a valid metadata.xml file
59 - @type herds: str or ElementTree
60 - @param herds: path to a herds.xml, or a pre-parsed ElementTree
61 @raise IOError: if C{metadata_xml_path} can not be read
62 """
63
64 @@ -220,85 +216,15 @@ class MetaDataXML(object):
65 except ExpatError as e:
66 raise SyntaxError("%s" % (e,))
67
68 - if isinstance(herds, etree.ElementTree):
69 - herds_etree = herds
70 - herds_path = None
71 - else:
72 - herds_etree = None
73 - herds_path = herds
74 -
75 # Used for caching
76 - self._herdstree = herds_etree
77 - self._herds_path = herds_path
78 self._descriptions = None
79 self._maintainers = None
80 - self._herds = None
81 self._useflags = None
82 self._upstream = None
83
84 def __repr__(self):
85 return "<%s %r>" % (self.__class__.__name__, self.metadata_xml_path)
86
87 - def _get_herd_email(self, herd):
88 - """Get a herd's email address.
89 -
90 - @type herd: str
91 - @param herd: herd whose email you want
92 - @rtype: str or None
93 - @return: email address or None if herd is not in herds.xml
94 - @raise IOError: if $PORTDIR/metadata/herds.xml can not be read
95 - """
96 -
97 - if self._herdstree is None:
98 - try:
99 - self._herdstree = etree.parse(_unicode_encode(self._herds_path,
100 - encoding=_encodings['fs'], errors='strict'),
101 - parser=etree.XMLParser(target=_MetadataTreeBuilder()))
102 - except (ImportError, IOError, SyntaxError):
103 - return None
104 -
105 - # Some special herds are not listed in herds.xml
106 - if herd in ('no-herd', 'maintainer-wanted', 'maintainer-needed'):
107 - return None
108 -
109 - try:
110 - # Python 2.7 or >=3.2
111 - iterate = self._herdstree.iter
112 - except AttributeError:
113 - iterate = self._herdstree.getiterator
114 -
115 - for node in iterate('herd'):
116 - if node.findtext('name') == herd:
117 - return node.findtext('email')
118 -
119 - def herds(self, include_email=False):
120 - """Return a list of text nodes for <herd>.
121 -
122 - @type include_email: bool
123 - @keyword include_email: if True, also look up the herd's email
124 - @rtype: tuple
125 - @return: if include_email is False, return a list of strings;
126 - if include_email is True, return a list of tuples containing:
127 - [('herd1', 'herd1@g.o'), ('no-herd', None);
128 - """
129 - if self._herds is None:
130 - if self._xml_tree is None:
131 - self._herds = tuple()
132 - else:
133 - herds = []
134 - for elem in self._xml_tree.findall('herd'):
135 - text = elem.text
136 - if text is None:
137 - text = ''
138 - if include_email:
139 - herd_mail = self._get_herd_email(text)
140 - herds.append((text, herd_mail))
141 - else:
142 - herds.append(text)
143 - self._herds = tuple(herds)
144 -
145 - return self._herds
146 -
147 def descriptions(self):
148 """Return a list of text nodes for <longdescription>.
149
150 @@ -369,12 +295,11 @@ class MetaDataXML(object):
151 return self._upstream
152
153 def format_maintainer_string(self):
154 - """Format string containing maintainers and herds (emails if possible).
155 + """Format string containing maintainers.
156 Used by emerge to display maintainer information.
157 - Entries are sorted according to the rules stated on the bug wranglers page.
158
159 @rtype: String
160 - @return: a string containing maintainers and herds
161 + @return: a string containing maintainers
162 """
163 maintainers = []
164 for maintainer in self.maintainers():
165 @@ -384,17 +309,6 @@ class MetaDataXML(object):
166 else:
167 maintainers.append(maintainer.email)
168
169 - for herd, email in self.herds(include_email=True):
170 - if herd == "no-herd":
171 - continue
172 - if email is None or not email.strip():
173 - if herd and herd.strip():
174 - maintainers.append(herd)
175 - else:
176 - maintainers.append(email)
177 -
178 - maintainers = list(unique_everseen(maintainers))
179 -
180 maint_str = ""
181 if maintainers:
182 maint_str = maintainers[0]
183 diff --git a/repoman/pym/repoman/checks/herds/__init__.py b/repoman/pym/repoman/checks/herds/__init__.py
184 deleted file mode 100644
185 index e69de29bb..000000000
186 diff --git a/repoman/pym/repoman/checks/herds/herdbase.py b/repoman/pym/repoman/checks/herds/herdbase.py
187 deleted file mode 100644
188 index ebe6a19b4..000000000
189 --- a/repoman/pym/repoman/checks/herds/herdbase.py
190 +++ /dev/null
191 @@ -1,135 +0,0 @@
192 -# -*- coding: utf-8 -*-
193 -# repoman: Herd database analysis
194 -# Copyright 2010-2013 Gentoo Foundation
195 -# Distributed under the terms of the GNU General Public License v2 or later
196 -
197 -from __future__ import print_function, unicode_literals
198 -
199 -import errno
200 -import xml.etree.ElementTree
201 -try:
202 - from xml.parsers.expat import ExpatError
203 -except (SystemExit, KeyboardInterrupt):
204 - raise
205 -except (ImportError, SystemError, RuntimeError, Exception):
206 - # broken or missing xml support
207 - # https://bugs.python.org/issue14988
208 - # This means that python is built without xml support.
209 - # We tolerate global scope import failures for optional
210 - # modules, so that ImportModulesTestCase can succeed (or
211 - # possibly alert us about unexpected import failures).
212 - pass
213 -
214 -from portage import _encodings, _unicode_encode
215 -from portage.exception import FileNotFound, ParseError, PermissionDenied
216 -from portage import os
217 -
218 -from repoman.errors import err
219 -
220 -__all__ = [
221 - "make_herd_base", "get_herd_base"
222 -]
223 -
224 -
225 -def _make_email(nick_name):
226 - if not nick_name.endswith('@gentoo.org'):
227 - nick_name = nick_name + '@gentoo.org'
228 - return nick_name
229 -
230 -
231 -class HerdBase(object):
232 - def __init__(self, herd_to_emails, all_emails):
233 - self.herd_to_emails = herd_to_emails
234 - self.all_emails = all_emails
235 -
236 - def known_herd(self, herd_name):
237 - return herd_name in self.herd_to_emails
238 -
239 - def known_maintainer(self, nick_name):
240 - return _make_email(nick_name) in self.all_emails
241 -
242 - def maintainer_in_herd(self, nick_name, herd_name):
243 - return _make_email(nick_name) in self.herd_to_emails[herd_name]
244 -
245 -
246 -class _HerdsTreeBuilder(xml.etree.ElementTree.TreeBuilder):
247 - """
248 - Implements doctype() as required to avoid deprecation warnings with
249 - >=python-2.7.
250 - """
251 - def doctype(self, name, pubid, system):
252 - pass
253 -
254 -
255 -def make_herd_base(filename):
256 - herd_to_emails = dict()
257 - all_emails = set()
258 -
259 - try:
260 - xml_tree = xml.etree.ElementTree.parse(
261 - _unicode_encode(
262 - filename, encoding=_encodings['fs'], errors='strict'),
263 - parser=xml.etree.ElementTree.XMLParser(
264 - target=_HerdsTreeBuilder()))
265 - except ExpatError as e:
266 - raise ParseError("metadata.xml: %s" % (e,))
267 - except EnvironmentError as e:
268 - func_call = "open('%s')" % filename
269 - if e.errno == errno.EACCES:
270 - raise PermissionDenied(func_call)
271 - elif e.errno == errno.ENOENT:
272 - raise FileNotFound(filename)
273 - raise
274 -
275 - herds = xml_tree.findall('herd')
276 - for h in herds:
277 - _herd_name = h.find('name')
278 - if _herd_name is None:
279 - continue
280 - herd_name = _herd_name.text.strip()
281 - del _herd_name
282 -
283 - maintainers = h.findall('maintainer')
284 - herd_emails = set()
285 - for m in maintainers:
286 - _m_email = m.find('email')
287 - if _m_email is None:
288 - continue
289 - m_email = _m_email.text.strip()
290 -
291 - herd_emails.add(m_email)
292 - all_emails.add(m_email)
293 -
294 - herd_to_emails[herd_name] = herd_emails
295 -
296 - return HerdBase(herd_to_emails, all_emails)
297 -
298 -
299 -def get_herd_base(repoman_settings):
300 - try:
301 - herd_base = make_herd_base(
302 - os.path.join(repoman_settings["PORTDIR"], "metadata/herds.xml"))
303 - except (EnvironmentError, ParseError, PermissionDenied) as e:
304 - err(str(e))
305 - except FileNotFound:
306 - # TODO: Download as we do for metadata.dtd, but add a way to
307 - # disable for non-gentoo repoman users who may not have herds.
308 - herd_base = None
309 - return herd_base
310 -
311 -
312 -if __name__ == '__main__':
313 - h = make_herd_base('/usr/portage/metadata/herds.xml')
314 -
315 - assert(h.known_herd('sound'))
316 - assert(not h.known_herd('media-sound'))
317 -
318 - assert(h.known_maintainer('sping'))
319 - assert(h.known_maintainer('sping@g.o'))
320 - assert(not h.known_maintainer('portage'))
321 -
322 - assert(h.maintainer_in_herd('zmedico@g.o', 'tools-portage'))
323 - assert(not h.maintainer_in_herd('pva@g.o', 'tools-portage'))
324 -
325 - import pprint
326 - pprint.pprint(h.herd_to_emails)
327 diff --git a/repoman/pym/repoman/checks/herds/metadata.py b/repoman/pym/repoman/checks/herds/metadata.py
328 deleted file mode 100644
329 index b4a433ed7..000000000
330 --- a/repoman/pym/repoman/checks/herds/metadata.py
331 +++ /dev/null
332 @@ -1,26 +0,0 @@
333 -# -*- coding:utf-8 -*-
334 -
335 -
336 -class UnknownHerdsError(ValueError):
337 - def __init__(self, herd_names):
338 - _plural = len(herd_names) != 1
339 - super(UnknownHerdsError, self).__init__(
340 - 'Unknown %s %s' % (
341 - _plural and 'herds' or 'herd',
342 - ','.join('"%s"' % e for e in herd_names)))
343 -
344 -
345 -def check_metadata_herds(xml_tree, herd_base):
346 - herd_nodes = xml_tree.findall('herd')
347 - unknown_herds = [
348 - name for name in (
349 - e.text.strip() for e in herd_nodes if e.text is not None)
350 - if not herd_base.known_herd(name)]
351 -
352 - if unknown_herds:
353 - raise UnknownHerdsError(unknown_herds)
354 -
355 -
356 -def check_metadata(xml_tree, herd_base):
357 - if herd_base is not None:
358 - check_metadata_herds(xml_tree, herd_base)
359 --
360 2.16.1

Replies