Rename PDFContext->PdfContext
This commit is contained in:
@@ -24,7 +24,7 @@ from functools import partial
|
|||||||
from ocrmypdf._plugin_manager import get_plugin_manager
|
from ocrmypdf._plugin_manager import get_plugin_manager
|
||||||
|
|
||||||
|
|
||||||
class PDFContext:
|
class PdfContext:
|
||||||
"""Holds our context for a particular run of the pipeline"""
|
"""Holds our context for a particular run of the pipeline"""
|
||||||
|
|
||||||
def __init__(self, options, work_folder, origin, pdfinfo, plugin_manager):
|
def __init__(self, options, work_folder, origin, pdfinfo, plugin_manager):
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import pluggy
|
|||||||
from ocrmypdf import pluginspec
|
from ocrmypdf import pluginspec
|
||||||
from ocrmypdf._concurrent import exec_progress_pool
|
from ocrmypdf._concurrent import exec_progress_pool
|
||||||
from ocrmypdf._graft import OcrGrafter
|
from ocrmypdf._graft import OcrGrafter
|
||||||
from ocrmypdf._jobcontext import PDFContext, cleanup_working_files
|
from ocrmypdf._jobcontext import PdfContext, cleanup_working_files
|
||||||
from ocrmypdf._logging import PageNumberFilter
|
from ocrmypdf._logging import PageNumberFilter
|
||||||
from ocrmypdf._pipeline import (
|
from ocrmypdf._pipeline import (
|
||||||
convert_to_pdfa,
|
convert_to_pdfa,
|
||||||
@@ -330,7 +330,7 @@ def run_pipeline(options, *, plugin_manager, api=False):
|
|||||||
max_workers=options.jobs if not options.use_threads else 1, # To help debug
|
max_workers=options.jobs if not options.use_threads else 1, # To help debug
|
||||||
)
|
)
|
||||||
|
|
||||||
context = PDFContext(options, work_folder, origin_pdf, pdfinfo, plugin_manager)
|
context = PdfContext(options, work_folder, origin_pdf, pdfinfo, plugin_manager)
|
||||||
|
|
||||||
# Validate options are okay for this pdf
|
# Validate options are okay for this pdf
|
||||||
validate_pdfinfo_options(context)
|
validate_pdfinfo_options(context)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from PIL import Image
|
|||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from . import leptonica
|
from . import leptonica
|
||||||
from ._jobcontext import PDFContext
|
from ._jobcontext import PdfContext
|
||||||
from .exceptions import OutputFileAccessError
|
from .exceptions import OutputFileAccessError
|
||||||
from .exec import jbig2enc, pngquant
|
from .exec import jbig2enc, pngquant
|
||||||
from .helpers import safe_symlink
|
from .helpers import safe_symlink
|
||||||
@@ -582,7 +582,7 @@ def main(infile, outfile, level, jobs=1):
|
|||||||
)
|
)
|
||||||
|
|
||||||
with TemporaryDirectory() as td:
|
with TemporaryDirectory() as td:
|
||||||
context = PDFContext(options, td, infile, None, None)
|
context = PdfContext(options, td, infile, None, None)
|
||||||
tmpout = Path(td) / 'out.pdf'
|
tmpout = Path(td) / 'out.pdf'
|
||||||
optimize(
|
optimize(
|
||||||
infile,
|
infile,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import pikepdf
|
|||||||
import pytest
|
import pytest
|
||||||
from pikepdf.models.metadata import decode_pdf_date
|
from pikepdf.models.metadata import decode_pdf_date
|
||||||
|
|
||||||
from ocrmypdf._jobcontext import PDFContext
|
from ocrmypdf._jobcontext import PdfContext
|
||||||
from ocrmypdf._pipeline import convert_to_pdfa
|
from ocrmypdf._pipeline import convert_to_pdfa
|
||||||
from ocrmypdf.cli import get_parser
|
from ocrmypdf.cli import get_parser
|
||||||
from ocrmypdf.exceptions import ExitCode
|
from ocrmypdf.exceptions import ExitCode
|
||||||
@@ -298,7 +298,7 @@ def test_metadata_fixup_warning(resources, outdir, caplog):
|
|||||||
|
|
||||||
copyfile(resources / 'graph.pdf', outdir / 'graph.pdf')
|
copyfile(resources / 'graph.pdf', outdir / 'graph.pdf')
|
||||||
|
|
||||||
context = PDFContext(options, outdir, outdir / 'graph.pdf', None, None)
|
context = PdfContext(options, outdir, outdir / 'graph.pdf', None, None)
|
||||||
metadata_fixup(working_file=outdir / 'graph.pdf', context=context)
|
metadata_fixup(working_file=outdir / 'graph.pdf', context=context)
|
||||||
for record in caplog.records:
|
for record in caplog.records:
|
||||||
assert record.levelname != 'WARNING'
|
assert record.levelname != 'WARNING'
|
||||||
@@ -309,7 +309,7 @@ def test_metadata_fixup_warning(resources, outdir, caplog):
|
|||||||
meta['prism2:publicationName'] = 'OCRmyPDF Test'
|
meta['prism2:publicationName'] = 'OCRmyPDF Test'
|
||||||
graph.save(outdir / 'graph_mod.pdf')
|
graph.save(outdir / 'graph_mod.pdf')
|
||||||
|
|
||||||
context = PDFContext(options, outdir, outdir / 'graph_mod.pdf', None, None)
|
context = PdfContext(options, outdir, outdir / 'graph_mod.pdf', None, None)
|
||||||
metadata_fixup(working_file=outdir / 'graph.pdf', context=context)
|
metadata_fixup(working_file=outdir / 'graph.pdf', context=context)
|
||||||
assert any(record.levelname == 'WARNING' for record in caplog.records)
|
assert any(record.levelname == 'WARNING' for record in caplog.records)
|
||||||
|
|
||||||
@@ -329,7 +329,7 @@ def test_prevent_gs_invalid_xml(resources, outdir):
|
|||||||
args=['-j', '1', '--output-type', 'pdfa-2', 'a.pdf', 'b.pdf']
|
args=['-j', '1', '--output-type', 'pdfa-2', 'a.pdf', 'b.pdf']
|
||||||
)
|
)
|
||||||
pdfinfo = PdfInfo(outdir / 'layers.rendered.pdf')
|
pdfinfo = PdfInfo(outdir / 'layers.rendered.pdf')
|
||||||
context = PDFContext(options, outdir, outdir / 'layers.rendered.pdf', pdfinfo, None)
|
context = PdfContext(options, outdir, outdir / 'layers.rendered.pdf', pdfinfo, None)
|
||||||
|
|
||||||
convert_to_pdfa(
|
convert_to_pdfa(
|
||||||
str(outdir / 'layers.rendered.pdf'), str(outdir / 'pdfa.ps'), context
|
str(outdir / 'layers.rendered.pdf'), str(outdir / 'pdfa.ps'), context
|
||||||
@@ -360,7 +360,7 @@ def test_malformed_docinfo(caplog, resources, outdir):
|
|||||||
args=['-j', '1', '--output-type', 'pdfa-2', 'a.pdf', 'b.pdf']
|
args=['-j', '1', '--output-type', 'pdfa-2', 'a.pdf', 'b.pdf']
|
||||||
)
|
)
|
||||||
pdfinfo = PdfInfo(outdir / 'layers.rendered.pdf')
|
pdfinfo = PdfInfo(outdir / 'layers.rendered.pdf')
|
||||||
context = PDFContext(options, outdir, outdir / 'layers.rendered.pdf', pdfinfo, None)
|
context = PdfContext(options, outdir, outdir / 'layers.rendered.pdf', pdfinfo, None)
|
||||||
|
|
||||||
convert_to_pdfa(
|
convert_to_pdfa(
|
||||||
str(outdir / 'layers.rendered.pdf'), str(outdir / 'pdfa.ps'), context
|
str(outdir / 'layers.rendered.pdf'), str(outdir / 'pdfa.ps'), context
|
||||||
|
|||||||
Reference in New Issue
Block a user