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 @ 687

Revision 687, 2.3 KB checked in by jdalbey, 4 years ago (diff)

logging_service.py, et.al. Revise how it handles a missing CADcomments.log file - just skip the file read but continue. Also update all watchers to use config dir.

RevLine 
1import json, time, ConfigParser, os
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
13configdir = "config"  # default dir for production
14
15def setup(dir):
16    global lastLineNum, configdir
17    lastLineNum = 0
18    configdir = dir
19    return
20
21# Retrieve new messages from CAD comment log
22def getLogEntries():
23    global lastLineNum, configdir
24    # get path to input file from configuration
25    config = ConfigParser.ConfigParser()
26    config.read(configdir+'/logging_service.cfg')
27    logfilepath  = config.get('Paths', 'UnifiedLogPath')
28    pathToLog = logfilepath + "CADcomments.log"
29   
30    try:
31        text_file = open(pathToLog, "r")
32    except IOError as ex:
33        if ex.errno == 2:
34            # 'No such file or directory'
35            # Assume this is a read sync problem: Don't modify lastLineNum
36            print pathToLog + " missing, skipping file read."
37            #lastLineNum = 0   #Start over
38            return []
39        else:
40            print "IOError reading "+pathToLog+" file."
41            print "errno: ",ex.errno
42           
43    else:
44        # Check file size
45        fileSize = os.path.getsize(pathToLog)
46        if fileSize == 0:
47            print pathToLog+" is empty, skipping file read and resetting."
48            lastLineNum = 0   #Start over
49            return []
50        else: # file is good, read it.
51            msgList = text_file.read().strip().split('\n')
52            text_file.close()
53            currList = []
54            currList = msgList[lastLineNum:] # new items since last file read
55            lastLineNum = len(msgList)
56            return currList
57
58# Local main for unit testing
59def main():
60    setup("config/devlinux")
61    # Loop Forever, checking every five seconds
62    while True:
63        # Look for new messages
64        answer = getLogEntries()
65        # Output results
66        for item in answer:
67            print item
68        # wait
69        time.sleep(5)
70
71if __name__ == "__main__":
72    main()
Note: See TracBrowser for help on using the repository browser.