Warning: Can't use blame annotator:
svn blame failed on trunk/src/python/unifiedlogger/cad_watcher.py: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/python/unifiedlogger/cad_watcher.py @ 466

Revision 466, 1.7 KB checked in by jdalbey, 7 years ago (diff)

Add copyXMLfile method to Coordinator to fix #178.

RevLine 
1import json, time, ConfigParser
2from copy import deepcopy
3
4# CAD comment log Watcher
5# Look for changes in the CAD comment log.
6# The CADserver will append new comments to the log as they arrive
7# from clients.  We only need to keep track of the log length in order to
8# determine if a new comment has been added.  We will output the
9# new messages that arrived during the last wait interval.
10# jdalbey  7/6/2019
11
12lastLineNum = 0
13
14# Utility functions
15def isEmpty(cmsitem):
16    return cmsitem == ",,,,,"
17def isFull(cmsitem):
18    return not isEmpty(cmsitem)
19
20# Read the cad comments log
21def readFile():
22    # get path to input file from configuration
23    config = ConfigParser.ConfigParser()
24    config.read('config/logging_service.cfg')
25    logfilepath  = config.get('Paths', 'UnifiedLogPath')
26   
27    lines = []
28    try:
29        text_file = open(logfilepath + "CADcomments.log", "r")
30    except IOError:
31        print "Error: missing "+logfilepath+"CADcomments.log file."
32    else:
33        lines = text_file.read().split('\n')
34        text_file.close()   
35    return lines
36   
37def setup():
38    lastLineNum = 0
39    return
40
41# Retrieve new messages from CAD comment log
42def getLogEntries():
43    global lastLineNum
44    msgList = readFile()
45    currList = []
46    currList = msgList[lastLineNum:]    # new items since last file read
47    lastLineNum = len(msgList)-1
48    return currList
49
50# Local main for unit testing
51def main():
52    setup()
53    # Loop Forever, checking every five seconds
54    while True:
55        # Look for new messages
56        answer = getLogEntries()
57        # Output results
58        for item in answer:
59            print item
60        # wait
61        time.sleep(5)
62
63if __name__ == "__main__":
64    main()
Note: See TracBrowser for help on using the repository browser.