2019-12-05 15:28:19 +00:00
|
|
|
#! /usr/bin/env python3
|
2002-09-10 13:09:27 +00:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
from fontTools.ttLib import identifierToTag
|
2015-10-01 11:03:35 +01:00
|
|
|
import textwrap
|
2002-09-10 13:09:27 +00:00
|
|
|
|
|
|
|
|
2002-09-10 20:42:35 +00:00
|
|
|
fontToolsDir = os.path.dirname(os.path.dirname(os.path.join(os.getcwd(), sys.argv[0])))
|
|
|
|
fontToolsDir= os.path.normpath(fontToolsDir)
|
|
|
|
tablesDir = os.path.join(fontToolsDir,
|
|
|
|
"Lib", "fontTools", "ttLib", "tables")
|
2020-05-03 22:53:28 +01:00
|
|
|
docFile = os.path.join(fontToolsDir, "Doc/source/ttx.rst")
|
2002-09-10 13:09:27 +00:00
|
|
|
|
|
|
|
names = glob.glob1(tablesDir, "*.py")
|
|
|
|
|
|
|
|
modules = []
|
2002-09-10 20:42:35 +00:00
|
|
|
tables = []
|
2002-09-10 13:09:27 +00:00
|
|
|
for name in names:
|
|
|
|
try:
|
|
|
|
tag = identifierToTag(name[:-3])
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
modules.append(name[:-3])
|
2002-09-10 20:42:35 +00:00
|
|
|
tables.append(tag.strip())
|
2002-09-10 13:09:27 +00:00
|
|
|
|
|
|
|
modules.sort()
|
2002-09-10 20:42:35 +00:00
|
|
|
tables.sort()
|
|
|
|
|
2002-09-10 13:09:27 +00:00
|
|
|
|
2018-09-25 23:18:21 +02:00
|
|
|
with open(os.path.join(tablesDir, "__init__.py"), "w") as file:
|
2002-09-10 13:09:27 +00:00
|
|
|
|
2018-09-25 23:18:21 +02:00
|
|
|
file.write('''
|
2015-04-14 17:26:59 -07:00
|
|
|
from fontTools.misc.py23 import *
|
|
|
|
|
2015-04-14 00:17:52 -07:00
|
|
|
# DON'T EDIT! This file is generated by MetaTools/buildTableList.py.
|
|
|
|
def _moduleFinderHint():
|
|
|
|
"""Dummy function to let modulefinder know what tables may be
|
|
|
|
dynamically imported. Generated by MetaTools/buildTableList.py.
|
|
|
|
|
|
|
|
>>> _moduleFinderHint()
|
|
|
|
"""
|
|
|
|
''')
|
|
|
|
|
2018-09-25 23:18:21 +02:00
|
|
|
for module in modules:
|
|
|
|
file.write("\tfrom . import %s\n" % module)
|
2002-09-10 13:09:27 +00:00
|
|
|
|
2018-09-25 23:18:21 +02:00
|
|
|
file.write('''
|
2015-04-14 00:17:52 -07:00
|
|
|
if __name__ == "__main__":
|
|
|
|
import doctest, sys
|
|
|
|
sys.exit(doctest.testmod().failed)
|
|
|
|
''')
|
|
|
|
|
2002-09-10 20:42:35 +00:00
|
|
|
|
2020-05-03 22:53:28 +01:00
|
|
|
begin = ".. begin table list\n"
|
2017-01-18 16:15:25 +00:00
|
|
|
end = ".. end table list"
|
2018-09-25 23:18:21 +02:00
|
|
|
with open(docFile) as f:
|
|
|
|
doc = f.read()
|
2002-09-10 20:42:35 +00:00
|
|
|
beginPos = doc.find(begin)
|
|
|
|
assert beginPos > 0
|
|
|
|
beginPos = beginPos + len(begin) + 1
|
|
|
|
endPos = doc.find(end)
|
|
|
|
|
2015-10-01 11:03:35 +01:00
|
|
|
lines = textwrap.wrap(", ".join(tables[:-1]) + " and " + tables[-1], 66)
|
2020-05-03 22:53:28 +01:00
|
|
|
intro = "The following tables are currently supported::\n\n"
|
2015-10-01 11:03:35 +01:00
|
|
|
blockquote = "\n".join(" "*4 + line for line in lines) + "\n"
|
|
|
|
|
2020-05-03 22:53:28 +01:00
|
|
|
doc = doc[:beginPos] + intro + blockquote + "\n" + doc[endPos:]
|
2002-09-10 20:42:35 +00:00
|
|
|
|
2018-09-25 23:18:21 +02:00
|
|
|
with open(docFile, "w") as f:
|
|
|
|
f.write(doc)
|