mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/file-setup.git
synced 2025-07-01 10:20:34 +00:00
Update file_setup Pipeline
This commit is contained in:
57
file_setup
Executable file
57
file_setup
Executable file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3.5
|
||||
# coding=utf-8
|
||||
|
||||
|
||||
"""
|
||||
merge_images
|
||||
|
||||
Usage: For usage instructions run with option --help
|
||||
Author: Stephan Porada <sporada@uni-bielefeld.de>
|
||||
|
||||
"""
|
||||
|
||||
from argparse import ArgumentParser
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
parser = ArgumentParser(description='Merges images into one .pdf file.')
|
||||
parser.add_argument('i', metavar='input directory')
|
||||
parser.add_argument('o', metavar='output directory')
|
||||
parser.add_argument('f', metavar='output file base')
|
||||
parser.add_argument('--log-dir')
|
||||
parser.add_argument('--zip')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def merge_images(input_dir, output_dir, output_file_base, zip):
|
||||
try:
|
||||
os.mkdir(output_dir)
|
||||
except FileExistsError:
|
||||
pass
|
||||
cmd = 'ls -Q -v "{i}"/*.* > "{i}"/file_list.txt'.format(i=input_dir)
|
||||
subprocess.run(cmd, shell=True)
|
||||
cmd = 'convert @"{}"/file_list.txt "{}"/"{}".pdf'.format(input_dir, output_dir, output_file_base) # noqa
|
||||
subprocess.run(cmd, shell=True)
|
||||
cmd = 'rm "{}"/file_list.txt'.format(input_dir)
|
||||
subprocess.run(cmd, shell=True)
|
||||
if zip is not None:
|
||||
cmd = 'cd "{}"'.format(output_dir)
|
||||
cmd += ' && '
|
||||
cmd += 'zip'
|
||||
cmd += ' -m'
|
||||
cmd += ' "{}"_-_pdf "{}".pdf'.format(zip, output_file_base)
|
||||
cmd += ' && '
|
||||
cmd += 'cd -'
|
||||
subprocess.run(cmd, shell=True)
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_arguments()
|
||||
print(args)
|
||||
merge_images(args.i, args.o, args.f, args.zip)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user