• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /usr/bin/env python3
2
3import sys
4import os
5import glob
6from fontTools.ttLib import identifierToTag
7import textwrap
8
9
10fontToolsDir = os.path.dirname(os.path.dirname(os.path.join(os.getcwd(), sys.argv[0])))
11fontToolsDir= os.path.normpath(fontToolsDir)
12tablesDir = os.path.join(fontToolsDir,
13		"Lib", "fontTools", "ttLib", "tables")
14docFile = os.path.join(fontToolsDir, "Doc/source/ttx.rst")
15
16names = glob.glob1(tablesDir, "*.py")
17
18modules = []
19tables = []
20for name in names:
21	try:
22		tag = identifierToTag(name[:-3])
23	except:
24		pass
25	else:
26		modules.append(name[:-3])
27		tables.append(tag.strip())
28
29modules.sort()
30tables.sort()
31
32
33with open(os.path.join(tablesDir, "__init__.py"), "w") as file:
34
35	file.write('''
36# DON'T EDIT! This file is generated by MetaTools/buildTableList.py.
37def _moduleFinderHint():
38	"""Dummy function to let modulefinder know what tables may be
39	dynamically imported. Generated by MetaTools/buildTableList.py.
40
41		>>> _moduleFinderHint()
42	"""
43''')
44
45	for module in modules:
46		file.write("\tfrom . import %s\n" % module)
47
48	file.write('''
49if __name__ == "__main__":
50	import doctest, sys
51	sys.exit(doctest.testmod().failed)
52''')
53
54
55begin = ".. begin table list\n"
56end = ".. end table list"
57with open(docFile) as f:
58	doc = f.read()
59beginPos = doc.find(begin)
60assert beginPos > 0
61beginPos = beginPos + len(begin) + 1
62endPos = doc.find(end)
63
64lines = textwrap.wrap(", ".join(tables[:-1]) + " and " + tables[-1], 66)
65intro = "The following tables are currently supported::\n\n"
66blockquote = "\n".join(" "*4 + line for line in lines) + "\n"
67
68doc = doc[:beginPos] + intro + blockquote + "\n" + doc[endPos:]
69
70with open(docFile, "w") as f:
71	f.write(doc)
72