ooiservices/app/main/alertsalarms_tools.py
def _compile_asset_rds():
    """ Retrieve asset_ids from uframe for all reference designators referenced in /sensor/inv/toc structure;
    return dictionary with key of asset_id. On error, log and raise exception.
    Note:
        - All reference designators are determined from toc structure and not just what /sensor/inv/toc provides.
        - The original toc response format was a list of dicts; the more recent (May 2016) toc format is a dict.
        - This function has been updated to handle both the original toc list format and newer toc dict format.
    """
    result = {}
    try:
        # Get contents of /sensor/inv/toc
        toc = get_toc_information()

        # If toc is of type dict, then processing newer style toc format
        if isinstance(toc, dict):
            message = 'Using new TOC structure.'
            current_app.logger.info(message)
            if 'instruments' not in toc:
                message = 'TOC does not have attribute \'instruments\', unable to process for reference designators.'
                raise Exception(message)

            # Verify toc attribute 'instruments' is not None or empty, if so, raise Exception.
            toc = toc['instruments']
            if not toc or toc is None:
                message = 'TOC attribute \'instruments\' is None or empty, unable to process for reference designators.'
                raise Exception(message)

        # Process toc to get lists of:
        # (1) reference designators (generated by accumulation),
        # (2) actual reference designators called out in each element of toc response,
        # (3)list of differences
        uframe_url, timeout, timeout_read = get_uframe_assets_info()
        reference_designators, toc_only, difference = process_toc_information_reference_designators(toc)
        if not reference_designators:
            message = 'No reference_designators identified when processing toc information.'
            raise Exception(message)

        #print '\n debug ***** Number of reference designators from toc: ', len(reference_designators)
        if reference_designators and toc_only:
            for rd in reference_designators:
                if rd:
                    try:
                        ids = get_asset_id_by_reference_designator(rd, uframe_url, timeout, timeout_read)
                    except Exception as err:
                        message = 'Exception raised in get_asset_id_by_reference_designator: %s' % err.message
                        raise Exception(message)
                    if ids:
                        ids.sort()
                        for id in ids:
                            if id not in result:
                                result[id] = rd

        list_of_ids = []
        if result:
            list_of_ids = result.keys()
            if list_of_ids:
                list_of_ids.sort()
        return result, list_of_ids

    except ConnectionError:
        message = 'ConnectionError for _compile_asset_rds'
        current_app.logger.info(message)
        return {}, []
    except Timeout:
        message = 'Timeout for _compile_asset_rds'
        current_app.logger.info(message)
        return {}, []
    except Exception as err:
        message = err.message
        current_app.logger.info(message)
        return {}, []
 Retrieve asset_ids from uframe for all reference designators referenced in /sensor/inv/toc structure;
    return dictionary with key of asset_id. On error, log and raise exception.
    Note:
        - All reference designators are determined from toc structure and not just what /sensor/inv/toc provides.
        - The original toc response format was a list of dicts; the more recent (May 2016) toc format is a dict.
        - This function has been updated to handle both the original toc list format and newer toc dict format.
    
