Skip to content

Commit

Permalink
[WIP] make ProcessorTasks aware of the ocrd-tool.json of the processo…
Browse files Browse the repository at this point in the history
…r they are wrapping

c.f. OCR-D#295 OCR-D#296
  • Loading branch information
kba committed Sep 11, 2019
1 parent 5eef289 commit 6b8af8b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ocrd/ocrd/task_sequence.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import json
from shlex import split as shlex_split
from distutils.spawn import find_executable as which # pylint: disable=import-error,no-name-in-module
from subprocess import check_output

from ocrd_utils import getLogger
from ocrd.processor.base import run_cli
Expand Down Expand Up @@ -36,8 +38,17 @@ def __init__(self, executable, input_file_grps, output_file_grps, parameter_path
self.input_file_grps = input_file_grps
self.output_file_grps = output_file_grps
self.parameter_path = parameter_path
self._ocrd_tool_json = None

@property
def ocrd_tool_json(self):
if self._ocrd_tool_json:
return self._ocrd_tool_json
self._ocrd_tool_json = json.loads(check_output([self.executable, '--dump-json']))
return self._ocrd_tool_json

def validate(self):
# TODO allow raw JSON
if self.parameter_path and not os.access(self.parameter_path, os.R_OK):
raise Exception("Parameter file not readable: %s" % self.parameter_path)
if not self.input_file_grps:
Expand Down Expand Up @@ -103,5 +114,3 @@ def run_tasks(mets, log_level, page_id, task_strs):
for output_file_grp in task.output_file_grps:
if not output_file_grp in workspace.mets.file_groups:
raise Exception("Invalid state: expected output file group not in mets: %s" % output_file_grp)


0 comments on commit 6b8af8b

Please sign in to comment.