Changeset 467 in tmcsimulator for trunk/src/python


Ignore:
Timestamp:
07/27/2019 08:23:36 PM (7 years ago)
Author:
jdalbey
Message:

cad_watcher.py added more elaborate error handling to cope with missing or empty CADcomments.log. Hopefully fixes #177.

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

Legend:

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

    r466 r467  
    1 import json, time, ConfigParser 
     1import json, time, ConfigParser, os 
    22from copy import deepcopy 
    33 
     
    1818    return not isEmpty(cmsitem) 
    1919 
    20 # Read the cad comments log  
    21 def readFile(): 
    22     # get path to input file from configuration 
    23     config = ConfigParser.ConfigParser() 
    24     config.read('config/logging_service.cfg') 
    25     logfilepath  = config.get('Paths', 'UnifiedLogPath') 
    26      
    27     lines = [] 
    28     try: 
    29         text_file = open(logfilepath + "CADcomments.log", "r") 
    30     except IOError: 
    31         print "Error: missing "+logfilepath+"CADcomments.log file." 
    32     else: 
    33         lines = text_file.read().split('\n') 
    34         text_file.close()     
    35     return lines 
    36      
    3720def setup(): 
    3821    lastLineNum = 0 
     
    4225def getLogEntries(): 
    4326    global lastLineNum 
    44     msgList = readFile() 
    45     currList = [] 
    46     currList = msgList[lastLineNum:]    # new items since last file read 
    47     lastLineNum = len(msgList)-1 
    48     return currList 
     27    # get path to input file from configuration 
     28    config = ConfigParser.ConfigParser() 
     29    config.read('config/logging_service.cfg') 
     30    logfilepath  = config.get('Paths', 'UnifiedLogPath') 
     31    pathToLog = logfilepath + "CADcomments.log" 
     32     
     33    try: 
     34        text_file = open(pathToLog, "r") 
     35    except IOError as ex: 
     36        if ex.errno == 2: 
     37            # 'No such file or directory 
     38            print pathToLog + " missing: assuming reset" 
     39            lastLineNum = 0   #Start over 
     40            return [] 
     41        else: 
     42            print "IOError reading "+pathToLog+" file." 
     43            print "errno: ",ex.errno 
     44             
     45    else: 
     46        # Check file size 
     47        fileSize = os.path.getsize(pathToLog) 
     48        if fileSize == 0: 
     49            # Assume this is a read sync problem: Don't modify lastLineNum 
     50            print pathToLog+" is empty." 
     51            return [] 
     52        else: # file is good, read it. 
     53            msgList = text_file.read().split('\n') 
     54            text_file.close() 
     55            currList = [] 
     56            currList = msgList[lastLineNum:] # new items since last file read 
     57            lastLineNum = len(msgList)-1 
     58            return currList 
    4959 
    5060# Local main for unit testing 
  • trunk/src/python/unifiedlogger/wing_project.wpr

    r466 r467  
    8585        'current_pages': [3, 
    8686                          1], 
    87         'notebook_display': 'normal', 
     87        'notebook_display': 'hidden', 
    8888        'notebook_percent': 0.30000000000000004, 
    8989        'override_title': None, 
     
    187187                            20)], 
    188188         'code-line': '                trimmed_item = item.strip()\n', 
    189          'first-line': 39L, 
     189         'first-line': 50L, 
    190190         'folded-linenos': [], 
    191191         'sel-line': 57L, 
     
    194194         'selection_start': 1955L, 
    195195         'zoom': 0L}, 
    196         1563915837.345044], 
    197         [loc('activitylog_watcher.py'), 
    198          {'attrib-starts': [('getLogEntries|0|', 
    199                              42)], 
    200           'code-line': '    return currList\n', 
    201           'first-line': 37L, 
    202           'folded-linenos': [], 
    203           'sel-line': 48L, 
    204           'sel-line-start': 1427L, 
    205           'selection_end': 1427L, 
    206           'selection_start': 1427L, 
    207           'zoom': 0L}, 
    208          1563915839.151954], 
    209         [loc('logging_service.py'), 
    210          {'attrib-starts': [('startup|0|', 
    211                              20)], 
    212           'code-line': '                trimmed_item = item.strip()\n', 
    213           'first-line': 50L, 
    214           'folded-linenos': [], 
    215           'sel-line': 57L, 
    216           'sel-line-start': 1955L, 
    217           'selection_end': 1955L, 
    218           'selection_start': 1955L, 
    219           'zoom': 0L}, 
    220          1563915884.294776], 
     196        1563915884.294776], 
    221197        [loc('activitylog_watcher.py'), 
    222198         {'attrib-starts': [('getLogEntries|0|', 
     
    423399          'selection_start': 1851L, 
    424400          'zoom': 0L}, 
    425          1564189539.194298]], 
     401         1564189539.194298], 
     402        [loc('cad_watcher.py'), 
     403         {'attrib-starts': [('setup|0|', 
     404                             41)], 
     405          'code-line': 'def setup():\n', 
     406          'first-line': 24L, 
     407          'folded-linenos': [], 
     408          'sel-line': 41L, 
     409          'sel-line-start': 1329L, 
     410          'selection_end': 1329L, 
     411          'selection_start': 1329L, 
     412          'zoom': 0L}, 
     413         1564287471.970187], 
     414        [loc('../../../../../../../../usr/lib/python2.7/genericpath.py'), 
     415         {'attrib-starts': [('getsize|0|', 
     416                             54)], 
     417          'code-line': '    return os.stat(filename).st_size\n', 
     418          'first-line': 39L, 
     419          'folded-linenos': [], 
     420          'sel-line': 56L, 
     421          'sel-line-start': 1506L, 
     422          'selection_end': 1506L, 
     423          'selection_start': 1506L, 
     424          'zoom': 0L}, 
     425         1564287481.404096]], 
    426426        20), 
    427427        'current-loc': loc('cad_watcher.py'), 
     
    438438                                'zoom': 0L}), 
    439439                              (loc('cad_watcher.py'), 
    440                                {'attrib-starts': [], 
    441                                 'code-line': 'lastLineNum = 0\n', 
    442                                 'first-line': 33L, 
     440                               {'attrib-starts': [('getLogEntries|0|', 
     441        24)], 
     442                                'code-line': "            msgList = text_fil"\ 
     443        "e.read().split('\\n')\n", 
     444                                'first-line': 29L, 
    443445                                'folded-linenos': [], 
    444                                 'sel-line': 11L, 
    445                                 'sel-line-start': 417L, 
    446                                 'selection_end': 432L, 
    447                                 'selection_start': 432L, 
     446                                'sel-line': 52L, 
     447                                'sel-line-start': 1613L, 
     448                                'selection_end': 1613L, 
     449                                'selection_start': 1613L, 
    448450                                'zoom': 0L}), 
    449451                              (loc('cms_watcher.py'), 
     
    500502         loc('__main__.py')]), 
    501503                               'open_files': [u'../../../config/logging_service.cfg', 
     504        u'__main__.py', 
    502505        u'activitylog_watcher.py', 
    503506        u'cms_watcher.py', 
    504         u'__main__.py', 
    505507        u'logging_service.py', 
    506508        u'cad_watcher.py']}, 
     
    511513        'traversal_pos': ((0, 
    512514                           3), 
    513                           1564183253.966105), 
     515                          1564287665.60169), 
    514516        'user_data': {}}, 
    515517                 'saved_notebook_display': None, 
     
    519521                 'traversal_pos': ((0, 
    520522                                    4), 
    521                                    1564183317.08295), 
     523                                   1564289756.891358), 
    522524                 'user_data': {}}, 
    523525        'window-alloc': (29, 
     
    575577        'selection_start': 22028L, 
    576578        'zoom': 0L}, 
     579                       loc('../../../../../../../../usr/lib/python2.7/genericpath.py'): {'a'\ 
     580        'ttrib-starts': [('getsize|0|', 
     581                          54)], 
     582        'code-line': '    return os.stat(filename).st_size\n', 
     583        'first-line': 39L, 
     584        'folded-linenos': [], 
     585        'sel-line': 56L, 
     586        'sel-line-start': 1506L, 
     587        'selection_end': 1506L, 
     588        'selection_start': 1506L, 
     589        'zoom': 0L}, 
    577590                       loc('../../../../../../../../usr/lib/python2.7/json/decoder.py'): {'a'\ 
    578591        'ttrib-starts': [('JSONDecoder|0|', 
Note: See TracChangeset for help on using the changeset viewer.