Commit 5eca0431 authored by Daniel Smith's avatar Daniel Smith

Add support for direct use of COIN log file via url

parent f885cf8d
Pipeline #1344 canceled with stages
......@@ -6,6 +6,9 @@ This is a minimal log parser for test logs created by the COIN CI system. Provid
# Arguments
1. --logdir - The full path to a directory of logs. Please use uour OS's correct path separator.
2. --printall - Set to force printing details of tests with more than 9 fail cases.
3. --suppressconsole - Set to prevent writing results to screen.
4. --suppressfile - Set to prevent writing results to file.
\ No newline at end of file
2. --logurl - The URL to a logfile in txt or gzip format. Suitable for use directy with COIN URLs.
3. --outputdir - Specify the output location for result files. Defaults to {logdir}/parser_results.
1. Custom value required when using --logurl unless file output is suppressed with --suppressfile. Please use your OS's correct path separator.
4. --printall - Set to force printing details of tests with more than 9 fail cases.
5. --suppressconsole - Set to prevent writing results to screen.
6. --suppressfile - Set to prevent writing results to file.
\ No newline at end of file
import os
import argparse
import re
import io
import tempfile
import requests
failedTests = {} # Typing.dict()
totalCount = 0
......@@ -19,8 +22,11 @@ def findFailedTests(logfile: str):
if args.suppressFile:
resultsFilename = os.devnull
else:
resultsFilename = "{0}{1}{2}_failures.txt".format(os.path.join(args.logDir, "parser_results"), os.sep,
logfile[logfile.rfind(os.sep) + 1: logfile.rfind('.txt')])
if args.logDir:
resultsFilename = "{0}{1}{2}_failures.txt".format(os.path.join(args.logDir, "parser_results"), os.sep,
logfile[logfile.rfind(os.sep) + 1: logfile.rfind('.txt')])
else: # Assume URL was passed and we only have one file, and --outputdir was specified.
resultsFilename = "{0}{1}parser_results.txt".format(os.path.join(args.outDir, "parser_results"), os.sep)
with open(resultsFilename, mode='w+') as outfile:
for match in pattern.finditer(logtext): # Iterate through the matches for failed tests and strip out the individual cases.
......@@ -51,10 +57,22 @@ def findFailedTests(logfile: str):
if not args.suppressConsole: print("\r\n") # just a spacer fore readability when printing results to screen.
def retrieveLogFromURL(url: str):
r = ""
try:
r = requests.get(url)
except Exception as e:
print(e)
return r.content
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--logdir',dest='logDir', type=str, required=True, help='The full path to a directory of logs')
parser.add_argument('--logdir',dest='logDir', type=str, help='The full path to a directory of logs')
parser.add_argument('--logurl', dest='logURL', type=str, help='The URL to a logfile in txt or gzip format. Suitable for use directy with COIN.')
parser.add_argument('--outputdir', dest='outDir', type=str, help='Specify the output location for result files. Defaults to $\{logdir\}/parser_results')
parser.add_argument('--printall', action='store_true', dest="printAll", help="Set --printall to force printing details of tests with more than 9 fail cases. ")
parser.add_argument('--suppressconsole', action='store_true', dest="suppressConsole", help="Set --supressconsole to prevent writing to screen.")
parser.add_argument('--suppressfile', action='store_true', dest="suppressFile", help="Set --supressfile to prevent writing results to file.")
......@@ -62,15 +80,32 @@ if __name__ == "__main__":
args = parser.parse_args()
logfiles = os.listdir(args.logDir)
# print(logfiles) # diagnostic
if not args.logDir and not (args.logURL and (False if args.logURL and not args.suppressFile else True)):
print("\r\nWARNING: You must supply either --logdir or --logurl as an argument.\r\n--outputdir must be\
specified when using --logurl unless file output is supressed with --suppressfile.")
exit(0)
print("\r\n") # Just to help with formatting the output on screen.
if args.logDir:
if not os.path.exists(os.path.join(args.logDir, "parser_results")) and not args.suppressFile:
os.makedirs(os.path.join(args.logDir, "parser_results"))
if not os.path.exists(os.path.join(args.logDir, "parser_results")) and not args.suppressFile:
os.makedirs(os.path.join(args.logDir, "parser_results"))
for logfile in logfiles:
print("Processing {0}".format(logfile))
if not os.path.isdir(os.path.join(args.logDir, logfile)):
findFailedTests(os.path.join(args.logDir, logfile))
for logfile in logfiles:
print("Processing {0}".format(logfile))
if not os.path.isdir(os.path.join(args.logDir, logfile)):
findFailedTests(os.path.join(args.logDir, logfile))
else: # must be args.logURL supplied.
log = tempfile.NamedTemporaryFile(mode='wb', suffix=".txt", delete=False)
filebytes=retrieveLogFromURL(args.logURL)
log.writelines(io.BytesIO(filebytes))
log.close()
findFailedTests(log.name)
try:
os.remove(log.name)
except Exception as e:
os.unlink(log.name) # try unlinking as a backup?
print("Done parsing.\r\nTotal failed test applications: {0}\r\nTotal failed test cases: {1}".format(totalCount, totalTestCaseCount))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment