| 1 |
|
| 2 |
import sys |
| 3 |
|
| 4 |
target_modules = [ |
| 5 |
"gftools-build-font2ttf", |
| 6 |
"gftools-fix-ascii-fontmetadata", |
| 7 |
"gftools-fix-familymetadata", |
| 8 |
"gftools-fix-fsselection", |
| 9 |
"gftools-fix-gasp", |
| 10 |
"gftools-fix-glyph-private-encoding", |
| 11 |
"gftools-fix-glyphs", |
| 12 |
"gftools-fix-nameids", |
| 13 |
|
| 14 |
"gftools-fix-ttfautohint", |
| 15 |
"gftools-fix-vendorid", |
| 16 |
"gftools-fix-vertical-metrics", |
| 17 |
"gftools-list-panose", |
| 18 |
"gftools-list-weightclass", |
| 19 |
"gftools-list-widthclass", |
| 20 |
"gftools-metadata-vs-api", |
| 21 |
"gftools-update-families", |
| 22 |
] |
| 23 |
|
| 24 |
|
| 25 |
help_text = {} |
| 26 |
for module_name in target_modules: |
| 27 |
target = __import__(module_name) |
| 28 |
help_text[module_name] = target.parser.format_help() |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
mandatory_args = ["[-h]"] |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
optional_args = [ |
| 39 |
"[-v]", |
| 40 |
"[--autofix]", |
| 41 |
"[--csv]", |
| 42 |
"[--verbose]", |
| 43 |
"[-a ASCENTS]", |
| 44 |
"[-ah ASCENTS_HHEA]", |
| 45 |
"[-at ASCENTS_TYPO]", |
| 46 |
"[-aw ASCENTS_WIN]", |
| 47 |
"[-d DESCENTS]", |
| 48 |
"[-dh DESCENTS_HHEA]", |
| 49 |
"[-dt DESCENTS_TYPO]", |
| 50 |
"[-dw DESCENTS_WIN]", |
| 51 |
"[-l LINEGAPS]", |
| 52 |
"[-lh LINEGAPS_HHEA]", |
| 53 |
"[-lt LINEGAPS_TYPO]", |
| 54 |
"[--api API]", |
| 55 |
"[--cache CACHE]", |
| 56 |
"[--set SET]", |
| 57 |
"[--platform PLATFORM]", |
| 58 |
"[--id ID]", |
| 59 |
"[--ignore-copy-existing-ttf]", |
| 60 |
"[--with-otf]", |
| 61 |
"[-e EXISTING]", |
| 62 |
] |
| 63 |
|
| 64 |
failed = False |
| 65 |
for arg in mandatory_args: |
| 66 |
missing = [] |
| 67 |
for module_name in help_text.keys(): |
| 68 |
if arg not in help_text[module_name]: |
| 69 |
missing.append(module_name) |
| 70 |
|
| 71 |
if missing != []: |
| 72 |
failed = True |
| 73 |
print( |
| 74 |
( |
| 75 |
"ERROR: These modules lack the {} command line argument:" |
| 76 |
"\nERROR:\t{}\n" |
| 77 |
).format(arg, "\nERROR:\t".join(missing)) |
| 78 |
) |
| 79 |
|
| 80 |
import re |
| 81 |
|
| 82 |
for module_name in help_text.keys(): |
| 83 |
text = help_text[module_name] |
| 84 |
args = re.findall("(\[\-[^\[]*\])", text) |
| 85 |
|
| 86 |
|
| 87 |
for arg in args: |
| 88 |
if arg not in optional_args + mandatory_args: |
| 89 |
print( |
| 90 |
( |
| 91 |
"WARNING: Module {} has cmdline argument {}" |
| 92 |
" which is not in the list of optional ones." |
| 93 |
"" |
| 94 |
).format(module_name, arg) |
| 95 |
) |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
if failed: |
| 100 |
sys.exit( |
| 101 |
"Some errors were detected in the command-line" |
| 102 |
" arguments of the Font Bakery scripts." |
| 103 |
) |