2015-10-24 00:00:54 -06:00
|
|
|
from io import open
|
|
|
|
import os
|
|
|
|
import sys
|
2015-09-22 23:25:41 -06:00
|
|
|
|
2015-10-24 00:00:54 -06:00
|
|
|
scriptdirs = (
|
|
|
|
'scripts',
|
|
|
|
#'scripts/devel', # devel scripts don't have to be documented
|
|
|
|
'scripts/fix',
|
|
|
|
'scripts/gui',
|
|
|
|
'scripts/modtools')
|
|
|
|
|
|
|
|
|
|
|
|
def check_file(fname):
|
|
|
|
doclines = []
|
|
|
|
with open(fname, errors='ignore') as f:
|
|
|
|
for l in f.readlines():
|
|
|
|
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
|
|
|
|
title, underline = doclines[2], doclines[3]
|
|
|
|
if underline != '=' * len(title):
|
|
|
|
print('Error: title/underline mismatch:', fname, title, underline)
|
|
|
|
return 1
|
|
|
|
start = fname.split('/')[-2]
|
|
|
|
if start != 'scripts' and not title.startswith(start):
|
2015-10-27 17:07:02 -06:00
|
|
|
print('Error: title is missing start string: {} {} {}'.format(fname, start, title))
|
2015-10-24 00:00:54 -06:00
|
|
|
return 1
|
|
|
|
return 0
|
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)"""
|
|
|
|
errors = 0
|
|
|
|
for path in scriptdirs:
|
|
|
|
for f in os.listdir(path):
|
|
|
|
f = path + '/' + f
|
|
|
|
if os.path.isfile(f) and f[-3:] in {'.rb', 'lua'}:
|
|
|
|
errors += check_file(f)
|
|
|
|
return errors
|
|
|
|
|
2015-09-22 23:25:41 -06:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-10-24 00:00:54 -06:00
|
|
|
sys.exit(bool(main()))
|