| Revision 439,
1.5 KB
checked in by jdalbey, 7 years ago
(diff) |
|
setup wing project for logging service python files. Add config file for file paths.
|
| Line | |
|---|
| 1 | import json, time |
|---|
| 2 | from 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 | |
|---|
| 12 | lastLineNum = 0 |
|---|
| 13 | |
|---|
| 14 | # Utility functions |
|---|
| 15 | def isEmpty(cmsitem): |
|---|
| 16 | return cmsitem == ",,,,," |
|---|
| 17 | def isFull(cmsitem): |
|---|
| 18 | return not isEmpty(cmsitem) |
|---|
| 19 | |
|---|
| 20 | # Read the cad comments log |
|---|
| 21 | def readFile(): |
|---|
| 22 | lines = [] |
|---|
| 23 | try: |
|---|
| 24 | text_file = open("CADcomments.log", "r") |
|---|
| 25 | except IOError: |
|---|
| 26 | print "Error: missing CADcomments.log file." |
|---|
| 27 | else: |
|---|
| 28 | lines = text_file.read().split('\n') |
|---|
| 29 | text_file.close() |
|---|
| 30 | return lines |
|---|
| 31 | |
|---|
| 32 | def setup(): |
|---|
| 33 | # nothing needed for setup |
|---|
| 34 | return |
|---|
| 35 | |
|---|
| 36 | # Retrieve new messages from CAD comment log |
|---|
| 37 | def getLogEntries(): |
|---|
| 38 | global lastLineNum |
|---|
| 39 | msgList = readFile() |
|---|
| 40 | currList = [] |
|---|
| 41 | currList = msgList[lastLineNum:] # new items since last file read |
|---|
| 42 | lastLineNum = len(msgList)-1 |
|---|
| 43 | return currList |
|---|
| 44 | |
|---|
| 45 | # Local main for unit testing |
|---|
| 46 | def main(): |
|---|
| 47 | setup() |
|---|
| 48 | # Loop Forever, checking every five seconds |
|---|
| 49 | while True: |
|---|
| 50 | # Look for new messages |
|---|
| 51 | answer = getLogEntries() |
|---|
| 52 | # Output results |
|---|
| 53 | for item in answer: |
|---|
| 54 | print item |
|---|
| 55 | # wait |
|---|
| 56 | time.sleep(5) |
|---|
| 57 | |
|---|
| 58 | if __name__ == "__main__": |
|---|
| 59 | main() |
|---|
Note: See
TracBrowser
for help on using the repository browser.