|
1
|
|
|
# pylint: disable=missing-module-docstring,invalid-name |
|
2
|
|
|
from os.path import join, basename |
|
3
|
|
|
|
|
4
|
|
|
import click |
|
5
|
|
|
|
|
6
|
|
|
from ocrd import Processor |
|
7
|
|
|
from ocrd.decorators import ocrd_cli_options, ocrd_cli_wrap_processor |
|
8
|
|
|
from ocrd_utils import getLogger |
|
9
|
|
|
|
|
10
|
|
|
DUMMY_TOOL = { |
|
11
|
|
|
'executable': 'ocrd-dummy', |
|
12
|
|
|
'description': 'Bare-bones processor that copies file from input group to output group', |
|
13
|
|
|
'steps': ['preprocessing/optimization'], |
|
14
|
|
|
'categories': ['Image preprocessing'], |
|
15
|
|
|
'input_file_grp': 'DUMMY_INPUT', |
|
16
|
|
|
'output_file_grp': 'DUMMY_OUTPUT', |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
LOG = getLogger('ocrd.dummy') |
|
20
|
|
|
|
|
21
|
|
|
class DummyProcessor(Processor): |
|
22
|
|
|
""" |
|
23
|
|
|
Bare-bones processor that copies mets:file from input group to output group. |
|
24
|
|
|
""" |
|
25
|
|
|
|
|
26
|
|
|
def process(self): |
|
27
|
|
|
for n, input_file in enumerate(self.input_files): |
|
28
|
|
|
input_file = self.workspace.download_file(input_file) |
|
29
|
|
|
page_id = input_file.pageId or input_file.ID |
|
30
|
|
|
LOG.info("INPUT FILE %i / %s", n, page_id) |
|
31
|
|
|
file_id = 'COPY_OF_%s' % input_file.ID |
|
32
|
|
|
local_filename = join(self.output_file_grp, basename(input_file.local_filename)) |
|
33
|
|
|
with open(input_file.local_filename, 'rb') as f: |
|
34
|
|
|
content = f.read() |
|
35
|
|
|
self.workspace.add_file( |
|
36
|
|
|
ID=file_id, |
|
37
|
|
|
file_grp=self.output_file_grp, |
|
38
|
|
|
pageId=input_file.pageId, |
|
39
|
|
|
mimetype=input_file.mimetype, |
|
40
|
|
|
local_filename=local_filename, |
|
41
|
|
|
content=content) |
|
42
|
|
|
|
|
43
|
|
|
def __init__(self, *args, **kwargs): |
|
44
|
|
|
kwargs['ocrd_tool'] = DUMMY_TOOL |
|
45
|
|
|
kwargs['version'] = '0.0.1' |
|
46
|
|
|
super(DummyProcessor, self).__init__(*args, **kwargs) |
|
47
|
|
|
|
|
48
|
|
|
@click.command() |
|
49
|
|
|
@ocrd_cli_options |
|
50
|
|
|
def cli(*args, **kwargs): |
|
51
|
|
|
return ocrd_cli_wrap_processor(DummyProcessor, *args, **kwargs) |
|
52
|
|
|
|