Ejemplo n.º 1
0
def load_index(cache_file):
    """
    Return a LicenseIndex loaded from cache.
    """
    from licensedcode.index import LicenseIndex
    with open(cache_file, 'rb') as ifc:
        # Note: weird but read() + loads() is much (twice++???) faster than load()
        try:
            return LicenseIndex.load(ifc)
        except Exception as e:
            msg = (
                'ERROR: Failed to load license cache (the file may be corrupted ?).\n'
                f'Please delete "{cache_file}" and retry.\n'
                'If the problem persists, copy this error message '
                'and submit a bug report at https://github.com/nexB/scancode-toolkit/issues/'
            )
            raise Exception(msg) from e
Ejemplo n.º 2
0
def load_index(cache_file, use_loads=False):
    """
    Return a LicenseIndex loaded from cache.
    """
    from licensedcode.index import LicenseIndex
    with open(cache_file, 'rb') as ifc:
        # Note: weird but read() + loads() is much (twice++???) faster than load()
        try:
            if use_loads:
                return LicenseIndex.loads(ifc.read())
            else:
                return LicenseIndex.load(ifc)
        except Exception as e:
            import traceback
            msg = (
                '\n'
                'ERROR: Failed to load license cache (the file may be corrupted ?).\n'
                'Please delete "{cache_file}" and retry.\n'
                'If the problem persists, copy this error message '
                'and submit a bug report.\n'.format(**locals()))
            msg += '\n' + traceback.format_exc()
            raise Exception(msg)
Ejemplo n.º 3
0
def load_index(cache_file, use_loads=False):
    """
    Return a LicenseIndex loaded from cache.
    """
    from licensedcode.index import LicenseIndex
    with open(cache_file, 'rb') as ifc:
        # Note: weird but read() + loads() is much (twice++???) faster than load()
        try:
            if use_loads:
                return LicenseIndex.loads(ifc.read())
            else:
                return LicenseIndex.load(ifc)
        except:
            ex_type, ex_msg, ex_traceback = sys.exc_info()
            message = (
                str(ex_msg) +
                '\nERROR: Failed to load license cache (the file may be corrupted ?).\n'
                'Please delete "{cache_file}" and retry.\n'
                'If the problem persists, copy this error message '
                'and submit a bug report.\n'.format(**locals()))
            if py3:
                raise ex_type(message).with_traceback(ex_traceback)
            else:
                six.reraise(ex_type, message, ex_traceback)