1 #! /usr/bin/env python 2 3 import sys 4 import os 5 import glob 6 from fontTools.ttLib import identifierToTag 7 8 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") 14 15 names = glob.glob1(tablesDir, "*.py") 16 17 modules = [] 18 tables = [] 19 for 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 28 modules.sort() 29 tables.sort() 30 31 32 file = open(os.path.join(tablesDir, "__init__.py"), "w") 33 34 file.write("# DON'T EDIT! This file is generated by MetaTools/buildTableList.py.\n") 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: 40 file.write("\tfrom . import %s\n" % module) 41 42 file.close() 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) 56