Changeset 687 in tmcsimulator for trunk


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.

Location:
trunk/src/python/unifiedlogger
Files:
5 edited

Legend:

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

    r647 r687  
    3434file1length = 0 
    3535file2length = 0 
     36configdir = "config"  # default dir for production 
    3637 
    3738# Utility functions 
     
    4243# get path to input file from configuration 
    4344def getLogFilePath(): 
     45    global configdir 
    4446    config = ConfigParser.ConfigParser() 
    45     config.read('config/logging_service.cfg') 
     47    config.read(configdir+'/logging_service.cfg') 
    4648    return config.get('Paths', 'ActivityLogPath') 
    4749 
     
    5052# jdalbey 2022.9.1 
    5153def getLogFilenames(): 
     54    global configdir 
    5255    config = ConfigParser.ConfigParser() 
    53     config.read('config/logging_service.cfg') 
     56    config.read(configdir+'/logging_service.cfg') 
    5457    file1 = config.get('Files','ActivityLogDataFilename') 
    5558    file2 = config.get('Files','ActivityLogSummaryFilename') 
     
    124127    return resultList 
    125128 
    126 def setup(): 
    127     # nothing needed for setup 
     129def setup(dir): 
     130    global configdir 
     131    configdir = dir 
    128132    return 
    129133 
    130134# Local main for unit testing 
    131135def main(): 
    132     setup() 
     136    setup("config/devlinux") 
    133137    # Loop Forever, checking every five seconds 
    134138    while True: 
  • 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: 
  • trunk/src/python/unifiedlogger/cms_watcher.py

    r549 r687  
    1 import json, time 
     1import json, time, ConfigParser 
    22from copy import deepcopy 
    33 
     
    99currList = []  # current messages 
    1010locationMap = {} # map of CMS ID's to locations 
     11filepath = "webapps/dynamicdata" # default during development 
    1112 
    1213# Utility functions 
     
    1718 
    1819# Read the cms message file 
    19 def readFile():      
    20      with open ("webapps/dynamicdata/cms_messages.json",'r') as myfile: 
     20def readFile(): 
     21    global filepath 
     22    with open (filepath+"/cms_messages.json",'r') as myfile: 
    2123          jsonData=myfile.read() 
    2224  
    23      return json.loads(jsonData)['data'] 
     25    return json.loads(jsonData)['data'] 
    2426 
    2527# Read the static file of cms locations and create a lookup map 
     
    5658                    msgList[idx]['cms']['message']['phase2']['Line3']) 
    5759 
    58 def setup(): 
    59      extractMessages(initialize()) 
     60def setup(dir): 
     61    global filepath 
     62    # get path to input file from configuration 
     63    config = ConfigParser.ConfigParser() 
     64    config.read(dir+'/logging_service.cfg') 
     65    filepath  = config.get('Paths', 'UnifiedLogPath') 
     66    
     67    extractMessages(initialize()) 
    6068 
    6169# compare previous messages to current messages to look for changes 
     
    8694def main(): 
    8795     global currList 
    88      setup() 
     96     setup("config/devlinux") 
    8997     # Loop Forever 
    9098     while True: 
  • trunk/src/python/unifiedlogger/har_watcher.py

    r649 r687  
    1 import json, time 
     1import json, time, ConfigParser 
    22from copy import deepcopy 
    33 
     
    99currList = []  # current messages 
    1010locationMap = {} # map of HAR ID's to locations 
     11filepath = "webapps/dynamicdata" # default during development 
    1112 
    1213# Utility functions 
     
    1718 
    1819# Read the har message file 
    19 def readFile():      
    20      with open ("webapps/dynamicdata/har_messages.json",'r') as myfile: 
     20def readFile(): 
     21    global filepath 
     22    with open (filepath+"/har_messages.json",'r') as myfile: 
    2123          jsonData=myfile.read() 
    2224  
    23      return json.loads(jsonData)['data'] 
     25    return json.loads(jsonData)['data'] 
    2426 
    2527# Read the static file of cms locations and create a lookup map 
     
    5153          currList.append(aMessage.replace("\n"," ").strip()) 
    5254 
    53 def setup(): 
    54      extractMessages(initialize()) 
     55def setup(dir): 
     56    global filepath 
     57    # get path to input file from configuration 
     58    config = ConfigParser.ConfigParser() 
     59    config.read(dir+'/logging_service.cfg') 
     60    filepath  = config.get('Paths', 'UnifiedLogPath') 
     61 
     62    extractMessages(initialize()) 
    5563 
    5664# compare previous messages to current messages to look for changes 
     
    8189def main(): 
    8290     global currList 
    83      setup() 
     91     setup("config/devlinux") 
    8492     # Loop Forever 
    8593     while True: 
  • trunk/src/python/unifiedlogger/logging_service.py

    r683 r687  
    1212     
    1313# Load the sim time file and extract the seconds */ 
    14 def getSimTime(): 
     14def getSimTime(path): 
    1515    global seconds     
    16     with open ("webapps/dynamicdata/sim_elapsedtime.json", 'r') as myfile: 
     16    with open (path+"sim_elapsedtime.json", 'r') as myfile: 
    1717        jsonData=myfile.read() 
    1818    try:      
     
    3737    config.read(configdir + '/logging_service.cfg') 
    3838    logfilepath  = config.get('Paths', 'UnifiedLogPath') 
    39      
     39 
    4040    # Delete any previously existing output file 
    4141    f = open(logfilepath + outputFilename, "w") 
     
    4949        setupfunc = getattr(plugmodule, 'setup') 
    5050        #Call setup 
    51         setupfunc() 
     51        setupfunc(configdir) 
    5252    #END LOOP 
    5353     
     
    5555    while True: 
    5656    #    Get simulation time 
    57         timeStamp = getSimTime() 
     57        timeStamp = getSimTime(logfilepath) 
    5858    #    Reset Output Buffer 
    5959        output = "" 
     
    6666             
    6767    #        Run the plugin process returning new log entries 
    68             results = getfunc()      
     68            results = getfunc() 
    6969    #       Append simulation time and the log entries to the Output Buffer 
    7070            for item in results: 
     
    8787#END DO 
    8888 
    89 # for unit testing 
     89# Entry point for application 
    9090if __name__ == '__main__': 
    9191    startup(sys.argv) 
Note: See TracChangeset for help on using the changeset viewer.