Skip to content
Snippets Groups Projects
Commit 2138ec63 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Fine tuning of debug logs

parent 298911b7
No related branches found
No related tags found
No related merge requests found
import os import os
import subprocess import subprocess
from debug.models import register_log_with_filename
from schoolapps.settings import BASE_DIR from schoolapps.settings import BASE_DIR
...@@ -21,9 +22,10 @@ def convert_markdown_2_latex(s): ...@@ -21,9 +22,10 @@ def convert_markdown_2_latex(s):
os.path.join(BASE_DIR, "latex", "m2l.md")) os.path.join(BASE_DIR, "latex", "m2l.md"))
process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE) process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0] output = process.communicate()[0]
print("[MD TO LATEX]", output) del output
print("[RETURN CODE]", process.returncode)
# register_log_with_filename("m2l", "m2l", "m2l.log", process.returncode) # Register log file in debugging tool
register_log_with_filename("m2l", "m2l", "m2l.log", process.returncode)
# Read converted latex from file # Read converted latex from file
tex_file = open(os.path.join(BASE_DIR, "latex", "m2l.tex"), "r", encoding="utf8") tex_file = open(os.path.join(BASE_DIR, "latex", "m2l.tex"), "r", encoding="utf8")
......
...@@ -23,9 +23,10 @@ def generate_pdf(tex, filename): ...@@ -23,9 +23,10 @@ def generate_pdf(tex, filename):
filename)) filename))
process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE) process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0] 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) 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): def generate_class_tex(subs, date, header_info, hints=None):
......
import datetime import datetime
import os import os
import traceback
from PyPDF2 import PdfFileMerger from PyPDF2 import PdfFileMerger
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
...@@ -7,6 +8,7 @@ from django.http import Http404, FileResponse ...@@ -7,6 +8,7 @@ from django.http import Http404, FileResponse
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.utils import timezone 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 schoolapps.settings import SHORT_WEEK_DAYS, LONG_WEEK_DAYS
from timetable.filters import HintFilter from timetable.filters import HintFilter
from timetable.forms import HintForm from timetable.forms import HintForm
...@@ -299,16 +301,23 @@ def sub_pdf(request): ...@@ -299,16 +301,23 @@ def sub_pdf(request):
generate_pdf(tex, "class{}".format(i)) generate_pdf(tex, "class{}".format(i))
# Merge PDFs # Merge PDFs
merger = PdfFileMerger() try:
class0 = open(os.path.join(BASE_DIR, "latex", "class0.pdf"), "rb") merger = PdfFileMerger()
class1 = open(os.path.join(BASE_DIR, "latex", "class1.pdf"), "rb") class0 = open(os.path.join(BASE_DIR, "latex", "class0.pdf"), "rb")
merger.append(fileobj=class0) class1 = open(os.path.join(BASE_DIR, "latex", "class1.pdf"), "rb")
merger.append(fileobj=class1) 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") # Write merged PDF to class.pdf
merger.write(output) output = open(os.path.join(BASE_DIR, "latex", "class.pdf"), "wb")
output.close() 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 # Read and response PDF
file = open(os.path.join(BASE_DIR, "latex", "class.pdf"), "rb") file = open(os.path.join(BASE_DIR, "latex", "class.pdf"), "rb")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment