fix pipeline

This commit is contained in:
Patrick Jentsch 2020-06-23 15:19:49 +02:00
parent 298a7291ea
commit 09b40c47c5
2 changed files with 28 additions and 19 deletions

View File

@ -17,9 +17,15 @@ 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('-i', '--input-directory',
help='Input directory',
required=True)
parser.add_argument('-o', '--output-directory',
help='Output directory',
required=True)
parser.add_argument('-f', '--output-file-base',
help='output file base',
required=True)
parser.add_argument('--log-dir')
parser.add_argument('--zip')
return parser.parse_args()
@ -42,20 +48,17 @@ def merge_images(input_dir, output_dir, output_file_base, zip):
subprocess.run(cmd, shell=True)
# Convert all image files into pdf files
cmd = ('mogrify -compress LZW -format pdf '
+ '-path "{o}" @"{i}"/file_list.txt').format(i=input_dir,
o=tmp_dir)
+ '-path "{}" @"{}"/file_list.txt'.format(tmp_dir, input_dir))
subprocess.run(cmd, shell=True)
# remove file list
cmd = 'rm "{i}"/file_list.txt'.format(i=input_dir)
cmd = 'rm "{}"/file_list.txt'.format(input_dir)
subprocess.run(cmd, shell=True)
# join all pdfs into one pdf
cmd = ('pdftk "{tmp_i}"/*.pdf cat '
+ 'output "{o}"/"{ofb}".pdf').format(tmp_i=tmp_dir,
o=output_dir,
ofb=output_file_base)
cmd = ('pdftk "{}"/*.pdf cat '.format(tmp_dir)
+ 'output "{}"/"{}".pdf').format(output_dir, output_file_base)
subprocess.run(cmd, shell=True)
# remove single pdf files
cmd = 'rm -r {tmp_i}'.format(tmp_i=tmp_dir)
cmd = 'rm -r "{}"'.format(tmp_dir)
subprocess.run(cmd, shell=True)
# zip stuff
if zip is not None:
@ -74,7 +77,10 @@ def merge_images(input_dir, output_dir, output_file_base, zip):
def main():
args = parse_arguments()
merge_images(args.i, args.o, args.f, args.zip)
merge_images(args.input_directory,
args.output_directory,
args.output_file_base,
args.zip)
if __name__ == '__main__':

View File

@ -12,18 +12,21 @@ UID = str(os.getuid())
GID = str(os.getgid())
parser = ArgumentParser(add_help=False)
parser.add_argument('-i')
parser.add_argument('-o')
parser.add_argument('-f')
parser.add_argument('-i', '--input-directory')
parser.add_argument('-o', '--output-directory')
args, remaining_args = parser.parse_known_args()
cmd = ['docker', 'run', '--rm', '-it', '-u', '{}:{}'.format(UID, GID)]
if args.o is not None:
cmd += ['-v', '{}:{}'.format(os.path.abspath(args.o), CONTAINER_OUTPUT_DIR)]
if args.output_directory is not None:
cmd += ['-v', '{}:{}'.format(os.path.abspath(args.output_directory),
CONTAINER_OUTPUT_DIR)]
remaining_args.insert(0, CONTAINER_OUTPUT_DIR)
if args.i is not None:
cmd += ['-v', '{}:{}'.format(os.path.abspath(args.i), CONTAINER_INPUT_DIR)]
remaining_args.insert(0, '-o')
if args.input_directory is not None:
cmd += ['-v', '{}:{}'.format(os.path.abspath(args.input_directory),
CONTAINER_INPUT_DIR)]
remaining_args.insert(0, CONTAINER_INPUT_DIR)
remaining_args.insert(0, '-i')
cmd.append(CONTAINER_IMAGE)
cmd += remaining_args
subprocess.run(cmd)