From 85f9d3084205d2504e740f6757aa37ded6dd108d Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Fri, 19 Oct 2018 19:06:35 +0200 Subject: [PATCH] add agent in run_processor after process() and before save_mets(), #147 --- ocrd/processor/base.py | 16 ++++++++++++---- test/processor/test_processor.py | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ocrd/processor/base.py b/ocrd/processor/base.py index 0771951f2..4968efb0e 100644 --- a/ocrd/processor/base.py +++ b/ocrd/processor/base.py @@ -28,7 +28,7 @@ def run_processor( output_file_grp=None, parameter=None, working_dir=None, -): +): # pylint: disable=too-many-locals """ Create a workspace for mets_url and run processor through it @@ -59,10 +59,18 @@ def run_processor( output_file_grp=output_file_grp, parameter=parameter ) - log.debug("Processor instance %s", processor) - log.debug('%s', ocrd_tool) + # print(processor.version) + name = '%s v%s' % (ocrd_tool['executable'], processor.version) + otherrole = ocrd_tool['steps'][0] + log.debug("Processor instance %s (%s doing %s)", processor, name, otherrole) processor.process() - # workspace.add_agent( + workspace.mets.add_agent( + name=name, + _type='OTHER', + othertype='SOFTWARE', + role='OTHER', + otherrole=otherrole + ) workspace.save_mets() # TODO not used as of 0.8.2 diff --git a/test/processor/test_processor.py b/test/processor/test_processor.py index 9acc846ee..e2b4e16b8 100644 --- a/test/processor/test_processor.py +++ b/test/processor/test_processor.py @@ -1,17 +1,21 @@ from test.base import TestCase, assets, main # pylint: disable=import-error, no-name-in-module from ocrd.resolver import Resolver -from ocrd.processor.base import Processor +from ocrd.processor.base import Processor, run_processor + +DUMMY_TOOL = {'executable': 'ocrd-test', 'steps': ['recognition/post-correction']} class DummyProcessor(Processor): def __init__(self, *args, **kwargs): - kwargs['ocrd_tool'] = { - 'executable': 'ocrd-test' - } + kwargs['ocrd_tool'] = DUMMY_TOOL kwargs['version'] = '0.0.1' super(DummyProcessor, self).__init__(*args, **kwargs) + def process(self): + # print('# nope') + pass + class TestResolver(TestCase): def setUp(self): @@ -29,5 +33,11 @@ def test_params(self): proc = Processor(workspace=self.workspace) self.assertEqual(proc.parameter, {}) + def test_run_agent(self): + no_agents_before = len(self.workspace.mets.agents) + run_processor(DummyProcessor, ocrd_tool=DUMMY_TOOL, workspace=self.workspace) + self.assertEqual(len(self.workspace.mets.agents), no_agents_before + 1, 'one more agent') + print(self.workspace.mets.agents[no_agents_before]) + if __name__ == "__main__": main()