Gentoo Archives: gentoo-portage-dev

From: Matt Turner <mattst88@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Matt Turner <mattst88@g.o>
Subject: [gentoo-portage-dev] [PATCH gentoolkit] equery: Remove 'changes' subcommand
Date: Mon, 04 Jan 2021 18:44:22
Message-Id: 20210104184416.418667-1-mattst88@gentoo.org
1 ChangeLogs have been gone from gentoo.git since the beginning, and
2 Council agreed in 2016 to allow Infra to decide whether to distribute
3 them through rsync, which they have decided not to do [1].
4
5 [1] https://projects.gentoo.org/council/meeting-logs/20160410-summary.txt
6
7 Signed-off-by: Matt Turner <mattst88@g.o>
8 ---
9 pym/gentoolkit/equery/__init__.py | 1 -
10 pym/gentoolkit/equery/changes.py | 184 ------------------------
11 pym/gentoolkit/helpers.py | 173 ----------------------
12 pym/gentoolkit/test/equery/test_init.py | 1 -
13 pym/gentoolkit/test/test_helpers.py | 47 ------
14 5 files changed, 406 deletions(-)
15 delete mode 100644 pym/gentoolkit/equery/changes.py
16
17 diff --git a/pym/gentoolkit/equery/__init__.py b/pym/gentoolkit/equery/__init__.py
18 index 4640086..677f534 100644
19 --- a/pym/gentoolkit/equery/__init__.py
20 +++ b/pym/gentoolkit/equery/__init__.py
21 @@ -42,7 +42,6 @@ __authors__ = (
22
23 NAME_MAP = {
24 'b': 'belongs',
25 - 'c': 'changes',
26 'k': 'check',
27 'd': 'depends',
28 'g': 'depgraph',
29 diff --git a/pym/gentoolkit/equery/changes.py b/pym/gentoolkit/equery/changes.py
30 deleted file mode 100644
31 index f234ecb..0000000
32 --- a/pym/gentoolkit/equery/changes.py
33 +++ /dev/null
34 @@ -1,184 +0,0 @@
35 -# Copyright(c) 2009, Gentoo Foundation
36 -#
37 -# Licensed under the GNU General Public License, v2 or higher
38 -
39 -"""Displays the ChangeLog entry for the latest installable version of an atom"""
40 -
41 -__docformat__ = 'epytext'
42 -
43 -# =======
44 -# Imports
45 -# =======
46 -
47 -import sys
48 -import os
49 -from getopt import gnu_getopt, GetoptError
50 -
51 -import gentoolkit.pprinter as pp
52 -from gentoolkit.atom import Atom
53 -from gentoolkit.equery import format_options, mod_usage
54 -from gentoolkit.helpers import ChangeLog
55 -from gentoolkit.query import Query
56 -
57 -# =======
58 -# Globals
59 -# =======
60 -
61 -QUERY_OPTS = {
62 - 'only_latest': False,
63 - 'show_full_log': False,
64 - 'limit': None,
65 - 'from': None,
66 - 'to': None
67 -}
68 -
69 -# =========
70 -# Functions
71 -# =========
72 -
73 -def print_help(with_description=True):
74 - """Print description, usage and a detailed help message.
75 -
76 - @type with_description: bool
77 - @param with_description: if true, print module's __doc__ string
78 - """
79 -
80 - if with_description:
81 - print(__doc__.strip())
82 - print()
83 - print(mod_usage(mod_name="changes"))
84 - print()
85 - print(pp.emph("examples"))
86 - print (" c portage # show latest visible "
87 - "version's entry")
88 - print(" c portage --full --limit=3 # show 3 latest entries")
89 - print(" c '=sys-apps/portage-2.1.6*' # use atom syntax")
90 - print(" c portage --from=2.2_rc60 --to=2.2_rc70 # use version ranges")
91 - print()
92 - print(pp.command("options"))
93 - print(format_options((
94 - (" -h, --help", "display this help message"),
95 - (" -l, --latest", "display only the latest ChangeLog entry"),
96 - (" -f, --full", "display the full ChangeLog"),
97 - (" --limit=NUM",
98 - "limit the number of entries displayed (with --full)"),
99 - (" --from=VER", "set which version to display from"),
100 - (" --to=VER", "set which version to display to"),
101 - )))
102 -
103 -
104 -def parse_module_options(module_opts):
105 - """Parse module options and update QUERY_OPTS"""
106 -
107 - opts = (x[0] for x in module_opts)
108 - posargs = (x[1] for x in module_opts)
109 - for opt, posarg in zip(opts, posargs):
110 - if opt in ('-h', '--help'):
111 - print_help()
112 - sys.exit(0)
113 - elif opt in ('-f', '--full'):
114 - QUERY_OPTS['show_full_log'] = True
115 - elif opt in ('-l', '--latest'):
116 - QUERY_OPTS['only_latest'] = True
117 - elif opt in ('--limit',):
118 - set_limit(posarg)
119 - elif opt in ('--from',):
120 - QUERY_OPTS['from'] = posarg
121 - elif opt in ('--to',):
122 - QUERY_OPTS['to'] = posarg
123 -
124 -
125 -def print_entries(entries):
126 - """Print entries and strip trailing whitespace from the last entry."""
127 -
128 - len_entries = len(entries)
129 - for i, entry in enumerate(entries, start=1):
130 - if i < len_entries:
131 - pp.uprint(entry)
132 - else:
133 - pp.uprint(entry.strip())
134 -
135 -
136 -def set_limit(posarg):
137 - """Set a limit in QUERY_OPTS on how many ChangeLog entries to display.
138 -
139 - Die if posarg is not an integer.
140 - """
141 -
142 - if posarg.isdigit():
143 - QUERY_OPTS['limit'] = int(posarg)
144 - else:
145 - err = "Module option --limit requires integer (got '%s')"
146 - sys.stderr.write(pp.error(err % posarg))
147 - print()
148 - print_help(with_description=False)
149 - sys.exit(2)
150 -
151 -
152 -def main(input_args):
153 - """Parse input and run the program"""
154 -
155 - short_opts = "hlf"
156 - long_opts = ('help', 'full', 'from=', 'latest', 'limit=', 'to=')
157 -
158 - try:
159 - module_opts, queries = gnu_getopt(input_args, short_opts, long_opts)
160 - except GetoptError as err:
161 - sys.stderr.write(pp.error("Module %s" % err))
162 - print()
163 - print_help(with_description=False)
164 - sys.exit(2)
165 -
166 - parse_module_options(module_opts)
167 -
168 - if not queries:
169 - print_help()
170 - sys.exit(2)
171 -
172 - first_run = True
173 - got_match = False
174 - for query in (Query(x) for x in queries):
175 - if not first_run:
176 - print()
177 -
178 - match = query.find_best()
179 - if match is None:
180 - continue
181 -
182 - got_match = True
183 - changelog_path = os.path.join(match.package_path(), 'ChangeLog')
184 - changelog = ChangeLog(changelog_path)
185 -
186 - #
187 - # Output
188 - #
189 -
190 - if (QUERY_OPTS['only_latest'] or (
191 - changelog.entries and not changelog.indexed_entries
192 - )):
193 - pp.uprint(changelog.latest.strip())
194 - else:
195 - end = QUERY_OPTS['limit'] or len(changelog.indexed_entries)
196 - if QUERY_OPTS['to'] or QUERY_OPTS['from']:
197 - print_entries(
198 - changelog.entries_matching_range(
199 - from_ver=QUERY_OPTS['from'],
200 - to_ver=QUERY_OPTS['to']
201 - )[:end]
202 - )
203 - elif QUERY_OPTS['show_full_log']:
204 - print_entries(changelog.full[:end])
205 - else:
206 - # Raises GentoolkitInvalidAtom here if invalid
207 - if query.is_ranged():
208 - atom = Atom(str(query))
209 - else:
210 - atom = '=' + str(match.cpv)
211 - print_entries(changelog.entries_matching_atom(atom)[:end])
212 -
213 - first_run = False
214 -
215 - if not got_match:
216 - sys.exit(1)
217 -
218 -# vim: set ts=4 sw=4 tw=79:
219 diff --git a/pym/gentoolkit/helpers.py b/pym/gentoolkit/helpers.py
220 index e7185c3..236a379 100644
221 --- a/pym/gentoolkit/helpers.py
222 +++ b/pym/gentoolkit/helpers.py
223 @@ -9,7 +9,6 @@
224 """
225
226 __all__ = (
227 - 'ChangeLog',
228 'FileOwner',
229 'get_cpvs',
230 'get_installed_cpvs',
231 @@ -43,178 +42,6 @@ from gentoolkit.versionmatch import VersionMatch
232 # Classes
233 # =======
234
235 -class ChangeLog:
236 - """Provides methods for working with a Gentoo ChangeLog file.
237 -
238 - Example usage:
239 - >>> from gentoolkit.helpers import ChangeLog
240 - >>> portage = ChangeLog('/usr/portage/sys-apps/portage/ChangeLog')
241 - >>> print(portage.latest.strip())
242 - *portage-2.2.0_alpha142 (26 Oct 2012)
243 - <BLANKLINE>
244 - 26 Oct 2012; Zac Medico <zmedico@g.o> +portage-2.2.0_alpha142.ebuild:
245 - 2.2.0_alpha142 version bump. This includes all of the fixes in 2.1.11.31. Bug
246 - #210077 tracks all bugs fixed since portage-2.1.x.
247 - >>> len(portage.full)
248 - 270
249 - >>> len(portage.entries_matching_range(
250 - ... from_ver='2.1.11.31',
251 - ... to_ver='9999'))
252 - 140
253 - """
254 - def __init__(self, changelog_path, invalid_entry_is_fatal=False):
255 - if not (os.path.isfile(changelog_path) and
256 - os.access(changelog_path, os.R_OK)):
257 - raise errors.GentoolkitFatalError(
258 - "%s does not exist or is unreadable" % pp.path(changelog_path)
259 - )
260 - self.changelog_path = changelog_path
261 - self.invalid_entry_is_fatal = invalid_entry_is_fatal
262 -
263 - # Process the ChangeLog:
264 - self.entries = self._split_changelog()
265 - self.indexed_entries = self._index_changelog()
266 - self.full = self.entries
267 - self.latest = self.entries[0]
268 -
269 - def __repr__(self):
270 - return "<%s %r>" % (self.__class__.__name__, self.changelog_path)
271 -
272 - def entries_matching_atom(self, atom):
273 - """Return entries whose header versions match atom's version.
274 -
275 - @type atom: L{gentoolkit.atom.Atom} or str
276 - @param atom: a atom to find matching entries against
277 - @rtype: list
278 - @return: entries matching atom
279 - @raise errors.GentoolkitInvalidAtom: if atom is a string and malformed
280 - """
281 - result = []
282 -
283 - if not isinstance(atom, Atom):
284 - atom = Atom(atom)
285 -
286 - for entry_set in self.indexed_entries:
287 - i, entry = entry_set
288 - # VersionMatch doesn't store .cp, so we'll force it to match here:
289 - i.cp = atom.cp
290 - if atom.intersects(i):
291 - result.append(entry)
292 -
293 - return result
294 -
295 - def entries_matching_range(self, from_ver=None, to_ver=None):
296 - """Return entries whose header versions are within a range of versions.
297 -
298 - @type from_ver: str
299 - @param from_ver: valid Gentoo version
300 - @type to_ver: str
301 - @param to_ver: valid Gentoo version
302 - @rtype: list
303 - @return: entries between from_ver and to_ver
304 - @raise errors.GentoolkitFatalError: if neither vers are set
305 - @raise errors.GentoolkitInvalidVersion: if either ver is invalid
306 - """
307 - result = []
308 -
309 - # Make sure we have at least one version set
310 - if not (from_ver or to_ver):
311 - raise errors.GentoolkitFatalError(
312 - "Need to specifiy 'from_ver' or 'to_ver'"
313 - )
314 -
315 - # Create a VersionMatch instance out of from_ver
316 - from_restriction = None
317 - if from_ver:
318 - try:
319 - from_ver_rev = CPV("null-%s" % from_ver)
320 - except errors.GentoolkitInvalidCPV:
321 - raise errors.GentoolkitInvalidVersion(from_ver)
322 - from_restriction = VersionMatch(from_ver_rev, op='>=')
323 -
324 - # Create a VersionMatch instance out of to_ver
325 - to_restriction = None
326 - if to_ver:
327 - try:
328 - to_ver_rev = CPV("null-%s" % to_ver)
329 - except errors.GentoolkitInvalidCPV:
330 - raise errors.GentoolkitInvalidVersion(to_ver)
331 - to_restriction = VersionMatch(to_ver_rev, op='<=')
332 -
333 - # Add entry to result if version ranges intersect it
334 - for entry_set in self.indexed_entries:
335 - i, entry = entry_set
336 - if from_restriction and not from_restriction.match(i):
337 - continue
338 - if to_restriction and not to_restriction.match(i):
339 - # TODO: is it safe to break here?
340 - continue
341 - result.append(entry)
342 -
343 - return result
344 -
345 - def _index_changelog(self):
346 - """Use the output of L{self._split_changelog} to create an index list
347 - of L{gentoolkit.versionmatch.VersionMatch} objects.
348 -
349 - @rtype: list
350 - @return: tuples containing a VersionMatch instance for the release
351 - version of each entry header as the first item and the entire entry
352 - as the second item
353 - @raise ValueError: if self.invalid_entry_is_fatal is True and we hit an
354 - invalid entry
355 - """
356 -
357 - result = []
358 - for entry in self.entries:
359 - # Extract the package name from the entry header, ex:
360 - # *xterm-242 (07 Mar 2009) => xterm-242
361 - pkg_name = entry.split(' ', 1)[0].lstrip('*')
362 - if not pkg_name.strip():
363 - continue
364 - try:
365 - entry_ver = CPV(pkg_name, validate=True)
366 - except errors.GentoolkitInvalidCPV:
367 - if self.invalid_entry_is_fatal:
368 - raise ValueError(entry_ver)
369 - continue
370 -
371 - result.append((VersionMatch(entry_ver, op='='), entry))
372 -
373 - return result
374 -
375 - def _split_changelog(self):
376 - """Split the ChangeLog into individual entries.
377 -
378 - @rtype: list
379 - @return: individual ChangeLog entries
380 - """
381 -
382 - result = []
383 - partial_entries = []
384 - with open(_unicode_encode(self.changelog_path,
385 - encoding=_encodings['fs'], errors="replace"),
386 - encoding=_encodings['content']) as log:
387 - for line in log:
388 - if line.startswith('#'):
389 - continue
390 - elif line.startswith('*'):
391 - # Append last entry to result...
392 - entry = ''.join(partial_entries)
393 - if entry and not entry.isspace():
394 - result.append(entry)
395 - # ... and start a new entry
396 - partial_entries = [line]
397 - else:
398 - partial_entries.append(line)
399 - else:
400 - # Append the final entry
401 - entry = ''.join(partial_entries)
402 - result.append(entry)
403 -
404 - return result
405 -
406 -
407 class FileOwner:
408 """Creates a function for locating the owner of filename queries.
409
410 diff --git a/pym/gentoolkit/test/equery/test_init.py b/pym/gentoolkit/test/equery/test_init.py
411 index 075f653..4cad22e 100644
412 --- a/pym/gentoolkit/test/equery/test_init.py
413 +++ b/pym/gentoolkit/test/equery/test_init.py
414 @@ -15,7 +15,6 @@ class TestEqueryInit(unittest.TestCase):
415 name_map = {
416 'a': 'has',
417 'b': 'belongs',
418 - 'c': 'changes',
419 'k': 'check',
420 'd': 'depends',
421 'g': 'depgraph',
422 diff --git a/pym/gentoolkit/test/test_helpers.py b/pym/gentoolkit/test/test_helpers.py
423 index 734539c..be27835 100644
424 --- a/pym/gentoolkit/test/test_helpers.py
425 +++ b/pym/gentoolkit/test/test_helpers.py
426 @@ -6,52 +6,6 @@ from tempfile import NamedTemporaryFile, mktemp
427 from gentoolkit import helpers
428
429
430 -class TestChangeLog(unittest.TestCase):
431 -
432 - def setUp(self):
433 - pass
434 -
435 - def tearDown(self):
436 - pass
437 -
438 -# Commented out for being useless
439 -# def test_split_changelog(self):
440 -# changelog = """
441 -# *portage-2.1.6.2 (20 Dec 2008)
442 -
443 -# 20 Dec 2008; Zac Medico <zmedico@g.o> +portage-2.1.6.2.ebuild:
444 -# 2.1.6.2 bump. This fixes bug #251591 (repoman inherit.autotools false
445 -# positives) and bug #251616 (performance issue in build log search regex
446 -# makes emerge appear to hang). Bug #216231 tracks all bugs fixed since
447 -# 2.1.4.x.
448 -
449 -# 20 Dec 2008; Zac Medico <zmedico@g.o> -portage-2.1.6.ebuild,
450 -# -portage-2.1.6.1.ebuild, -portage-2.2_rc17.ebuild:
451 -# Remove old versions.
452 -
453 -
454 -# *portage-2.1.6.1 (12 Dec 2008)
455 -
456 -# 12 Dec 2008; Zac Medico <zmedico@g.o> +portage-2.1.6.1.ebuild:
457 -# 2.1.6.1 bump. This fixes bug #250148 (emerge hangs with selinux if ebuild
458 -# spawns a daemon), bug #250166 (trigger download when generating manifest
459 -# if file size differs from existing entry), and bug #250212 (new repoman
460 -# upstream.workaround category for emake -j1 warnings). Bug #216231 tracks
461 -# all bugs fixed since 2.1.4.x.
462 -
463 -
464 -# *portage-2.1.6 (07 Dec 2008)
465 -
466 -# 07 Dec 2008; Zac Medico <zmedico@g.o> +portage-2.1.6.ebuild:
467 -# 2.1.6 final release. This fixes bug #249586. Bug #216231 tracks all bugs
468 -# fixed since 2.1.4.x.
469 -
470 -# 07 Dec 2008; Zac Medico <zmedico@g.o> -portage-2.1.6_rc1.ebuild,
471 -# -portage-2.1.6_rc2.ebuild, -portage-2.1.6_rc3.ebuild,
472 -# -portage-2.2_rc16.ebuild:
473 -# Remove old versions.
474 -# """
475 -
476 class TestFileOwner(unittest.TestCase):
477
478 def setUp(self):
479 @@ -113,7 +67,6 @@ class TestFileOwner(unittest.TestCase):
480
481 def test_main():
482 suite = unittest.TestLoader()
483 - suite.loadTestsFromTestCase(TestChangeLog)
484 suite.loadTestsFromTestCase(TestFileOwner)
485 unittest.TextTestRunner(verbosity=2).run(suite)
486 test_main.__test__ = False
487 --
488 2.26.2

Replies