예제 #1
0
def load_lib():
    """
    Return the loaded libmagic shared library object from plugin provided or
    default "vendored" paths.
    """
    # get paths from plugins
    dll = get_location(TYPECODE_LIBMAGIC_DLL)
    libdir = get_location(TYPECODE_LIBMAGIC_LIBDIR)
    return command.load_shared_library(dll, libdir)
예제 #2
0
def load_lib():
    """
    Return the loaded libarchive shared library object from plugin provided or
    default "vendored" paths.
    """
    # get paths from plugins
    dll = get_location(EXTRACTCODE_LIBARCHIVE_DLL)
    libdir = get_location(EXTRACTCODE_LIBARCHIVE_LIBDIR)
    return command.load_shared_library(dll, libdir)
예제 #3
0
def load_lib():
    """
    Return the loaded libarchive shared library object from plugin-provided path.
    """
    from plugincode.location_provider import get_location

    # get paths from plugins
    dll = get_location(EXTRACTCODE_LIBARCHIVE_DLL)
    libdir = get_location(EXTRACTCODE_LIBARCHIVE_LIBDIR)
    return command.load_shared_library(dll, libdir)
예제 #4
0
def load_lib():
    """
    Return the libmagic shared library object loaded from either:
    - an environment variable ``TYPECODE_LIBMAGIC_PATH``
    - a plugin-provided path,
    - the system PATH.
    Raise an NoMagicLibError if no libmagic can be found.
    """
    from plugincode.location_provider import get_location

    # try the environment first
    dll_loc = os.environ.get(TYPECODE_LIBMAGIC_PATH_ENVVAR)

    if TRACE and dll_loc:
        logger_debug('load_lib:', 'got environ magic location:', dll_loc)

    # try a plugin-provided path second
    if not dll_loc:
        dll_loc = get_location(TYPECODE_LIBMAGIC_DLL)

        if TRACE and dll_loc:
            logger_debug('load_lib:', 'got plugin magic location:', dll_loc)

    # try well known locations
    if not dll_loc:
        failover_lib = load_lib_failover()
        if failover_lib:
            warnings.warn(
                'System libmagic found in typical location is used. '
                'Install instead a typecode-libmagic plugin for best support.')
            return failover_lib

    # try the PATH
    if not dll_loc:
        dll = 'libmagic.dll' if on_windows else 'libmagic.so'
        dll_loc = command.find_in_path(dll)

        if dll_loc:
            warnings.warn(
                'libmagic found in the PATH. '
                'Install instead a typecode-libmagic plugin for best support.')

        if TRACE and dll_loc:
            logger_debug('load_lib:', 'got path magic location:', dll_loc)

    if not dll_loc or not os.path.isfile(dll_loc):
        raise NoMagicLibError(
            'CRITICAL: libmagic DLL and its magic database are not installed. '
            'Unable to continue: you need to install a valid typecode-libmagic '
            'plugin with a valid and proper libmagic and magic DB available.\n'
            f'OR set the {TYPECODE_LIBMAGIC_PATH_ENVVAR} and '
            f'{TYPECODE_LIBMAGIC_DB_PATH_ENVVAR} environment variables.\n'
            f'OR install libmagic in typical common locations.\n'
            f'OR have a libmagic in the system PATH.\n')
    return command.load_shared_library(dll_loc)
예제 #5
0
def load_lib():
    """
    Return the loaded libmagic shared library object from plugin provided or
    default "vendored" paths.
    """
    # get paths from plugins
    dll = get_location(TYPECODE_LIBMAGIC_DLL)
    libdir = get_location(TYPECODE_LIBMAGIC_LIBDIR)
    if not (dll and libdir) or not os.path.isfile(dll) or not os.path.isdir(libdir):
        raise Exception(
            'CRITICAL: libmagic DLL and is magic database are not installed. '
            'Unable to continue: you need to install a valid typecode-libmagic '
            'plugin with a valid and proper libmagic and magic DB available.'
    )
    return command.load_shared_library(dll, libdir)