source: tmcsimulator/trunk/webapps/unifiedlogger/cad_watcher.py @ 433

Revision 433, 1.0 KB checked in by jdalbey, 7 years ago (diff)

Unified Logger v1.0. Add cad watcher plugin to logging service.

Line 
1import json, time
2from copy import deepcopy
3
4# CAD comment log Watcher
5# Look for changes in the CAD comment log
6# jdalbey  7/6/2019
7
8lastLineNum = 0
9
10# Utility functions
11def isEmpty(cmsitem):
12    return cmsitem == ",,,,,"
13def isFull(cmsitem):
14    return not isEmpty(cmsitem)
15
16# Read the cms message file
17def readFile():     
18    text_file = open("../../CADcomments.log", "r")
19    lines = text_file.read().split('\n')
20    return lines
21   
22def setup():
23    # nothing needed for setup
24    return
25
26# Retrieve new messages from CAD comment log
27def getLogEntries():
28    global lastLineNum
29    msgList = readFile()
30    currList = []
31    currList = msgList[lastLineNum:]    # new items since last file read
32    lastLineNum = len(msgList)-1
33    return currList
34
35def main():
36    setup()
37    # Loop Forever
38    while True:
39        # Look for changed messages
40        answer = getLogEntries()
41        # Output results
42        for item in answer:
43            print item
44        # wait
45        time.sleep(5)
46
47if __name__ == "__main__":
48    main()
Note: See TracBrowser for help on using the repository browser.