mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/file-setup.git
synced 2024-12-26 19:34:19 +00:00
58 lines
1.5 KiB
Plaintext
58 lines
1.5 KiB
Plaintext
|
#!/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()
|