jvr | da15a42 | 2002-09-10 13:09:27 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | import sys |
| 4 | import os |
| 5 | import glob |
| 6 | from fontTools.ttLib import identifierToTag |
| 7 | |
| 8 | |
jvr | 9151a0c | 2002-09-10 20:42:35 +0000 | [diff] [blame] | 9 | fontToolsDir = os.path.dirname(os.path.dirname(os.path.join(os.getcwd(), sys.argv[0]))) |
| 10 | fontToolsDir= os.path.normpath(fontToolsDir) |
| 11 | tablesDir = os.path.join(fontToolsDir, |
| 12 | "Lib", "fontTools", "ttLib", "tables") |
| 13 | docFile = os.path.join(fontToolsDir, "Doc", "documentation.html") |
jvr | da15a42 | 2002-09-10 13:09:27 +0000 | [diff] [blame] | 14 | |
| 15 | names = glob.glob1(tablesDir, "*.py") |
| 16 | |
| 17 | modules = [] |
jvr | 9151a0c | 2002-09-10 20:42:35 +0000 | [diff] [blame] | 18 | tables = [] |
jvr | da15a42 | 2002-09-10 13:09:27 +0000 | [diff] [blame] | 19 | for name in names: |
| 20 | try: |
| 21 | tag = identifierToTag(name[:-3]) |
| 22 | except: |
| 23 | pass |
| 24 | else: |
| 25 | modules.append(name[:-3]) |
jvr | 9151a0c | 2002-09-10 20:42:35 +0000 | [diff] [blame] | 26 | tables.append(tag.strip()) |
jvr | da15a42 | 2002-09-10 13:09:27 +0000 | [diff] [blame] | 27 | |
| 28 | modules.sort() |
jvr | 9151a0c | 2002-09-10 20:42:35 +0000 | [diff] [blame] | 29 | tables.sort() |
| 30 | |
jvr | da15a42 | 2002-09-10 13:09:27 +0000 | [diff] [blame] | 31 | |
| 32 | file = open(os.path.join(tablesDir, "__init__.py"), "w") |
| 33 | |
jvr | 4ca01ea | 2003-08-25 21:19:47 +0000 | [diff] [blame] | 34 | file.write("# DON'T EDIT! This file is generated by MetaTools/buildTableList.py.\n") |
jvr | da15a42 | 2002-09-10 13:09:27 +0000 | [diff] [blame] | 35 | file.write("def _moduleFinderHint():\n") |
| 36 | file.write('\t"""Dummy function to let modulefinder know what tables may be\n') |
| 37 | file.write('\tdynamically imported. Generated by MetaTools/buildTableList.py.\n') |
| 38 | file.write('\t"""\n') |
| 39 | for module in modules: |
Behdad Esfahbod | e07cc6a | 2013-12-06 19:54:59 -0500 | [diff] [blame^] | 40 | file.write("\tfrom . import %s\n" % module) |
jvr | da15a42 | 2002-09-10 13:09:27 +0000 | [diff] [blame] | 41 | |
| 42 | file.close() |
jvr | 9151a0c | 2002-09-10 20:42:35 +0000 | [diff] [blame] | 43 | |
| 44 | |
| 45 | begin = "<!-- begin table list -->" |
| 46 | end = "<!-- end table list -->" |
| 47 | doc = open(docFile).read() |
| 48 | beginPos = doc.find(begin) |
| 49 | assert beginPos > 0 |
| 50 | beginPos = beginPos + len(begin) + 1 |
| 51 | endPos = doc.find(end) |
| 52 | |
| 53 | doc = doc[:beginPos] + ", ".join(tables[:-1]) + " and " + tables[-1] + "\n" + doc[endPos:] |
| 54 | |
| 55 | open(docFile, "w").write(doc) |