Migrate doc/make_target_table.py to Catalyst 2.x and Python 2.x
authorSebastian Pipping <sebastian@pipping.org>
Mon, 9 Jul 2012 15:02:12 +0000 (17:02 +0200)
committerSebastian Pipping <sebastian@pipping.org>
Mon, 9 Jul 2012 15:14:18 +0000 (17:14 +0200)
Makefile
doc/make_target_table.py

index bbdb525de97f3d4d9f7c093775bacb6b328e6743..ba802ad2d9cf14258e35706322e8788389ba1a92 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ $(MAN_PAGES): files/%: doc/%.txt $(MAN_PAGE_INCLUDES) doc/asciidoc.conf Makefile
 doc/subarches.generated.txt: $(wildcard arch/*.py) doc/make_subarch_table_guidexml.py
        ./doc/make_subarch_table_guidexml.py
 
-doc/targets.generated.txt: doc/make_target_table.py $(wildcard modules/catalyst/targets/*.py)
+doc/targets.generated.txt: doc/make_target_table.py $(wildcard modules/*_target.py)
        "./$<" > "$@"
 
 clean:
index 1bacbe286c341ac367e756a39cdfa95a8937c824..b72935fa10ef371133a7a3b1a069f22d301f5271 100755 (executable)
@@ -1,21 +1,34 @@
 #!/usr/bin/env python
 # Copyright (C) 2012 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2012 Sebastian Pipping <sebastian@pippin.org>
 # Licensed under GPL v2 or later
 
 # This script should be run from the root of the catalyst source.
 
+from __future__ import print_function
+
 import sys as _sys
 
 _sys.path.insert(0, 'modules')  # so we can find the `catalyst` module
 
-import catalyst.target as _catalyst_target
+import glob
+import re
 
 
 if __name__ == '__main__':
-    for module_name,module in sorted(_catalyst_target.get_targets().items()):
-        if hasattr(module, '__target_map'):
-            target_name = module.__target_map.keys()[0]
-            print('`{}`;;'.format(target_name))
-            # Replace blank lines with `+` (asciidoc list item continuation)
-            print(module.__doc__.strip().replace('\n\n', '\n+\n'))
-            print('')
+       extractor = re.compile('^modules/(([^ ]+)_target).py$')
+       for filename in sorted(glob.glob('modules/*_target.py')):
+               if 'generic' in filename:
+                       continue
+
+               match = extractor.match(filename)
+               target_name = match.group(2).replace('_', '-')
+               module_name = match.group(1)
+
+               __import__(module_name)
+               module = _sys.modules[module_name]
+
+               print('`%s`;;' % target_name)
+               # Replace blank lines with `+` (asciidoc list item continuation)
+               print(module.__doc__.strip().replace('\n\n', '\n+\n'))
+               print('')