From 284d8cdd7378647518d2f2058335316b22bb0bd1 Mon Sep 17 00:00:00 2001 From: Lukas Tietze Date: Tue, 14 Jul 2020 15:57:59 +0200 Subject: [PATCH] Build-Skripte --- .gitignore | 1 + doc/common/build.py | 71 ++--------------------------------- doc/common/commonFunctions.py | 65 ++++++++++++++++++++++++++++++++ doc/common/spell-check.py | 25 ++++++++++++ 4 files changed, 95 insertions(+), 67 deletions(-) create mode 100644 doc/common/commonFunctions.py create mode 100644 doc/common/spell-check.py diff --git a/.gitignore b/.gitignore index ad29232..6842926 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ !.vscode/tasks.json bin/ obj/ +__pycache__ *.vcxproj.user *.spv diff --git a/doc/common/build.py b/doc/common/build.py index 1ce0c08..bf53b61 100644 --- a/doc/common/build.py +++ b/doc/common/build.py @@ -1,69 +1,8 @@ +import commonFunctions + import os import sys import shutil -from shutil import get_terminal_size - -ColorBlack = "\u001b[30m" -ColorRed = "\u001b[31m" -ColorGreen = "\u001b[32m" -ColorYellow = "\u001b[33m" -ColorBlue = "\u001b[34m" -ColorMagenta = "\u001b[35m" -ColorCyan = "\u001b[36m" -ColorWhite = "\u001b[37m" -ColorReset = "\u001b[0m" - - -def printInfo(message): - print(ColorBlue, message, ColorReset) - pass - - -def printWarning(message): - print(ColorYellow, message, ColorReset) - pass - - -def printError(message): - print(ColorRed, message, ColorReset) - pass - - -def printStatus(message): - print(ColorCyan, message, ColorReset) - pass - - -def printSuccess(message): - print(ColorGreen, message, ColorReset) - pass - - -def beginPart(name): - w = int(get_terminal_size([50, 1]).columns * 0.75) - namePadding = int((w - len(name)) / 2) - - printInfo("-" * w) - printInfo((" " * namePadding) + name + (" " * namePadding)) - printInfo("-" * w) - pass - - -def command(cmd) -> int: - printStatus(cmd) - - res = os.system(cmd) - - str = f"Done, action result: {res}" - - if(res == 0): - printSuccess(str) - else: - printWarning(str) - - return res - pass - argc = len(sys.argv) @@ -91,18 +30,16 @@ if good == 0: exit() cmdLatex = "texfot -tee=\".\\tex.fot\" pdflatex -output-format=pdf -interaction=nonstopmode -file-line-error document.tex" -cmdGlossaries = "makeglossaries document" -cmdBib = "bibtex document" beginPart("Latex first run") success = command(cmdLatex) if success == 0: beginPart("Bibtex") - command(cmdBib) + command("bibtex document") beginPart("Makeglossaries") - command(cmdGlossaries) + command("makeglossaries document") beginPart("Latex second run") success = command(cmdLatex) diff --git a/doc/common/commonFunctions.py b/doc/common/commonFunctions.py new file mode 100644 index 0000000..e8cc77d --- /dev/null +++ b/doc/common/commonFunctions.py @@ -0,0 +1,65 @@ +import os +import subprocess +import sys +from shutil import get_terminal_size + +ColorBlack = "\u001b[30m" +ColorRed = "\u001b[31m" +ColorGreen = "\u001b[32m" +ColorYellow = "\u001b[33m" +ColorBlue = "\u001b[34m" +ColorMagenta = "\u001b[35m" +ColorCyan = "\u001b[36m" +ColorWhite = "\u001b[37m" +ColorReset = "\u001b[0m" + + +def printInfo(message): + print(ColorBlue, message, ColorReset) + pass + + +def printWarning(message): + print(ColorYellow, message, ColorReset) + pass + + +def printError(message): + print(ColorRed, message, ColorReset) + pass + + +def printStatus(message): + print(ColorCyan, message, ColorReset) + pass + + +def printSuccess(message): + print(ColorGreen, message, ColorReset) + pass + + +def beginPart(name): + w = int(get_terminal_size([50, 1]).columns * 0.75) + namePadding = int((w - len(name)) / 2) + + printInfo("-" * w) + printInfo((" " * namePadding) + name + (" " * namePadding)) + printInfo("-" * w) + pass + + +def command(cmd, input=sys.stdin) -> int: + printStatus(cmd) + + res = subprocess.run(cmd, stdin=input) + + str = f"Done, action result: {res.returncode}" + + if(res.returncode == 0): + printSuccess(str) + else: + printWarning(str) + + return res.returncode + pass diff --git a/doc/common/spell-check.py b/doc/common/spell-check.py new file mode 100644 index 0000000..68a0b05 --- /dev/null +++ b/doc/common/spell-check.py @@ -0,0 +1,25 @@ +from commonFunctions import * + +import os +import io +import sys +import subprocess + +beginPart("Spell Checking") + +dryRun = "-dry" in sys.argv + +for root, subdirs, files in os.walk("."): + res = [] + + for file in files: + if os.path.splitext(file)[1] == ".tex": + filePath = os.path.join(root, file) + + if file in sys.argv or filePath in sys.argv: + printWarning("Ignoring file " + filePath) + else: + printInfo("Checking " + filePath) + if not dryRun: + res.append(subprocess.run("aspell --lang=De-de --mode=tex -a", + stdin=io.open(filePath), stdout=io.open("res", "w"))) -- GitLab