| Revision 433,
1.0 KB
checked in by jdalbey, 7 years ago
(diff) |
|
Unified Logger v1.0. Add cad watcher plugin to logging service.
|
| 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 | # jdalbey 7/6/2019 |
|---|
| 7 | |
|---|
| 8 | lastLineNum = 0 |
|---|
| 9 | |
|---|
| 10 | # Utility functions |
|---|
| 11 | def isEmpty(cmsitem): |
|---|
| 12 | return cmsitem == ",,,,," |
|---|
| 13 | def isFull(cmsitem): |
|---|
| 14 | return not isEmpty(cmsitem) |
|---|
| 15 | |
|---|
| 16 | # Read the cms message file |
|---|
| 17 | def readFile(): |
|---|
| 18 | text_file = open("../../CADcomments.log", "r") |
|---|
| 19 | lines = text_file.read().split('\n') |
|---|
| 20 | return lines |
|---|
| 21 | |
|---|
| 22 | def setup(): |
|---|
| 23 | # nothing needed for setup |
|---|
| 24 | return |
|---|
| 25 | |
|---|
| 26 | # Retrieve new messages from CAD comment log |
|---|
| 27 | def getLogEntries(): |
|---|
| 28 | global lastLineNum |
|---|
| 29 | msgList = readFile() |
|---|
| 30 | currList = [] |
|---|
| 31 | currList = msgList[lastLineNum:] # new items since last file read |
|---|
| 32 | lastLineNum = len(msgList)-1 |
|---|
| 33 | return currList |
|---|
| 34 | |
|---|
| 35 | def main(): |
|---|
| 36 | setup() |
|---|
| 37 | # Loop Forever |
|---|
| 38 | while True: |
|---|
| 39 | # Look for changed messages |
|---|
| 40 | answer = getLogEntries() |
|---|
| 41 | # Output results |
|---|
| 42 | for item in answer: |
|---|
| 43 | print item |
|---|
| 44 | # wait |
|---|
| 45 | time.sleep(5) |
|---|
| 46 | |
|---|
| 47 | if __name__ == "__main__": |
|---|
| 48 | main() |
|---|
Note: See
TracBrowser
for help on using the repository browser.