Retrieve asset_ids from uframe for all reference designators referenced in /sensor/inv/toc structure;
return dictionary with key of asset_id. On error, log and raise exception.
Note:
All reference designators are determined from toc structure and not just what /sensor/inv/toc provides.
The original toc response format was a list of dicts; the more recent (May 2016) toc format is a dict.
This function has been updated to handle both the original toc list format and newer toc dict format.
Retrieve asset_ids from uframe for all reference designators referenced in / sensor / inv / toc structure ; return dictionary with key of asset_id . On error log and raise exception . Note : All reference designators are determined from toc structure and not just what / sensor / inv / toc provides . The original toc response format was a list of dicts ; the more recent ( May 2016 ) toc format is a dict . This function has been updated to handle both the original toc list format and newer toc dict format .
def _compile_asset_rds():
    result = {}
    try:
        toc = get_toc_information()
        if isinstance(toc, dict):
            message = 'Using new TOC structure.'
            current_app.logger.info(message)
            if 'instruments' not in toc:
                message = 'TOC does not have attribute \'instruments\', unable to process for reference designators.'
                raise Exception(message)
            toc = toc['instruments']
            if not toc or toc is None:
                message = 'TOC attribute \'instruments\' is None or empty, unable to process for reference designators.'
                raise Exception(message)
        uframe_url, timeout, timeout_read = get_uframe_assets_info()
        reference_designators, toc_only, difference = process_toc_information_reference_designators(toc)
        if not reference_designators:
            message = 'No reference_designators identified when processing toc information.'
            raise Exception(message)
        if reference_designators and toc_only:
            for rd in reference_designators:
                if rd:
                    try:
                        ids = get_asset_id_by_reference_designator(rd, uframe_url, timeout, timeout_read)
                    except Exception as err:
                        message = 'Exception raised in get_asset_id_by_reference_designator: %s' % err.message
                        raise Exception(message)
                    if ids:
                        ids.sort()
                        for id in ids:
                            if id not in result:
                                result[id] = rd
        list_of_ids = []
        if result:
            list_of_ids = result.keys()
            if list_of_ids:
                list_of_ids.sort()
        return result, list_of_ids
    except ConnectionError:
        message = 'ConnectionError for _compile_asset_rds'
        current_app.logger.info(message)
        return {}, []
    except Timeout:
        message = 'Timeout for _compile_asset_rds'
        current_app.logger.info(message)
        return {}, []
    except Exception as err:
        message = err.message
        current_app.logger.info(message)
        return {}, []
def _compile_asset_rds ( ) : result = { } try : toc = get_toc_information ( ) if isinstance ( toc , dict ) : message = 'Using new TOC structure.' current_app . logger . info ( message ) if 'instruments' not in toc : message = 'TOC does not have attribute \'instruments\', unable to process for reference designators.' raise Exception ( message ) toc = toc [ 'instruments' ] if not toc or toc is None : message = 'TOC attribute \'instruments\' is None or empty, unable to process for reference designators.' raise Exception ( message ) uframe_url , timeout , timeout_read = get_uframe_assets_info ( ) reference_designators , toc_only , difference = process_toc_information_reference_designators ( toc ) if not reference_designators : message = 'No reference_designators identified when processing toc information.' raise Exception ( message ) if reference_designators and toc_only : for rd in reference_designators : if rd : try : ids = get_asset_id_by_reference_designator ( rd , uframe_url , timeout , timeout_read ) except Exception as err : message = 'Exception raised in get_asset_id_by_reference_designator: %s' % err . message raise Exception ( message ) if ids : ids . sort ( ) for id in ids : if id not in result : result [ id ] = rd list_of_ids = [ ] if result : list_of_ids = result . keys ( ) if list_of_ids : list_of_ids . sort ( ) return result , list_of_ids except ConnectionError : message = 'ConnectionError for _compile_asset_rds' current_app . logger . info ( message ) return { } , [ ] except Timeout : message = 'Timeout for _compile_asset_rds' current_app . logger . info ( message ) return { } , [ ] except Exception as err : message = err . message current_app . logger . info ( message ) return { } , [ ]
Retrieve asset_ids from uframe for all reference designators referenced in /sensor/inv/toc structure;
return dictionary with key of asset_id.
Retrieve asset_ids from uframe for all reference designators referenced in / sensor / inv / toc structure ; return dictionary with key of asset_id .
""" Retrieve asset_ids from uframe for all reference designators referenced in /sensor/inv/toc structure;
    return dictionary with key of asset_id. On error, log and raise exception.
    Note:
        - All reference designators are determined from toc structure and not just what /sensor/inv/toc provides.
        - The original toc response format was a list of dicts; the more recent (May 2016) toc format is a dict.
        - This function has been updated to handle both the original toc list format and newer toc dict format.
    """ # Get contents of /sensor/inv/toc # If toc is of type dict, then processing newer style toc format # Verify toc attribute 'instruments' is not None or empty, if so, raise Exception. # Process toc to get lists of: # (1) reference designators (generated by accumulation), # (2) actual reference designators called out in each element of toc response, # (3)list of differences #print '\n debug ***** Number of reference designators from toc: ', len(reference_designators)