From 7b6ce4c019365689903f31b4eb53cd5c27e066dd Mon Sep 17 00:00:00 2001 From: rtrimana Date: Wed, 22 Apr 2020 20:52:50 -0700 Subject: [PATCH] Modification in the script for extraction. --- SummarizeLogs.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/SummarizeLogs.py b/SummarizeLogs.py index e184fda..4de9acb 100644 --- a/SummarizeLogs.py +++ b/SummarizeLogs.py @@ -15,6 +15,7 @@ import glob # Index 0 is always for the Python script itself jpfLogDir = sys.argv[1] csvFileOutput = sys.argv[2] +addLogFile = sys.argv[3] # Extract the status finished/unfinished def getStatus(text): @@ -31,20 +32,36 @@ def getStates(text): startIndex = text.find('=', startStatesInfo) endIndex = text.find(',', startIndex) return text[startIndex+1:endIndex] + +# Extract number of conflicts +def getConflicts(text, startIndex): + conflictIndex = text.find('conflicts :', startIndex) + newLineIndex = text.index('\n', conflictIndex) + startIndex = conflictIndex + 10 # Assuming that it will be greater than 10 + if conflictIndex == -1: + returnedText = '0' + startIndex = len(text) + else: + returnedText = text[conflictIndex+14:newLineIndex] + return startIndex, returnedText print("Opening log files ...\n\n") out = open(csvFileOutput, "w+") -for filename in glob.glob(os.path.join(jpfLogDir, '*.log')): - with open(filename, 'r') as f: - text = f.read() - status = getStatus(text) # Getting status "no errors/finished" or "not finished" - states = getStates(text) - lastSlash = filename.rfind('/') - lastDoubleDash = filename.rfind('--') - fname = filename[lastSlash+1:lastDoubleDash] - lineReport = fname + ',' + status + ',' + states + '\n' - out.write(lineReport) - print(lineReport) +with open(addLogFile, 'r') as addFile: + addText = addFile.read() + startIndex = 0 + for filename in glob.glob(os.path.join(jpfLogDir, '*.log')): + with open(filename, 'r') as f: + text = f.read() + status = getStatus(text) # Getting status "no errors/finished" or "not finished" + states = getStates(text) + startIndex, conflicts = getConflicts(addText, startIndex) + lastSlash = filename.rfind('/') + lastDoubleDash = filename.rfind('--') + fname = filename[lastSlash+1:lastDoubleDash] + lineReport = fname + ',' + status + ',' + states + ',' + conflicts + '\n' + out.write(lineReport) + print(lineReport) out.close() -- 2.34.1