Print date/time and if build was successful

This commit is contained in:
Sage Vaillancourt 2021-07-28 18:42:02 -04:00
parent e200399366
commit 8892135160
1 changed files with 14 additions and 4 deletions

View File

@ -9,9 +9,13 @@ from flask import send_from_directory
def get_unique():
import uuid
unique = str(uuid.uuid1().hex)
print("Unique ID: " + unique)
return unique
def get_datetime():
from datetime import datetime
now = datetime.now()
return now.strftime("%Y-%m-%d %H:%M:%S")
@dataclass
class CLData():
username: str
@ -49,10 +53,15 @@ class CLData():
output_arg="-jobname=outputs/" + unique_id + " " + unique_file
com = "pdflatex -halt-on-error " + output_arg
print("COM: '" + com + "'")
result = subprocess.run(['bash', '-c', com], stdout=subprocess.PIPE, text=True)
build_text = "[" + get_datetime() + "] Building for " + unique_id + " "
result = subprocess.run(
['bash', '-c', com],
stdout=subprocess.PIPE,
text=True
)
if result.returncode == 0:
print(build_text + "[SUCCESS]")
threading.Timer(60 * 30, cleanup, [output_dir + unique_id]).start()
return (send_from_directory(
@ -62,11 +71,12 @@ class CLData():
as_attachment=True
), None)
else:
print(build_text + "[FAIL]")
# Collect output but delete boilerplate text
errors = result.stdout.split("\n")
del errors[:13]
del errors[-2:]
return (None, errors)
def cleanup(unique):
print(unique)
subprocess.run(['bash', '-c', "rm " + unique + ".*"])