def loadsdk(libname=None):
    if libname:
        logger.warning('Overriding C SDK location with %s', libname)
        if not path.isfile(libname):
            libname = _dll_name_in_home(libname)
    else:
        try:
            import pkg_resources
            libname = pkg_resources.resource_filename(__name__, dll_name())
        except Exception:  #pylint:disable=broad-except
            logger.warning(
                'Could not get native SDK path via pkg_resources:'
                ' loading native SDK library might fail',
                exc_info=sys.exc_info())
            thisdir = path.dirname(path.abspath(__file__))
            libname = path.join(thisdir, dll_name())

    try:
        logger.info('Loading native SDK library "%s".', libname)
        return SDKDllInterface(libname)
    except OSError as e:
        msg = 'Failed loading SDK stub from ' + libname + ': "' + str(e) + \
            '". Check your installation of the oneagent-sdk Python package,' + \
            ' e.g., try running ' + \
            '`pip install --verbose --force-reinstall oneagent-sdk`.'
        six.raise_from(SDKError(ErrorCode.LOAD_AGENT, msg), e)
def exec_chk(chk, arg):
    try:
        result = chk(arg)
        if result is not None and result is not True:
            raise ValueError('{} returned.'.format(result))
    except AssertionError:
        raise
    except Exception as e:
        six.raise_from(
            AssertionError('{!r}({!r}) failed: {}'.format(chk, arg, e)), e)
        raise  # Shut up pylint
    return result
def loadsdk(libname=None):
    if libname:
        logger.warning('Overriding C SDK location with %s', libname)
        if not path.isfile(libname):
            libname = _dll_name_in_home(libname)
    else:
        try:
            import pkg_resources
            libname = pkg_resources.resource_filename(__name__, dll_name())
        except ImportError:
            logger.warning(
                'Could not import pkg_resources module:'
                ' loading SDK native library might fail',
                exc_info=sys.exc_info())
            thisdir = path.dirname(path.abspath(__file__))
            libname = path.join(thisdir, dll_name())

    try:
        logger.info('Loading native sdk "%s".', libname)
        return SDKDllInterface(libname)
    except OSError as e:
        msg = 'Failed loading SDK stub from ' + libname + ': ' + str(e)
        six.raise_from(SDKError(ErrorCode.LOAD_AGENT, msg), e)