Changeset 687 in tmcsimulator for trunk/src/python/unifiedlogger/cad_watcher.py


Ignore:
Timestamp:
10/02/2022 10:32:42 AM (4 years ago)
Author:
jdalbey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/python/unifiedlogger/cad_watcher.py

    r522 r687  
    1111 
    1212lastLineNum = 0 
     13configdir = "config"  # default dir for production 
    1314 
    14 def setup(): 
     15def setup(dir): 
     16    global lastLineNum, configdir 
    1517    lastLineNum = 0 
     18    configdir = dir 
    1619    return 
    1720 
    1821# Retrieve new messages from CAD comment log  
    1922def getLogEntries(): 
    20     global lastLineNum 
     23    global lastLineNum, configdir 
    2124    # get path to input file from configuration 
    2225    config = ConfigParser.ConfigParser() 
    23     config.read('config/logging_service.cfg') 
     26    config.read(configdir+'/logging_service.cfg') 
    2427    logfilepath  = config.get('Paths', 'UnifiedLogPath') 
    2528    pathToLog = logfilepath + "CADcomments.log" 
     
    2932    except IOError as ex: 
    3033        if ex.errno == 2: 
    31             # 'No such file or directory 
    32             print pathToLog + " missing: assuming reset." 
    33             lastLineNum = 0   #Start over 
     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 
    3438            return [] 
    3539        else: 
     
    4145        fileSize = os.path.getsize(pathToLog) 
    4246        if fileSize == 0: 
    43             # Assume this is a read sync problem: Don't modify lastLineNum 
    44             print pathToLog+" is empty, ignoring." 
     47            print pathToLog+" is empty, skipping file read and resetting." 
    4548            lastLineNum = 0   #Start over 
    4649            return [] 
    4750        else: # file is good, read it. 
    48             msgList = text_file.read().split('\n') 
     51            msgList = text_file.read().strip().split('\n') 
    4952            text_file.close() 
    5053            currList = [] 
    5154            currList = msgList[lastLineNum:] # new items since last file read 
    52             lastLineNum = len(msgList)-1 
     55            lastLineNum = len(msgList) 
    5356            return currList 
    5457 
    5558# Local main for unit testing 
    5659def main(): 
    57     setup() 
     60    setup("config/devlinux") 
    5861    # Loop Forever, checking every five seconds 
    5962    while True: 
Note: See TracChangeset for help on using the changeset viewer.