Codestyle enhancements

This commit is contained in:
Patrick Jentsch 2022-01-27 13:48:16 +01:00
parent 22a7217036
commit aacac4e0a0

View File

@ -7,7 +7,6 @@ __version__ = '0.1.0'
from argparse import ArgumentParser
from pyflow import WorkflowRunner
import json
import multiprocessing
import os
import sys
@ -52,7 +51,9 @@ class CreatePDFWorkflow(WorkflowRunner):
os.path.join(self.job.output_dir, '{}.pdf'.format(self.job.name))
)
cmd += ' && '
cmd += 'rm "{}"'.format(os.path.join(self.job.output_dir, 'inputs.txt')) # noqa
cmd += 'rm "{}"'.format(
os.path.join(self.job.output_dir, 'inputs.txt')
)
self.addTask(
'convert',
command=cmd,
@ -68,6 +69,7 @@ class MainWorkflow(WorkflowRunner):
self.jobs = []
def collect_jobs(self):
self.jobs = []
for dir in os.listdir(self.input_dir):
if not os.path.isdir(os.path.join(self.input_dir, dir)):
continue
@ -102,38 +104,53 @@ class MainWorkflow(WorkflowRunner):
create_pdf_tasks.append(task)
self.waitForTasks()
output_files = []
outputs = []
for job in self.jobs:
# Track output files
relative_output_dir = os.path.relpath(job.output_dir, start=self.output_dir) # noqa
output_files.append(
relative_output_dir = os.path.relpath(
job.output_dir,
start=self.output_dir
)
outputs.append(
{
'description': 'PDF file without text layer.',
'file': os.path.join(relative_output_dir, '{}.pdf'.format(job.name)), # noqa
'file': os.path.join(
relative_output_dir,
'{}.pdf'.format(job.name)
),
'mimetype': 'application/pdf'
}
)
with open(os.path.join(self.output_dir, 'output_records.json'), 'w') as f: # noqa
json.dump(output_files, f, indent=4)
with open(os.path.join(self.output_dir, 'outputs.json'), 'w') as f:
json.dump(outputs, f, indent=4)
def parse_args():
parser = ArgumentParser(description='Pipeline for merging images')
parser.add_argument(
'-i', '--input-dir', help='Input directory', required=True)
'-i', '--input-dir',
help='Input directory',
required=True
)
parser.add_argument(
'-o', '--output-dir', help='Output directory', required=True)
'-o', '--output-dir',
help='Output directory',
required=True
)
parser.add_argument(
'--log-dir', help='Logging directory (Default: --output-dir)')
'--log-dir',
help='Logging directory (Default: --output-dir)'
)
parser.add_argument(
'--mem-mb',
help='Amount of system memory to be used (Default: min(--n-cores * 256, available system memory))', # noqa
help='Amount of system memory to be used '
'(Default: min(--n-cores * 256, available system memory))',
type=int
)
parser.add_argument(
'--n-cores',
default=min(2, multiprocessing.cpu_count()),
help='Number of CPU threads to be used (Default: min(2, CPU count))',
default=1,
help='Number of CPU threads to be used',
type=int
)
parser.add_argument(
@ -162,7 +179,10 @@ def main():
main_workflow = MainWorkflow(args.input_dir, args.output_dir)
main_workflow.collect_jobs()
retval = main_workflow.run(
dataDirRoot=args.log_dir, memMb=args.mem_mb, nCores=args.n_cores) # noqa
dataDirRoot=args.log_dir,
memMb=args.mem_mb,
nCores=args.n_cores
)
sys.exit(retval)