mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/ocr.git
				synced 2025-10-31 20:03:14 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env python3
 | |
| # coding=utf-8
 | |
| 
 | |
| from argparse import ArgumentParser
 | |
| import os
 | |
| import subprocess
 | |
| import sys
 | |
| 
 | |
| CONTAINER_IMAGE = 'gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/ocr:v0.1.0'
 | |
| CONTAINER_INPUT_DIR = '/input'
 | |
| CONTAINER_OUTPUT_DIR = '/output'
 | |
| CONTAINER_MODELS_DIR = '/usr/local/share/tessdata'
 | |
| CONTAINER_LOG_DIR = '/logs'
 | |
| 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('-m', '--model', action='extend', dest='models', nargs='+')
 | |
| parser.add_argument('--log-dir')
 | |
| args, remaining_args = parser.parse_known_args()
 | |
| 
 | |
| cmd = ['docker', 'run', '--rm', '-it', '-u', f'{UID}:{GID}']
 | |
| if args.input_dir is not None:
 | |
|     mapping = f'{os.path.abspath(args.input_dir)}:{CONTAINER_INPUT_DIR}'
 | |
|     cmd += ['-v', mapping]
 | |
|     remaining_args += ['-i', CONTAINER_INPUT_DIR]
 | |
| if args.output_dir is not None:
 | |
|     mapping = f'{os.path.abspath(args.output_dir)}:{CONTAINER_OUTPUT_DIR}'
 | |
|     cmd += ['-v', mapping]
 | |
|     remaining_args += ['-o', CONTAINER_OUTPUT_DIR]
 | |
| if args.models is not None:
 | |
|     for model in args.models:
 | |
|         mapping = f'{os.path.abspath(model)}:{CONTAINER_MODELS_DIR}/{os.path.basename(model)}'  # noqa
 | |
|         cmd += ['-v', mapping]
 | |
| if args.log_dir is not None:
 | |
|     mapping = '{os.path.abspath(args.log_dir)}:{CONTAINER_LOG_DIR}'
 | |
|     cmd += ['-v', mapping]
 | |
|     remaining_args += ['--log-dir', CONTAINER_LOG_DIR]
 | |
| cmd.append(CONTAINER_IMAGE)
 | |
| cmd += remaining_args
 | |
| 
 | |
| sys.exit(subprocess.run(cmd).returncode)
 |