file-setup/wrapper/setup_files
2020-02-07 16:26:24 +01:00

40 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python3
# coding=utf-8
import argparse
import os
import subprocess
container_image = 'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/setup_files:latest'
container_input_dir = '/input'
container_output_dir = '/output'
uid = str(os.getuid())
gid = str(os.getgid())
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
'-i',
dest='input_dir',
required=False
)
parser.add_argument(
'-o',
dest='output_dir',
required=False
)
args, remaining_args = parser.parse_known_args()
cmd = ['docker', 'run', '--rm', '-it', '-u', uid + ':' + gid]
if args.input_dir is not None:
host_input_dir = os.path.abspath(args.input_dir)
cmd += ['-v', host_input_dir + ':' + container_input_dir]
remaining_args += ['-i', container_input_dir]
if args.output_dir is not None:
host_output_dir = os.path.abspath(args.output_dir)
cmd += ['-v', host_output_dir + ':' + container_output_dir]
remaining_args += ['-o', container_output_dir]
cmd.append(container_image)
cmd += remaining_args
subprocess.run(cmd)