Adding printout for event numbers.
[smartthings-infrastructure.git] / SummarizeLogs.py
1 #!/usr/bin/python
2
3 import itertools
4 import sys
5 import os
6 import glob
7
8 # Input parameters:
9 # - JPF directory
10 # - JPF logs directory
11 # - app directory
12 # - list #1
13 # - list #2 (if needed)
14
15 # Index 0 is always for the Python script itself
16 jpfLogDir = sys.argv[1]
17 csvFileOutput = sys.argv[2]
18 addLogFile = sys.argv[3]
19
20 # Extract the status finished/unfinished
21 def getStatus(text):
22         if (text.find('no errors') != -1):
23                 return 'finished'
24         else:
25                 return 'unfinished'
26                 
27 # Extract the states
28 def getStates(text):
29         if not text:
30                 return '0'
31         startStatesInfo = text.find('states:')
32         startIndex = text.find('=', startStatesInfo)
33         endIndex = text.find(',', startIndex)
34         return text[startIndex+1:endIndex]
35         
36 # Extract number of conflicts
37 def getConflicts(text, startIndex):
38         conflictIndex = text.find('conflicts   :', startIndex)
39         newLineIndex = text.index('\n', conflictIndex)
40         startIndex = conflictIndex + 10 # Assuming that it will be greater than 10
41         if conflictIndex == -1:
42                 returnedText = '0'
43                 startIndex = len(text)
44         else:
45                 returnedText = text[conflictIndex+14:newLineIndex]
46         return startIndex, returnedText
47
48 print("Opening log files ...\n\n")
49 out = open(csvFileOutput, "w+")
50 with open(addLogFile, 'r') as addFile:
51         addText = addFile.read()
52         startIndex = 0
53         for filename in glob.glob(os.path.join(jpfLogDir, '*.log')):
54                 with open(filename, 'r') as f:
55                         text = f.read()
56                         status = getStatus(text) # Getting status "no errors/finished" or "not finished"
57                         states = getStates(text)
58                         startIndex, conflicts = getConflicts(addText, startIndex)
59                         lastSlash = filename.rfind('/')
60                         lastDoubleDash = filename.rfind('--')
61                         fname = filename[lastSlash+1:lastDoubleDash]
62                         lineReport = fname + ',' + status + ',' + states + ',' + conflicts + '\n'
63                         out.write(lineReport)
64                         print(lineReport)
65 out.close()
66                 
67
68