commit: 6a38e62e143df9bda84da1ce8a54948c57e833fa Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> AuthorDate: Mon Oct 12 00:55:05 2015 +0000 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> CommitDate: Wed Oct 28 16:49:56 2015 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=6a38e62e
make_target_table: rewrite for py3/stability doc/make_target_table.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/doc/make_target_table.py b/doc/make_target_table.py index f127c37..9eb072b 100755 --- a/doc/make_target_table.py +++ b/doc/make_target_table.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/python # Copyright (C) 2012 W. Trevor King <wk...@drexel.edu> # Copyright (C) 2012 Sebastian Pipping <sebast...@pipping.org> # Copyright (C) 2013 Brian dolbec <dol...@gentoo.org> @@ -10,34 +10,38 @@ from __future__ import print_function -import sys as _sys - import glob -import re +import locale +import os +import sys -def key_netboot_before_netboot2((target_name, _module)): - return target_name + '1' +def main(_argv): + source_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + # Force consistent sorting order. + locale.setlocale(locale.LC_COLLATE, 'C') -if __name__ == '__main__': - extractor = re.compile('^catalyst/targets/(([^ ]+)).py$') targets = list() - for filename in sorted(glob.glob('catalyst/targets/*.py')): + for filename in glob.glob(os.path.join(source_root, 'catalyst/targets/*.py')): if '__init__' in filename: continue - match = extractor.match(filename) - target_name = match.group(2).replace('_', '-') - module_name = 'catalyst.targets.' + match.group(1) + name = os.path.basename(filename)[0:-3] + target_name = name.replace('_', '-') + module_name = 'catalyst.targets.' + name __import__(module_name) - module = _sys.modules[module_name] + module = sys.modules[module_name] targets.append((target_name, module)) - for target_name, module in sorted(targets, key=key_netboot_before_netboot2): + for target_name, module in sorted(targets, key=lambda x: x[0]): print('`%s`;;' % target_name) # Replace blank lines with `+` (asciidoc list item continuation) print(module.__doc__.strip().replace('\n\n', '\n+\n')) print('') + + +if __name__ == '__main__': + main(sys.argv[1:])