Gentoo Archives: gentoo-catalyst

From: Mike Frysinger <vapier@g.o>
To: gentoo-catalyst@l.g.o
Subject: [gentoo-catalyst] [PATCH 2/9] make_target_table: rewrite for py3/stability
Date: Mon, 12 Oct 2015 04:36:11
Message-Id: 1444624562-26162-2-git-send-email-vapier@gentoo.org
In Reply to: [gentoo-catalyst] [PATCH 1/9] convert octals to py3 compat by Mike Frysinger
1 ---
2 doc/make_target_table.py | 32 ++++++++++++++++++--------------
3 1 file changed, 18 insertions(+), 14 deletions(-)
4
5 diff --git a/doc/make_target_table.py b/doc/make_target_table.py
6 index f127c37..9eb072b 100755
7 --- a/doc/make_target_table.py
8 +++ b/doc/make_target_table.py
9 @@ -1,4 +1,4 @@
10 -#!/usr/bin/env python2
11 +#!/usr/bin/python
12 # Copyright (C) 2012 W. Trevor King <wking@××××××.edu>
13 # Copyright (C) 2012 Sebastian Pipping <sebastian@×××××××.org>
14 # Copyright (C) 2013 Brian dolbec <dolsen@g.o>
15 @@ -10,34 +10,38 @@
16
17 from __future__ import print_function
18
19 -import sys as _sys
20 -
21 import glob
22 -import re
23 +import locale
24 +import os
25 +import sys
26
27
28 -def key_netboot_before_netboot2((target_name, _module)):
29 - return target_name + '1'
30 +def main(_argv):
31 + source_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
32
33 + # Force consistent sorting order.
34 + locale.setlocale(locale.LC_COLLATE, 'C')
35
36 -if __name__ == '__main__':
37 - extractor = re.compile('^catalyst/targets/(([^ ]+)).py$')
38 targets = list()
39 - for filename in sorted(glob.glob('catalyst/targets/*.py')):
40 + for filename in glob.glob(os.path.join(source_root, 'catalyst/targets/*.py')):
41 if '__init__' in filename:
42 continue
43
44 - match = extractor.match(filename)
45 - target_name = match.group(2).replace('_', '-')
46 - module_name = 'catalyst.targets.' + match.group(1)
47 + name = os.path.basename(filename)[0:-3]
48 + target_name = name.replace('_', '-')
49 + module_name = 'catalyst.targets.' + name
50
51 __import__(module_name)
52 - module = _sys.modules[module_name]
53 + module = sys.modules[module_name]
54
55 targets.append((target_name, module))
56
57 - for target_name, module in sorted(targets, key=key_netboot_before_netboot2):
58 + for target_name, module in sorted(targets, key=lambda x: x[0]):
59 print('`%s`;;' % target_name)
60 # Replace blank lines with `+` (asciidoc list item continuation)
61 print(module.__doc__.strip().replace('\n\n', '\n+\n'))
62 print('')
63 +
64 +
65 +if __name__ == '__main__':
66 + main(sys.argv[1:])
67 --
68 2.5.2

Replies