mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/ocr.git
synced 2024-12-26 17:44:18 +00:00
44 lines
1.4 KiB
Python
Executable File
44 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# coding=utf-8
|
|
|
|
"""A wrapper to execute the OCR pipeline in a Docker container."""
|
|
|
|
from argparse import ArgumentParser
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
CONTAINER_IMAGE = 'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/ocr:1.0.0'
|
|
CONTAINER_INPUT_DIR = '/input'
|
|
CONTAINER_LOG_DIR = '/logs'
|
|
CONTAINER_OUTPUT_DIR = '/output'
|
|
UID = str(os.getuid())
|
|
GID = str(os.getgid())
|
|
|
|
parser = ArgumentParser(add_help=False)
|
|
parser.add_argument('-i', '--input-dir')
|
|
parser.add_argument('-o', '--output-dir')
|
|
parser.add_argument('--log-dir')
|
|
args, remaining_args = parser.parse_known_args()
|
|
|
|
cmd = ['docker', 'run', '--rm', '-it', '-u', '{}:{}'.format(UID, GID)]
|
|
if args.log_dir is not None:
|
|
cmd += ['-v', '{}:{}'.format(os.path.abspath(args.log_dir),
|
|
CONTAINER_LOG_DIR)]
|
|
remaining_args.insert(0, CONTAINER_LOG_DIR)
|
|
remaining_args.insert(0, '--log-dir')
|
|
if args.input_dir is not None:
|
|
cmd += ['-v', '{}:{}'.format(os.path.abspath(args.input_dir),
|
|
CONTAINER_INPUT_DIR)]
|
|
remaining_args.insert(0, CONTAINER_INPUT_DIR)
|
|
remaining_args.insert(0, '-i')
|
|
if args.output_dir is not None:
|
|
cmd += ['-v', '{}:{}'.format(os.path.abspath(args.output_dir),
|
|
CONTAINER_OUTPUT_DIR)]
|
|
remaining_args.insert(0, CONTAINER_OUTPUT_DIR)
|
|
remaining_args.insert(0, '-o')
|
|
cmd.append(CONTAINER_IMAGE)
|
|
cmd += remaining_args
|
|
|
|
sys.exit(subprocess.run(cmd).returncode)
|