2019-05-21 12:29:26 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# coding=utf-8
|
|
|
|
|
2020-04-03 17:35:30 +02:00
|
|
|
from argparse import ArgumentParser
|
2019-06-03 13:32:42 +02:00
|
|
|
import os
|
2019-05-21 12:29:26 +02:00
|
|
|
import subprocess
|
|
|
|
|
2020-04-03 17:35:30 +02:00
|
|
|
CONTAINER_IMAGE = 'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/ocr:latest'
|
|
|
|
CONTAINER_INPUT_DIR = '/input'
|
2020-09-22 17:44:32 +02:00
|
|
|
CONTAINER_INTERMEDIATE_DIR = '/intermediate'
|
2020-04-03 17:35:30 +02:00
|
|
|
CONTAINER_OUTPUT_DIR = '/output'
|
|
|
|
UID = str(os.getuid())
|
|
|
|
GID = str(os.getgid())
|
2019-05-21 12:29:26 +02:00
|
|
|
|
2020-04-03 17:35:30 +02:00
|
|
|
parser = ArgumentParser(add_help=False)
|
2020-06-23 15:19:27 +02:00
|
|
|
parser.add_argument('-i', '--input-directory')
|
|
|
|
parser.add_argument('-o', '--output-directory')
|
2020-09-22 17:44:32 +02:00
|
|
|
parser.add_argument('--intermediate-directory')
|
2019-06-03 13:32:42 +02:00
|
|
|
args, remaining_args = parser.parse_known_args()
|
2019-05-21 12:29:26 +02:00
|
|
|
|
2020-04-03 17:35:30 +02:00
|
|
|
cmd = ['docker', 'run', '--rm', '-it', '-u', '{}:{}'.format(UID, GID)]
|
2020-09-22 17:44:32 +02:00
|
|
|
if args.intermediate_directory is not None:
|
|
|
|
cmd += ['-v', '{}:{}'.format(os.path.abspath(args.intermediate_directory),
|
|
|
|
CONTAINER_INTERMEDIATE_DIR)]
|
|
|
|
remaining_args.insert(0, CONTAINER_INTERMEDIATE_DIR)
|
|
|
|
remaining_args.insert(0, '--intermediate-directory')
|
2020-06-23 15:19:27 +02:00
|
|
|
if args.output_directory is not None:
|
|
|
|
cmd += ['-v', '{}:{}'.format(os.path.abspath(args.output_directory),
|
|
|
|
CONTAINER_OUTPUT_DIR)]
|
2020-04-03 17:35:30 +02:00
|
|
|
remaining_args.insert(0, CONTAINER_OUTPUT_DIR)
|
2020-06-23 15:19:27 +02:00
|
|
|
remaining_args.insert(0, '-o')
|
|
|
|
if args.input_directory is not None:
|
|
|
|
cmd += ['-v', '{}:{}'.format(os.path.abspath(args.input_directory),
|
|
|
|
CONTAINER_INPUT_DIR)]
|
2020-04-03 17:35:30 +02:00
|
|
|
remaining_args.insert(0, CONTAINER_INPUT_DIR)
|
2020-06-23 15:19:27 +02:00
|
|
|
remaining_args.insert(0, '-i')
|
2020-04-03 17:35:30 +02:00
|
|
|
cmd.append(CONTAINER_IMAGE)
|
2019-06-03 13:32:42 +02:00
|
|
|
cmd += remaining_args
|
2019-06-02 21:38:30 +02:00
|
|
|
|
|
|
|
subprocess.run(cmd)
|