2015-12-28 14:31:36 -07:00
|
|
|
from __future__ import print_function
|
2015-10-24 00:00:54 -06:00
|
|
|
from io import open
|
|
|
|
import os
|
2015-11-04 06:23:45 -07:00
|
|
|
from os.path import basename, dirname, join, splitext
|
2015-10-24 00:00:54 -06:00
|
|
|
import sys
|
2015-09-22 23:25:41 -06:00
|
|
|
|
2015-11-04 06:23:45 -07:00
|
|
|
|
|
|
|
def expected_cmd(path):
|
|
|
|
"""Get the command from the name of a script."""
|
|
|
|
dname, fname = basename(dirname(path)), splitext(basename(path))[0]
|
|
|
|
if dname in ('devel', 'fix', 'gui', 'modtools'):
|
|
|
|
return dname + '/' + fname
|
|
|
|
return fname
|
2015-10-24 00:00:54 -06:00
|
|
|
|
|
|
|
|
|
|
|
def check_file(fname):
|
2015-11-04 06:23:45 -07:00
|
|
|
errors, doclines = 0, []
|
2015-10-24 00:00:54 -06:00
|
|
|
with open(fname, errors='ignore') as f:
|
|
|
|
for l in f.readlines():
|
2015-12-28 14:31:36 -07:00
|
|
|
if not l.strip():
|
|
|
|
continue
|
2015-10-24 00:00:54 -06:00
|
|
|
if doclines or l.strip().endswith('=begin'):
|
|
|
|
doclines.append(l.rstrip())
|
|
|
|
if l.startswith('=end'):
|
|
|
|
break
|
|
|
|
else:
|
2015-10-27 17:07:02 -06:00
|
|
|
if doclines:
|
|
|
|
print('Error: docs start but not end: ' + fname)
|
|
|
|
else:
|
|
|
|
print('Error: no documentation in: ' + fname)
|
2015-10-24 00:00:54 -06:00
|
|
|
return 1
|
2015-12-28 14:31:36 -07:00
|
|
|
title, underline = doclines[1], doclines[2]
|
2015-10-24 00:00:54 -06:00
|
|
|
if underline != '=' * len(title):
|
|
|
|
print('Error: title/underline mismatch:', fname, title, underline)
|
2015-11-04 06:23:45 -07:00
|
|
|
errors += 1
|
|
|
|
if title != expected_cmd(fname):
|
|
|
|
print('Warning: expected script title {}, got {}'.format(
|
|
|
|
expected_cmd(fname), title))
|
|
|
|
errors += 1
|
|
|
|
return errors
|
2015-09-22 23:25:41 -06:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2015-10-24 00:00:54 -06:00
|
|
|
"""Check that all DFHack scripts include documentation (not 3rdparty)"""
|
2015-11-04 06:23:45 -07:00
|
|
|
err = 0
|
|
|
|
for root, _, files in os.walk('scripts'):
|
|
|
|
for f in files:
|
|
|
|
# TODO: remove 3rdparty exemptions from checks
|
|
|
|
# Requires reading their CMakeLists to only apply to used scripts
|
|
|
|
if f[-3:] in {'.rb', 'lua'} and '3rdparty' not in root:
|
|
|
|
err += check_file(join(root, f))
|
|
|
|
return err
|
2015-10-24 00:00:54 -06:00
|
|
|
|
2015-09-22 23:25:41 -06:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-10-24 00:00:54 -06:00
|
|
|
sys.exit(bool(main()))
|