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