Add functionality to allow creating log.generate.short without running the commit script
This can either be done by supplying an extra script or updating the commit script to handle such cases (might be better).
Standalone code is provided below.
The code below works with
python3 makeLogShort.py ./path/to/log.generate ./path/to/mc.XXX.py
#! /usr/bin/env python3
import re,sys, subprocess, shlex
def bashExec(cmd, debug = False, checkStatus = False):
if debug:
print(cmd)
return ''
p = subprocess.run(shlex.split(cmd), stdout=subprocess.PIPE)
if checkStatus:
return p.stdout.decode('utf-8').strip(), p.returncode
return p.stdout.decode('utf-8').strip()
tags = [
'estimated CPU for CI job',
'using release',
'ecmEnergy',
'inputGeneratorFile',
'inputEVNT_PreFile',
'randomSeed',
'EVNT to EVNT',
'LHEonly',
'ATHENA_PROC_NUMBER',
'platform'
]
logparser_cmd = f'python3 scripts/logParser.py -i {sys.argv[1]} -j {sys.argv[2]}'
LPO, rc = bashExec(logparser_cmd, checkStatus = True)
# Remove colours from logParserOutput and extract necessary information
LPO_noCols = re.sub(r'\x1b\[[0-9]{1,3}[mK]', '', LPO)
greps = sum((re.compile(f'.*{tag}.*').findall(LPO_noCols)[:1] for tag in tags), [])
# Pipe information into log.generate.short
with open(f'log.generate.short', 'w') as logShort:
logShort.write('\n'.join(greps))