Skip to content

Commit 1d5a31d

Browse files
authored
Merge pull request #2238 from gforney/master
clean up - move some scripts to a more logical place
2 parents d93f8a6 + 85faf98 commit 1d5a31d

File tree

10 files changed

+103
-10
lines changed

10 files changed

+103
-10
lines changed

Manuals/scripts/check_manuals.py

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,40 @@
55
@author: jhodges
66
"""
77

8-
import glob, os
8+
import os, subprocess, platform, argparse, glob, sys
9+
10+
def sortWhitelist(firemodels):
11+
whitelist = os.path.join(firemodels, 'fds','Manuals','Bibliography')+ os.sep + 'whitelist.txt'
12+
whitelist = os.path.abspath(whitelist)
13+
14+
with open(whitelist,'r') as f:
15+
txt = f.readlines()
16+
17+
words = list(set(txt[1:]))
18+
words.sort()
19+
20+
outtxt = txt[0] + '\n' + '\n'.join(words) + '\n'
21+
while '\n\n' in outtxt:
22+
outtxt = outtxt.replace('\n\n','\n')
23+
24+
with open(whitelist.replace('.txt','_back.txt'), 'w') as f:
25+
f.writelines(txt)
26+
27+
with open(whitelist, 'w') as f:
28+
f.write(outtxt)
29+
30+
def checkSpelling(file, firemodels):
31+
whitelist = os.path.join(firemodels, 'fds','Manuals','Bibliography')+ os.sep + 'whitelist.txt'
32+
whitelist = os.path.abspath(whitelist)
33+
if 'Windows' in platform.platform():
34+
whitelist = whitelist.replace('\\','/')
35+
whitelist = whitelist[0].upper() + whitelist[1:]
36+
cmd = ['aspell','--lang=en','--mode=tex','--add-extra-dicts=%s'%(whitelist), 'list', '<', file]
37+
38+
p = subprocess.run(cmd, capture_output=True, shell=True)
39+
txt = p.stdout.decode('utf-8')
40+
txt = txt.replace('\r\n','\n')
41+
return txt
942

1043
def checkCaption(caption):
1144

@@ -44,7 +77,7 @@ def checkCaption(caption):
4477
return outtxt
4578

4679
def check_disallowed_commands(txt, file):
47-
disallowed_commands = ['\\bf{','\\tt{']
80+
disallowed_commands = [] #['\\bf{','\\tt{']
4881
outtxt = ''
4982
for cmd in disallowed_commands:
5083
split = txt.split(cmd)
@@ -54,7 +87,43 @@ def check_disallowed_commands(txt, file):
5487
outtxt = outtxt + "ERROR, %s %s located at line %d\n"%(file, cmd, line_count)
5588
return outtxt
5689

57-
texfiles = glob.glob('..'+os.sep+'*'+os.sep+'*.tex')
90+
args = sys.argv
91+
parser = argparse.ArgumentParser(prog='check_manuals',
92+
description='checks latex manuals for alignment with FDS developer guidelines')
93+
parser.add_argument('call')
94+
parser.add_argument('--file', help='filename to analyze', default='')
95+
parser.add_argument('--datafile', help='filename containing list of files', default='')
96+
parser.add_argument('--globfile', help='glob search for files', default='')
97+
parser.add_argument('--outdir', help='directory to store output', default='')
98+
parser.add_argument('--outname', help='output filename', default='check_output.err')
99+
parser.add_argument('--suppressconsole', help='boolean flag specifying whether findings are printed to console', action='store_true')
100+
101+
cmdargs = parser.parse_args(args)
102+
suppressconsole = cmdargs.suppressconsole
103+
if cmdargs.file != '':
104+
texfiles = [cmdargs.file]
105+
elif cmdargs.datafile != '':
106+
with open(cmdargs.datafile, 'r') as f:
107+
texfiles = f.readlines()
108+
texfiles = [x.replace('\n','') for x in texfiles]
109+
elif cmdargs.globfile != '':
110+
texfiles = glob.glob(cmdargs.globfile)
111+
else:
112+
if not suppressconsole:
113+
print("Warning, one of --file, --datafile, or --globfile is expected. Checking tex files in current directory")
114+
texfiles = glob.glob('*.tex')
115+
116+
if not suppressconsole:
117+
print("Files to check:")
118+
for file in texfiles:
119+
print(file)
120+
outdir = cmdargs.outdir
121+
outname = cmdargs.outname
122+
123+
firemodels = os.path.join(os.path.dirname(__file__),'..','..','..')
124+
125+
# This can be called if the white list is being edited and you want sort it
126+
# sortWhitelist(firemodels)
58127

59128
outtxt = '\n'
60129
for i in range(0, len(texfiles)):
@@ -83,10 +152,23 @@ def check_disallowed_commands(txt, file):
83152

84153
# Check disallowed commands
85154
outtxt = outtxt + check_disallowed_commands(txt, file)
155+
156+
# Check spelling
157+
txt = checkSpelling(file, firemodels)
158+
159+
if len(txt) > 0:
160+
txt_list = list(set(txt.split('\n')))
161+
txt_list.sort()
162+
#while '\n\n' in txt:
163+
# txt = txt.replace('\n\n','\n')
164+
#outtxt = outtxt + '\n\nMisspelt Words in %s:\n'%(file) + '\n'.join(txt_list) + '\n\n'
165+
for j in range(0, len(txt_list)):
166+
outtxt = outtxt + '\n\nMisspelt Words in %s: %s\n'%(file,txt_list[j])
86167

87-
if len(outtxt) > 1:
168+
if len(outtxt) > 1 and not suppressconsole:
88169
print("Warnings identified in the manual check:")
89170
print(outtxt)
90171

91-
with open('check_output.txt', 'w') as f:
172+
if outdir != '': outname = outdir + os.sep + outname
173+
with open(outname, 'w') as f:
92174
f.write(outtxt)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/bash
2+
cd ../smokeview
23
grep '#ifdef' *.c *.cpp *.h ../shared/*.c ../shared/*.cpp ../shared/*.h | awk '{print $2}' | sort -u

Source/scripts/LINECOUNT.bat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@echo off
2+
set curdir=%CD%
3+
cd ..\smokeview
4+
cat *.c *.cpp *.h ..\shared\*.h ..\shared\*.c | wc -l
5+
cd %curdir%

Source/scripts/LINECOUNT.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
cd ../smokeview
3+
cat *.c *.cpp *.h ../shared/*.h ../shared/*.c | wc -l
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
@echo off
2+
set curdir=%CD%
3+
cd ..\smokeview
24
cat *.c *.cpp *.h ..\shared\*.c ..\shared\*.h ..\background\*.c ..\background\*.h ..\smokediff\*.h ..\smokediff\*.c ..\smokezip\*.c ..\smokezip\*.h ..\wind2fds\*.c ..\wind2fds\*.h | wc -l
5+
cd %curdir%

Source/scripts/LINECOUNT_ALL.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
cd ../smokeview
3+
cat *.c *.cpp *.h ../shared/*.c ../shared/*.h ../background/*.c ../background/*.h ../smokediff/*.h ../smokediff/*.c ../smokezip/*.c ../smokezip/*.h ../wind2fds/*.c ../wind2fds/*.h| wc -l

Source/smokeview/make_po_template.sh renamed to Source/scripts/make_po_template.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
MAKEPO=../../makepo/intel_linux_64/makepo_linux_64
44
#cat *.c *.cpp | $MAKEPO | sort -u | $MAKEPO -a > smokeview_template.po
5+
cd ../smokeview
56
cat *.c *.cpp | $MAKEPO | sort -u > smokeview_template.po

Source/smokeview/LINECOUNT.bat

Lines changed: 0 additions & 2 deletions
This file was deleted.

Source/smokeview/LINECOUNT.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

Source/smokeview/LINECOUNT_ALL.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)