From 15319b1c25d83b494f46ae069fd26ae71a7343ed Mon Sep 17 00:00:00 2001 From: Joseph Weston <joseph@weston.cloud> Date: Tue, 13 Mar 2018 18:39:25 +0100 Subject: [PATCH] remove reference to app context from 'process_pdf' This makes 'process_pdf' easier to use from a Python shell, which helps with debugging --- zesje/helpers/pdf_helper.py | 7 +++---- zesje/resources/pdfs.py | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zesje/helpers/pdf_helper.py b/zesje/helpers/pdf_helper.py index 24cae30ed..fb2aacb97 100644 --- a/zesje/helpers/pdf_helper.py +++ b/zesje/helpers/pdf_helper.py @@ -13,7 +13,6 @@ import pandas import cv2 import zbar -from flask import current_app as app from pony import orm from . import yaml_helper @@ -25,7 +24,7 @@ ExamMetadata = namedtuple('ExamMetadata', ['version', 'exam_name', 'qr_coords', 'widget_data']) -def process_pdf(pdf_id): +def process_pdf(pdf_id, data_directory): """Process a PDF, recording progress to a database This *must* be called from a subprocess of the @@ -36,9 +35,9 @@ def process_pdf(pdf_id): ---------- pdf_id : int The ID in the database of the PDF to process + data_directory : str + The absolute path to the data directory on disk """ - data_directory = app.config['DATA_DIRECTORY'] - report_error = functools.partial(write_pdf_status, pdf_id, 'error') report_progress = functools.partial(write_pdf_status, pdf_id, 'processing') report_success = functools.partial(write_pdf_status, pdf_id, 'success') diff --git a/zesje/resources/pdfs.py b/zesje/resources/pdfs.py index b8275710d..73ca4c114 100644 --- a/zesje/resources/pdfs.py +++ b/zesje/resources/pdfs.py @@ -76,7 +76,8 @@ class Pdfs(Resource): # TODO: save these into a process-local datastructure, or save # it into the DB as well so that we can cull 'processing' tasks # that are actually dead. - Process(target=pdf_helper.process_pdf, args=(pdf.id,)).start() + args = (pdf.id, app.config['DATA_DIRECTORY']) + Process(target=pdf_helper.process_pdf, args=args).start() return { 'id': pdf.id, -- GitLab