Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@ Also contains the command line tool `ocrd`.

See [README for `ocrd`](./README_ocrd.md) for further information.

## bash library

Builds a bash script that can be sourced by other bash scripts to create OCRD-compliant CLI.

See [README for `bashlib`](./README_bashlib.md) for further information.

## Testing

Download assets (`make assets`)
Expand Down
177 changes: 0 additions & 177 deletions README_bashlib.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/ocrd/ocrd.cli.bashlib.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/ocrd/ocrd.cli.log.rst

This file was deleted.

2 changes: 0 additions & 2 deletions docs/api/ocrd/ocrd.cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Submodules
.. toctree::
:maxdepth: 4

ocrd.cli.bashlib
ocrd.cli.log
ocrd.cli.network
ocrd.cli.ocrd_tool
ocrd.cli.process
Expand Down
6 changes: 2 additions & 4 deletions src/ocrd/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ def get_help(self, ctx):
from .ocrd_tool import ocrd_tool_cli
from .workspace import workspace_cli
from .process import process_cli
from .bashlib import bashlib_cli
from .validate import validate_cli
from .resmgr import resmgr_cli
from .zip import zip_cli
from .log import log_cli
from .network import network_cli
from .bashlib import bashlib_cli


__all__ = ['cli']
Expand Down Expand Up @@ -117,9 +116,8 @@ def cli(**kwargs): # pylint: disable=unused-argument
cli.add_command(ocrd_tool_cli)
cli.add_command(workspace_cli)
cli.add_command(process_cli)
cli.add_command(bashlib_cli)
cli.add_command(zip_cli)
cli.add_command(validate_cli)
cli.add_command(log_cli)
cli.add_command(resmgr_cli)
cli.add_command(network_cli)
cli.add_command(bashlib_cli)
123 changes: 6 additions & 117 deletions src/ocrd/cli/bashlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@
:nested: full

"""
from __future__ import print_function
import sys
import click

# WARNING: bashlib processors have been deprecated as of v3 of the OCR-D/core API
# and will be removed in v3.7.0. We retain the `ocrd bashlib` CLI only
# to not break the `ocrd bashlib filename` command, which is used in CD
# scripts to get the `share` directory of the core installation.

import click
from ocrd.constants import BASHLIB_FILENAME
import ocrd.constants
import ocrd_utils.constants
from ocrd_utils.constants import DEFAULT_METS_BASENAME
import ocrd_models.constants
import ocrd_validators.constants
from ocrd.decorators import (
parameter_option,
parameter_override_option,
ocrd_loglevel,
ocrd_cli_wrap_processor
)
from ocrd_utils import make_file_id
from ocrd.processor import Processor

# ----------------------------------------------------------------------
# ocrd bashlib
Expand All @@ -50,104 +40,3 @@ def bashlib_filename():
"""
print(BASHLIB_FILENAME)


@bashlib_cli.command('constants')
@click.argument('name')
def bashlib_constants(name):
"""
Query constants from ocrd_utils and ocrd_models
"""
all_constants = {}
for src in [ocrd.constants, ocrd_utils.constants, ocrd_models.constants, ocrd_validators.constants]:
for k in src.__all__:
all_constants[k] = src.__dict__[k]
if name in ['*', 'KEYS', '__all__']:
print(sorted(all_constants.keys()))
sys.exit(0)
if name not in all_constants:
print("ERROR: name '%s' is not a known constant" % name, file=sys.stderr)
sys.exit(1)
val = all_constants[name]
if isinstance(val, dict):
# make this bash-friendly (show initialization for associative array)
for key in val:
print("[%s]=%s" % (key, val[key]), end=' ')
else:
print(val)


@bashlib_cli.command('input-files')
@click.option('--ocrd-tool', help="path to ocrd-tool.json of processor to feed", default=None)
@click.option('--executable', help="name of processor executable in ocrd-tool.json", default=None)
@click.option('-m', '--mets', help="METS to process", default=DEFAULT_METS_BASENAME)
@click.option('-U', '--mets-server-url', help='TCP host URI or UDS path of METS server', default=None)
@click.option('-d', '--working-dir', help="Working Directory")
@click.option('-I', '--input-file-grp', help='File group(s) used as input.', default=None)
@click.option('-O', '--output-file-grp', help='File group(s) used as output.', default=None)
@click.option('-g', '--page-id', help="ID(s) of the pages to process")
@click.option('--overwrite', is_flag=True, default=False, help="Remove output pages/images if they already exist\n"
"(with '--page-id', remove only those).\n"
"Short-hand for OCRD_EXISTING_OUTPUT=OVERWRITE")
@click.option('--debug', is_flag=True, default=False, help="Abort on any errors with full stack trace.\n"
"Short-hand for OCRD_MISSING_OUTPUT=ABORT")
@parameter_option
@parameter_override_option
@ocrd_loglevel
def bashlib_input_files(ocrd_tool, executable, **kwargs):
"""
List input files for processing

Instantiate a processor and workspace from the given processing options.
Then loop through the input files of the input fileGrp, and for each one,
print its `url`, `ID`, `mimetype` and `pageId`, as well as its recommended
`outputFileId` (from ``make_file_id``).

(The printing format is one associative array initializer per line.)
"""
class BashlibProcessor(Processor):
# go half way of the normal run_processor / process_workspace call tree
# by just delegating to process_workspace, overriding process_page_file
# to ensure all input files exist locally (without persisting them in the METS)
# and print what needs to be acted on in bash-friendly way
def process_page_file(self, *input_files):
for field in ['url', 'local_filename', 'ID', 'mimetype', 'pageId']:
# make this bash-friendly (show initialization for associative array)
if len(input_files) > 1:
# single quotes allow us to preserve the list value inside the alist
value = ' '.join(str(getattr(res, field)) for res in input_files)
else:
value = str(getattr(input_files[0], field))
print(f"[{field}]='{value}'", end=' ')
output_file_id = make_file_id(input_files[0], kwargs['output_file_grp'])
print(f"[outputFileId]='{output_file_id}'")
if ocrd_tool and executable:
class FullBashlibProcessor(BashlibProcessor):
@property
def metadata_location(self):
# needed for metadata loading and validation mechanism
return ocrd_tool

@property
def executable(self):
# needed for ocrd_tool lookup
return executable
processor_class = FullBashlibProcessor
else:
# we have no true metadata file, so fill in just to make it work
class UnknownBashlibProcessor(BashlibProcessor):
@property
def ocrd_tool(self):
# needed to satisfy the validator
return {'executable': '',
# required now
'input_file_grp_cardinality': 1,
'output_file_grp_cardinality': 1,
'steps': ['']}

@property
def version(self):
# needed to satisfy the validator and wrapper
return '1.0'
processor_class = UnknownBashlibProcessor

ocrd_cli_wrap_processor(processor_class, **kwargs)
Loading
Loading