Generalize running scripts
This commit is contained in:
parent
9358971583
commit
0cfd95ad59
|
@ -4,7 +4,12 @@
|
||||||
default: python
|
default: python
|
||||||
pdflatex main.tex
|
pdflatex main.tex
|
||||||
|
|
||||||
|
SRC_DIR := $(shell find graphics/src -type f -printf "%f\n" -name *.txt | cut -d '.' -f1)
|
||||||
|
|
||||||
python:
|
python:
|
||||||
python python/Hasse.py graphics/src/example1.txt graphics/example1.tex
|
@for f in $(SRC_DIR); \
|
||||||
python python/FSA.py graphics/src/example2.txt graphics/example2.tex
|
do \
|
||||||
python python/Truthtable.py graphics/src/example3.txt graphics/example3.tex
|
echo -e "\033[33mCOMPILING $$f.tex\033[0m"; \
|
||||||
|
python ../exam_template/python/run.py graphics/src/$$f.txt graphics/$$f.tex; \
|
||||||
|
echo ""; \
|
||||||
|
done
|
|
@ -62,6 +62,9 @@ def generate_latex(inputLines):
|
||||||
|
|
||||||
return '\n'.join(output)
|
return '\n'.join(output)
|
||||||
|
|
||||||
|
def processFileContent(raw, template):
|
||||||
|
content = generate_latex(raw)
|
||||||
|
return template.replace('%CONTENT', content)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
filename = argv[1]
|
filename = argv[1]
|
||||||
|
|
|
@ -65,6 +65,11 @@ def latex_hasse(hasse):
|
||||||
|
|
||||||
return '\n'.join(output)
|
return '\n'.join(output)
|
||||||
|
|
||||||
|
def processFileContent(raw, template):
|
||||||
|
rels = getRels(raw)
|
||||||
|
content = latex_hasse(hasse_diagram(rels))
|
||||||
|
return template.replace("%CONTENT", content)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
filename = argv[1]
|
filename = argv[1]
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
try:
|
||||||
|
from tabulate import tabulate
|
||||||
|
except:
|
||||||
|
print('Couldn\'t find tabulate. Do you have it installed?')
|
||||||
|
|
||||||
|
|
||||||
def parseExpressionList(inputData):
|
def parseExpressionList(inputData):
|
||||||
return [e.strip() for e in inputData.split(',')]
|
return [e.strip() for e in inputData.split(',')]
|
||||||
|
@ -77,12 +82,27 @@ def latexify(exps, truthtable):
|
||||||
""".format(
|
""".format(
|
||||||
'|'.join('e' if e else 'c' for e,_ in latex_expressions),
|
'|'.join('e' if e else 'c' for e,_ in latex_expressions),
|
||||||
' & '.join(f'${exp}$' for _,exp in latex_expressions),
|
' & '.join(f'${exp}$' for _,exp in latex_expressions),
|
||||||
'\n'.join(' ' + ' & '.join('\\T' if b else '\\F' for b in line) for line in truthtable)
|
'\n'.join(' ' + ' & '.join('\\T' if b else '\\F' for b in line) + ' \\\\' for line in truthtable)
|
||||||
)
|
)
|
||||||
|
|
||||||
def printTruthtable(exps, truthtable):
|
def printTruthtable(exps, truthtable):
|
||||||
stringTable = [ ['\033[32mT\033[0m ' if b else '\033[31mF\033[0m' for b in line] for line in truthtable]
|
stringTable = [ ['\033[32mT\033[0m ' if b else '\033[31mF\033[0m' for b in line] for line in truthtable]
|
||||||
print(tabulate(stringTable, headers=exps))
|
try:
|
||||||
|
print(tabulate(stringTable, headers=exps))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def processFileContent(raw, template):
|
||||||
|
exps = parseExpressionList(raw)
|
||||||
|
truthtable = generateTruthTable(exps)
|
||||||
|
|
||||||
|
printTruthtable(exps, generateTruthTable(exps))
|
||||||
|
|
||||||
|
content = latexify(exps, truthtable)
|
||||||
|
return template.replace('%CONTENT', content)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
filename = argv[1]
|
filename = argv[1]
|
||||||
|
@ -91,11 +111,11 @@ if __name__ == '__main__':
|
||||||
exps = parseExpressionList(file.read())
|
exps = parseExpressionList(file.read())
|
||||||
truthtable = generateTruthTable(exps)
|
truthtable = generateTruthTable(exps)
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
printTruthtable(exps, generateTruthTable(exps))
|
printTruthtable(exps, generateTruthTable(exps))
|
||||||
except:
|
# except e:
|
||||||
print('Couldn\'t find tabulate. Do you have it installed?')
|
# print(e)
|
||||||
|
|
||||||
content = latexify(exps, truthtable)
|
content = latexify(exps, truthtable)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
from sys import argv
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import FSA
|
||||||
|
import Graph
|
||||||
|
import Hasse
|
||||||
|
import Truthtable
|
||||||
|
|
||||||
|
def fetchContentType(content):
|
||||||
|
new_content = content.split('\n')
|
||||||
|
contentType = new_content.pop(0)[2:]
|
||||||
|
return (contentType, '\n'.join(new_content))
|
||||||
|
|
||||||
|
def processContent(content):
|
||||||
|
contentType, content = fetchContentType(content)
|
||||||
|
with open(str(Path(__file__).parent.absolute()) + f'/tex_templates/{contentType}.tex') as template:
|
||||||
|
if contentType == 'Hasse':
|
||||||
|
result = Hasse.processFileContent(content, template.read())
|
||||||
|
elif contentType == 'FSA':
|
||||||
|
result = FSA.processFileContent(content, template.read())
|
||||||
|
elif contentType == 'Truthtable':
|
||||||
|
result = Truthtable.processFileContent(content, template.read())
|
||||||
|
else:
|
||||||
|
print('DIDN\'T RECOGNIZE FILE TYPE')
|
||||||
|
exit(1)
|
||||||
|
return result
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
filename = argv[1]
|
||||||
|
|
||||||
|
with open(filename) as file:
|
||||||
|
content = processContent(file.read())
|
||||||
|
|
||||||
|
with open(argv[2], 'w') as destination_file:
|
||||||
|
destination_file.write(content)
|
Loading…
Reference in New Issue