From 2138ec63b4cfb2d76a39252ad3421c6b83a36319 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Thu, 23 May 2019 17:04:54 +0200 Subject: [PATCH] Fine tuning of debug logs --- biscuit/apps/chronos/m2l.py | 8 +++++--- biscuit/apps/chronos/pdf.py | 3 ++- biscuit/apps/chronos/views.py | 29 +++++++++++++++++++---------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/biscuit/apps/chronos/m2l.py b/biscuit/apps/chronos/m2l.py index df99f3a3..99a76157 100644 --- a/biscuit/apps/chronos/m2l.py +++ b/biscuit/apps/chronos/m2l.py @@ -1,6 +1,7 @@ import os import subprocess +from debug.models import register_log_with_filename from schoolapps.settings import BASE_DIR @@ -21,9 +22,10 @@ def convert_markdown_2_latex(s): os.path.join(BASE_DIR, "latex", "m2l.md")) process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE) output = process.communicate()[0] - print("[MD TO LATEX]", output) - print("[RETURN CODE]", process.returncode) - # register_log_with_filename("m2l", "m2l", "m2l.log", process.returncode) + del output + + # Register log file in debugging tool + register_log_with_filename("m2l", "m2l", "m2l.log", process.returncode) # Read converted latex from file tex_file = open(os.path.join(BASE_DIR, "latex", "m2l.tex"), "r", encoding="utf8") diff --git a/biscuit/apps/chronos/pdf.py b/biscuit/apps/chronos/pdf.py index 64561c63..713437b6 100644 --- a/biscuit/apps/chronos/pdf.py +++ b/biscuit/apps/chronos/pdf.py @@ -23,9 +23,10 @@ def generate_pdf(tex, filename): filename)) process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE) output = process.communicate()[0] + del output + # Register log file in debugging tool register_log_with_filename("latex_{}".format(filename), "latex", "{}.log".format(filename), process.returncode) - print("[LATEX]", output) def generate_class_tex(subs, date, header_info, hints=None): diff --git a/biscuit/apps/chronos/views.py b/biscuit/apps/chronos/views.py index 17fe9fbe..312fc4cb 100755 --- a/biscuit/apps/chronos/views.py +++ b/biscuit/apps/chronos/views.py @@ -1,5 +1,6 @@ import datetime import os +import traceback from PyPDF2 import PdfFileMerger from django.contrib.auth.decorators import login_required, permission_required @@ -7,6 +8,7 @@ from django.http import Http404, FileResponse from django.shortcuts import render, redirect, get_object_or_404 from django.utils import timezone +from debug.models import register_traceback, register_return_0 from schoolapps.settings import SHORT_WEEK_DAYS, LONG_WEEK_DAYS from timetable.filters import HintFilter from timetable.forms import HintForm @@ -299,16 +301,23 @@ def sub_pdf(request): generate_pdf(tex, "class{}".format(i)) # Merge PDFs - merger = PdfFileMerger() - class0 = open(os.path.join(BASE_DIR, "latex", "class0.pdf"), "rb") - class1 = open(os.path.join(BASE_DIR, "latex", "class1.pdf"), "rb") - merger.append(fileobj=class0) - merger.append(fileobj=class1) - - # Write merged PDF to class.pdf - output = open(os.path.join(BASE_DIR, "latex", "class.pdf"), "wb") - merger.write(output) - output.close() + try: + merger = PdfFileMerger() + class0 = open(os.path.join(BASE_DIR, "latex", "class0.pdf"), "rb") + class1 = open(os.path.join(BASE_DIR, "latex", "class1.pdf"), "rb") + merger.append(fileobj=class0) + merger.append(fileobj=class1) + + # Write merged PDF to class.pdf + output = open(os.path.join(BASE_DIR, "latex", "class.pdf"), "wb") + merger.write(output) + output.close() + + # Register successful merge in debugging tool + register_return_0("merge_class", "pypdf2") + except Exception: + # Register exception in debugging tool + register_traceback("merge_class", "pypdf2") # Read and response PDF file = open(os.path.join(BASE_DIR, "latex", "class.pdf"), "rb") -- GitLab