예제 #1
0
    def _get_lief_version(cls, lief: LiefElfModuleT) -> PkgVersion:
        lief_ver_str_meta = None
        lief_ver_str_tag = None
        lief_ver_str_dunder = None

        with suppress_ex(Exception):
            return pkg_resources.get_distribution('lief').parsed_version

        if hasattr(lief, '__tag__'):
            with suppress_ex(Exception):
                lief_ver_str_tag = lief.__tag__
                return PkgVersion(lief_ver_str_tag)

        if hasattr(lief, '__version__'):
            with suppress_ex(Exception):
                lief_ver_str_dunder = lief.__version__
                return PkgVersion(lief_ver_str_tag)

        if lief_ver_str_dunder:
            with suppress_ex(Exception):
                lief_ver_str_dunder = lief_ver_str_dunder.partition('-')[0]
                return PkgVersion(lief_ver_str_dunder)

        if lief_ver_str_meta:
            with suppress_ex(Exception):
                lief_ver_str_meta = lief_ver_str_meta.partition('-')[0]
                return PkgVersion(lief_ver_str_meta)

        return None
 def _generic_new(base_cls, cls, *args,
                  **kwds):  # noqa: ANN001,ANN002,ANN003,ANN202
     if cls.__origin__ is None:
         return base_cls.__new__(cls)
     else:
         origin = _gorg(cls)
         obj = base_cls.__new__(origin)
         with suppress_ex(AttributeError):
             obj.__orig_class__ = cls
         obj.__init__(*args, **kwds)
         return obj
예제 #3
0
def augment_module_search_paths(
        options: Optional[PackagerOptionsBase] = None) -> NoReturn:
    if not options:
        pass
    elif options.irods_scripts_dir:
        script_common.irods_scripts_dir = options.irods_scripts_dir
    elif options.irods_package_prefix:
        if path.isabs(options.irods_home_dir):
            script_common.irods_scripts_dir = path.join(
                options.irods_package_prefix, options.irods_home_dir[1:],
                'scripts')
        else:
            script_common.irods_scripts_dir = path.join(
                options.irods_package_prefix, options.irods_home_dir,
                'scripts')
    else:
        script_common.irods_scripts_dir = path.join(
            options.irods_install_prefix, options.irods_home_dir, 'scripts')

    if not path.isabs(script_common.irods_scripts_dir):
        raise OSError(errno.EINVAL,
                      'irods_scripts_dir is not an absolute path',
                      script_common.irods_scripts_dir)
    if not path.exists(script_common.irods_scripts_dir):
        raise OSError(errno.ENOENT, 'irods_scripts_dir not found',
                      script_common.irods_scripts_dir)
    if not path.isdir(script_common.irods_scripts_dir):
        raise OSError(errno.ENOTDIR, 'irods_scripts_dir is not a directory',
                      script_common.irods_scripts_dir)

    # If the irods script dir is already in the search paths, do nothing
    for searchpath in sys.path:
        with suppress_ex(OSError):
            if path.samefile(searchpath, script_common.irods_scripts_dir):
                return

    sys.path.insert(1, script_common.irods_scripts_dir)