Changeset 687 in tmcsimulator for trunk/src/python
- Timestamp:
- 10/02/2022 10:32:42 AM (4 years ago)
- Location:
- trunk/src/python/unifiedlogger
- Files:
-
- 5 edited
-
activitylog_watcher.py (modified) (4 diffs)
-
cad_watcher.py (modified) (3 diffs)
-
cms_watcher.py (modified) (5 diffs)
-
har_watcher.py (modified) (5 diffs)
-
logging_service.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/python/unifiedlogger/activitylog_watcher.py
r647 r687 34 34 file1length = 0 35 35 file2length = 0 36 configdir = "config" # default dir for production 36 37 37 38 # Utility functions … … 42 43 # get path to input file from configuration 43 44 def getLogFilePath(): 45 global configdir 44 46 config = ConfigParser.ConfigParser() 45 config.read( 'config/logging_service.cfg')47 config.read(configdir+'/logging_service.cfg') 46 48 return config.get('Paths', 'ActivityLogPath') 47 49 … … 50 52 # jdalbey 2022.9.1 51 53 def getLogFilenames(): 54 global configdir 52 55 config = ConfigParser.ConfigParser() 53 config.read( 'config/logging_service.cfg')56 config.read(configdir+'/logging_service.cfg') 54 57 file1 = config.get('Files','ActivityLogDataFilename') 55 58 file2 = config.get('Files','ActivityLogSummaryFilename') … … 124 127 return resultList 125 128 126 def setup(): 127 # nothing needed for setup 129 def setup(dir): 130 global configdir 131 configdir = dir 128 132 return 129 133 130 134 # Local main for unit testing 131 135 def main(): 132 setup( )136 setup("config/devlinux") 133 137 # Loop Forever, checking every five seconds 134 138 while True: -
trunk/src/python/unifiedlogger/cad_watcher.py
r522 r687 11 11 12 12 lastLineNum = 0 13 configdir = "config" # default dir for production 13 14 14 def setup(): 15 def setup(dir): 16 global lastLineNum, configdir 15 17 lastLineNum = 0 18 configdir = dir 16 19 return 17 20 18 21 # Retrieve new messages from CAD comment log 19 22 def getLogEntries(): 20 global lastLineNum 23 global lastLineNum, configdir 21 24 # get path to input file from configuration 22 25 config = ConfigParser.ConfigParser() 23 config.read( 'config/logging_service.cfg')26 config.read(configdir+'/logging_service.cfg') 24 27 logfilepath = config.get('Paths', 'UnifiedLogPath') 25 28 pathToLog = logfilepath + "CADcomments.log" … … 29 32 except IOError as ex: 30 33 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 34 38 return [] 35 39 else: … … 41 45 fileSize = os.path.getsize(pathToLog) 42 46 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." 45 48 lastLineNum = 0 #Start over 46 49 return [] 47 50 else: # file is good, read it. 48 msgList = text_file.read().s plit('\n')51 msgList = text_file.read().strip().split('\n') 49 52 text_file.close() 50 53 currList = [] 51 54 currList = msgList[lastLineNum:] # new items since last file read 52 lastLineNum = len(msgList) -155 lastLineNum = len(msgList) 53 56 return currList 54 57 55 58 # Local main for unit testing 56 59 def main(): 57 setup( )60 setup("config/devlinux") 58 61 # Loop Forever, checking every five seconds 59 62 while True: -
trunk/src/python/unifiedlogger/cms_watcher.py
r549 r687 1 import json, time 1 import json, time, ConfigParser 2 2 from copy import deepcopy 3 3 … … 9 9 currList = [] # current messages 10 10 locationMap = {} # map of CMS ID's to locations 11 filepath = "webapps/dynamicdata" # default during development 11 12 12 13 # Utility functions … … 17 18 18 19 # Read the cms message file 19 def readFile(): 20 with open ("webapps/dynamicdata/cms_messages.json",'r') as myfile: 20 def readFile(): 21 global filepath 22 with open (filepath+"/cms_messages.json",'r') as myfile: 21 23 jsonData=myfile.read() 22 24 23 return json.loads(jsonData)['data']25 return json.loads(jsonData)['data'] 24 26 25 27 # Read the static file of cms locations and create a lookup map … … 56 58 msgList[idx]['cms']['message']['phase2']['Line3']) 57 59 58 def setup(): 59 extractMessages(initialize()) 60 def 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()) 60 68 61 69 # compare previous messages to current messages to look for changes … … 86 94 def main(): 87 95 global currList 88 setup( )96 setup("config/devlinux") 89 97 # Loop Forever 90 98 while True: -
trunk/src/python/unifiedlogger/har_watcher.py
r649 r687 1 import json, time 1 import json, time, ConfigParser 2 2 from copy import deepcopy 3 3 … … 9 9 currList = [] # current messages 10 10 locationMap = {} # map of HAR ID's to locations 11 filepath = "webapps/dynamicdata" # default during development 11 12 12 13 # Utility functions … … 17 18 18 19 # Read the har message file 19 def readFile(): 20 with open ("webapps/dynamicdata/har_messages.json",'r') as myfile: 20 def readFile(): 21 global filepath 22 with open (filepath+"/har_messages.json",'r') as myfile: 21 23 jsonData=myfile.read() 22 24 23 return json.loads(jsonData)['data']25 return json.loads(jsonData)['data'] 24 26 25 27 # Read the static file of cms locations and create a lookup map … … 51 53 currList.append(aMessage.replace("\n"," ").strip()) 52 54 53 def setup(): 54 extractMessages(initialize()) 55 def 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()) 55 63 56 64 # compare previous messages to current messages to look for changes … … 81 89 def main(): 82 90 global currList 83 setup( )91 setup("config/devlinux") 84 92 # Loop Forever 85 93 while True: -
trunk/src/python/unifiedlogger/logging_service.py
r683 r687 12 12 13 13 # Load the sim time file and extract the seconds */ 14 def getSimTime( ):14 def getSimTime(path): 15 15 global seconds 16 with open ( "webapps/dynamicdata/sim_elapsedtime.json", 'r') as myfile:16 with open (path+"sim_elapsedtime.json", 'r') as myfile: 17 17 jsonData=myfile.read() 18 18 try: … … 37 37 config.read(configdir + '/logging_service.cfg') 38 38 logfilepath = config.get('Paths', 'UnifiedLogPath') 39 39 40 40 # Delete any previously existing output file 41 41 f = open(logfilepath + outputFilename, "w") … … 49 49 setupfunc = getattr(plugmodule, 'setup') 50 50 #Call setup 51 setupfunc( )51 setupfunc(configdir) 52 52 #END LOOP 53 53 … … 55 55 while True: 56 56 # Get simulation time 57 timeStamp = getSimTime( )57 timeStamp = getSimTime(logfilepath) 58 58 # Reset Output Buffer 59 59 output = "" … … 66 66 67 67 # Run the plugin process returning new log entries 68 results = getfunc() 68 results = getfunc() 69 69 # Append simulation time and the log entries to the Output Buffer 70 70 for item in results: … … 87 87 #END DO 88 88 89 # for unit testing89 # Entry point for application 90 90 if __name__ == '__main__': 91 91 startup(sys.argv)
Note: See TracChangeset
for help on using the changeset viewer.
