Changeset 467 in tmcsimulator for trunk/src/python/unifiedlogger/cad_watcher.py
- Timestamp:
- 07/27/2019 08:23:36 PM (7 years ago)
- File:
-
- 1 edited
-
trunk/src/python/unifiedlogger/cad_watcher.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/python/unifiedlogger/cad_watcher.py
r466 r467 1 import json, time, ConfigParser 1 import json, time, ConfigParser, os 2 2 from copy import deepcopy 3 3 … … 18 18 return not isEmpty(cmsitem) 19 19 20 # Read the cad comments log21 def readFile():22 # get path to input file from configuration23 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 lines36 37 20 def setup(): 38 21 lastLineNum = 0 … … 42 25 def getLogEntries(): 43 26 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 27 # get path to input file from configuration 28 config = ConfigParser.ConfigParser() 29 config.read('config/logging_service.cfg') 30 logfilepath = config.get('Paths', 'UnifiedLogPath') 31 pathToLog = logfilepath + "CADcomments.log" 32 33 try: 34 text_file = open(pathToLog, "r") 35 except IOError as ex: 36 if ex.errno == 2: 37 # 'No such file or directory 38 print pathToLog + " missing: assuming reset" 39 lastLineNum = 0 #Start over 40 return [] 41 else: 42 print "IOError reading "+pathToLog+" file." 43 print "errno: ",ex.errno 44 45 else: 46 # Check file size 47 fileSize = os.path.getsize(pathToLog) 48 if fileSize == 0: 49 # Assume this is a read sync problem: Don't modify lastLineNum 50 print pathToLog+" is empty." 51 return [] 52 else: # file is good, read it. 53 msgList = text_file.read().split('\n') 54 text_file.close() 55 currList = [] 56 currList = msgList[lastLineNum:] # new items since last file read 57 lastLineNum = len(msgList)-1 58 return currList 49 59 50 60 # Local main for unit testing
Note: See TracChangeset
for help on using the changeset viewer.
