"""
This script finds tools that should be added to templates.py
"""
import os
import sys
from os import path
import glob
from templates import TOOLS, generateToolTemplates
toolDir = path.join(path.dirname(__file__), '..')
pyfiles = glob.glob("**/*.py", root_dir=toolDir, recursive=True)
print("found %s python files" % len(pyfiles))
candidates = []
for fname in pyfiles:
with open(os.path.join(toolDir, fname)) as f:
for line in f:
if "ArgumentParser" in line:
candidates.append(fname)
break
print("found %s files that use ArgumentParser" % len(candidates))
candidates = [f for f in candidates if path.dirname(f) not in ('build_config', 'devel', 'game', 'purgatory')]
print("found %s tools in eligble directories" % len(candidates))
usedTools = set(TOOLS)
candidates = [f for f in candidates if f not in usedTools]
print("found %s tools that are not listed in templates.py" % len(candidates))
failed = generateToolTemplates(toolDir, candidates, False, True)
if failed:
print("%s tools fail at template generation:" % len(failed))
print('\n'.join(failed), file=sys.stderr)
failedSet = set(failed)
missing = [f for f in candidates if f not in failedSet]
print("found %s usable tools:" % len(missing))
print('\n'.join(missing))