ability to add custom work dir

This commit is contained in:
joachimschmidt557 2019-08-23 18:52:40 +02:00
parent 4f3780e167
commit bd18a473d4

View file

@ -13,6 +13,7 @@ when isMainModule:
help("Compiles etherpad pads to pdf")
option("-p", "--port", help="Port for the server", default="8080")
option("-a", "--etherpad-address", help="The address of the etherpad", default="http://localhost:9001")
option("-d", "--working-directory", help="The directory to use for saving and compiling", default=".")
let opts = p.parse()
@ -21,13 +22,17 @@ when isMainModule:
let
pad = @"pad"
etherpadUrl = opts.etherpadAddress
workingDir = opts.workingDirectory
content = getContent(pad, etherpadUrl)
writeFile(pad & ".tex", content)
texFile = workingDir / pad & ".tex"
pdfFile = workingDir / pad & ".pdf"
let (output, exitCode) = execCmdEx(quoteShellCommand(["pdflatex", "-halt-on-error", pad & ".tex"]))
writeFile(texFile, content)
let (output, exitCode) = execCmdEx(quoteShellCommand(["pdflatex", "-halt-on-error", texFile]))
if exitCode == 0:
resp(Http200, readFile(pad & ".pdf"), contentType = "application/pdf")
resp(Http200, readFile(pdfFile), contentType = "application/pdf")
else:
resp output