Fix exit code error on Ghostscript failure
This commit is contained in:
@@ -322,7 +322,7 @@ def post_process(
|
||||
return optimize_pdf(pdf_out, context, executor)
|
||||
|
||||
|
||||
def report_output_pdf(options, start_input_file, optimize_messages):
|
||||
def report_output_pdf(options, start_input_file, optimize_messages) -> ExitCode:
|
||||
if options.output_file == '-':
|
||||
log.info("Output sent to stdout")
|
||||
elif hasattr(options.output_file, 'writable') and options.output_file.writable():
|
||||
@@ -346,3 +346,4 @@ def report_output_pdf(options, start_input_file, optimize_messages):
|
||||
report_output_file_size(
|
||||
options, start_input_file, options.output_file, optimize_messages
|
||||
)
|
||||
return ExitCode.ok
|
||||
|
||||
@@ -35,6 +35,7 @@ from ocrmypdf._pipelines.common import (
|
||||
worker_init,
|
||||
)
|
||||
from ocrmypdf._plugin_manager import OcrmypdfPluginManager
|
||||
from ocrmypdf.exceptions import ExitCode
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -53,7 +54,7 @@ def exec_hocrtransform_sync(page_context: PageContext) -> HOCRResult:
|
||||
return hocr_result
|
||||
|
||||
|
||||
def exec_hocr_to_ocr_pdf(context: PdfContext, executor: Executor) -> None:
|
||||
def exec_hocr_to_ocr_pdf(context: PdfContext, executor: Executor) -> Sequence[str]:
|
||||
"""Execute the OCR pipeline concurrently and output hOCR."""
|
||||
# Run exec_page_sync on every page
|
||||
options = context.options
|
||||
@@ -110,7 +111,7 @@ def run_hocr_to_ocr_pdf_pipeline(
|
||||
options: argparse.Namespace,
|
||||
*,
|
||||
plugin_manager: OcrmypdfPluginManager | None,
|
||||
) -> None:
|
||||
) -> ExitCode:
|
||||
with setup_pipeline(
|
||||
options=options, plugin_manager=plugin_manager, api=True, work_folder=None
|
||||
) as (work_folder, executor, plugin_manager):
|
||||
@@ -133,4 +134,4 @@ def run_hocr_to_ocr_pdf_pipeline(
|
||||
validate_pdfinfo_options(context)
|
||||
optimize_messages = exec_hocr_to_ocr_pdf(context, executor)
|
||||
|
||||
report_output_pdf(options, origin_pdf, optimize_messages)
|
||||
return report_output_pdf(options, origin_pdf, optimize_messages)
|
||||
|
||||
@@ -215,7 +215,7 @@ def run_pipeline(
|
||||
# Execute the pipeline
|
||||
optimize_messages = exec_concurrent(context, executor)
|
||||
|
||||
report_output_pdf(options, start_input_file, optimize_messages)
|
||||
exitcode = report_output_pdf(options, start_input_file, optimize_messages)
|
||||
|
||||
except KeyboardInterrupt if not api else NeverRaise:
|
||||
if options.verbose >= 1:
|
||||
@@ -254,4 +254,4 @@ def run_pipeline(
|
||||
log.exception("An exception occurred while executing the pipeline")
|
||||
return ExitCode.other_error
|
||||
|
||||
return ExitCode.ok
|
||||
return exitcode
|
||||
|
||||
Reference in New Issue
Block a user