lljobcat 1.52 KB
Newer Older
1 2 3 4 5 6
#!/usr/bin/env python3

from loadleveller import jobstatus, jobfile
import argparse
import subprocess
import json
7 8
import os
import shutil
9 10 11 12 13

parser = argparse.ArgumentParser(description='Concatenate job results and merge them if needed')
parser.add_argument('jobfiles', nargs='+', help='jobs to concatenate')
parser.add_argument('-o', '--output', required=True, help='output file for the concatenated result.')
parser.add_argument('-n', '--no-merge', action='store_true', help='skip the merging step')
14
parser.add_argument('-c', '--copy-jobfile', action='store_true', help='copy <jobfiles> to the output in a .scripts directory.')
15 16
args = parser.parse_args()

17 18 19 20 21
os.makedirs(os.path.dirname(args.output), exist_ok=True)
if args.copy_jobfile:
    job_archive_dir = os.path.splitext(args.output)[0]+'.scripts'
    os.makedirs(job_archive_dir, exist_ok=True)

22 23 24 25 26 27 28 29 30 31 32 33
tasks = []
for jobname in args.jobfiles:
    try:
        j = jobfile.JobFile(jobname)
        if not args.no_merge:
            if jobstatus.job_need_merge(j):
                subprocess.run(['loadl', 'm', jobname])

        with open(j.jobname+'.results.json', 'r') as infile:
            res = json.load(infile)
            tasks += res

34 35
        if args.copy_jobfile:
            shutil.copyfile(jobname, os.path.join(job_archive_dir,jobname))
36 37 38 39 40 41 42
    except FileNotFoundError:
        print('File not found for "{}". Skipping...'.format(jobname))
with open(args.output, 'w') as outfile:
    json.dump(tasks, outfile, indent=0)

print('{} -> {}'.format(' '.join(args.jobfiles), args.output))