"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file ".docker/webservice.py" between
OCRmyPDF-8.0.1.tar.gz and OCRmyPDF-8.1.0.tar.gz

About: OCRmyPDF adds an OCR text layer to scanned PDF files, allowing them to be searched.

webservice.py  (OCRmyPDF-8.0.1):webservice.py  (OCRmyPDF-8.1.0)
skipping to change at line 35 skipping to change at line 35
from flask import Flask, Response, flash, request, redirect, url_for, abort, sen d_from_directory from flask import Flask, Response, flash, request, redirect, url_for, abort, sen d_from_directory
from subprocess import run, PIPE from subprocess import run, PIPE
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
import os import os
import shlex import shlex
app = Flask(__name__) app = Flask(__name__)
app.secret_key = "secret" app.secret_key = "secret"
app.config['MAX_CONTENT_LENGTH'] = 50_000_000
app.config.from_envvar("OCRMYPDF_WEBSERVICE_SETTINGS", silent=True)
uploaddir = TemporaryDirectory(prefix="ocrmypdf-upload")
downloaddir = TemporaryDirectory(prefix="ocrmypdf-download")
app.config["UPLOAD_FOLDER"] = uploaddir
ALLOWED_EXTENSIONS = set(["pdf"]) ALLOWED_EXTENSIONS = set(["pdf"])
def allowed_file(filename): def allowed_file(filename):
return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXT ENSIONS return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXT ENSIONS
def do_ocrmypdf(file): def do_ocrmypdf(file):
uploaddir = TemporaryDirectory(prefix="ocrmypdf-upload")
downloaddir = TemporaryDirectory(prefix="ocrmypdf-download")
filename = secure_filename(file.filename) filename = secure_filename(file.filename)
up_file = os.path.join(uploaddir.name, filename) up_file = os.path.join(uploaddir.name, filename)
file.save(up_file) file.save(up_file)
down_file = os.path.join(downloaddir.name, filename) down_file = os.path.join(downloaddir.name, filename)
cmd_args = [arg for arg in shlex.split(request.form["params"])] cmd_args = [arg for arg in shlex.split(request.form["params"])]
if "--sidecar" in cmd_args: if "--sidecar" in cmd_args:
return Response("--sidecar not supported", 501, mimetype='text/plain') return Response("--sidecar not supported", 501, mimetype='text/plain')
ocrmypdf_args = ["ocrmypdf", *cmd_args, up_file, down_file] ocrmypdf_args = ["ocrmypdf", *cmd_args, up_file, down_file]
proc = run(ocrmypdf_args, stdout=PIPE, stderr=PIPE, encoding="utf-8") proc = run(ocrmypdf_args, stdout=PIPE, stderr=PIPE, encoding="utf-8")
if proc.returncode != 0: if proc.returncode != 0:
stderr = proc.stderr stderr = proc.stderr
 End of changes. 4 change blocks. 
4 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)