From e200399366321a0653409a0b3f466ab4d7081df1 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Tue, 27 Jul 2021 23:39:30 -0400 Subject: [PATCH] Display latex errors as applicable --- flaskr/templates/writing.html | 7 +++++++ latty.py | 19 ++++++++++++------- writing.py | 5 +++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/flaskr/templates/writing.html b/flaskr/templates/writing.html index aab92e9..4b79068 100644 --- a/flaskr/templates/writing.html +++ b/flaskr/templates/writing.html @@ -61,6 +61,13 @@ {{ render_field(form.body, 'class=bigtext') }} {{ render_field(form.closingtext) }} + {% if err %} +

+ {% for error in err %} + {{ error }}
+ {% endfor %} +

+ {% endif %}

diff --git a/latty.py b/latty.py index 13f569c..a7b6d46 100644 --- a/latty.py +++ b/latty.py @@ -47,20 +47,25 @@ class CLData(): f.write(open(proj_dir + "/writing_templates/base.tex", "r").read()) f.close() - com = "pdflatex -halt-on-error -jobname=outputs/" + unique_id + " " + unique_file + output_arg="-jobname=outputs/" + unique_id + " " + unique_file + com = "pdflatex -halt-on-error " + output_arg print("COM: '" + com + "'") - try: - subprocess.check_call(['bash', '-c', com]) + result = subprocess.run(['bash', '-c', com], stdout=subprocess.PIPE, text=True) + + if result.returncode == 0: threading.Timer(60 * 30, cleanup, [output_dir + unique_id]).start() - return send_from_directory( + return (send_from_directory( output_dir, unique_id + ".pdf", attachment_filename=self.username.replace(" ", "") + "_CoverLetter.pdf", as_attachment=True - ) - except subprocess.CalledProcessError: - return None + ), None) + else: + errors = result.stdout.split("\n") + del errors[:13] + del errors[-2:] + return (None, errors) def cleanup(unique): print(unique) diff --git a/writing.py b/writing.py index 728a320..ac1fd44 100644 --- a/writing.py +++ b/writing.py @@ -61,11 +61,12 @@ def index(): body=form.body.data, ) - resp = data.generate_pdf() + (resp, err) = data.generate_pdf() # Save entered data as cookies on user's machine - if not resp: + if err: resp = make_response(render_template('writing.html', form=form, + err=err, )) for pair in data.get_pairs(): resp.set_cookie(pair[0], urllib.parse.quote(pair[1]))