Esempio n. 1
0
def get_installed_extension_data():
    """
    Returns a list of all UI and Library extensions (not parsed) that are installed and active.

    Returns:
        list: list of components.Extension or components.LibraryExtension objects
    """
    # fixme: reorganzie this code to use one single method to collect extension data for both lib and ui
    ext_data_list = []

    for root_dir in user_config.get_ext_root_dirs():
        ext_data_list.extend(
            [ui_ext for ui_ext in parse_dir_for_ext_type(root_dir, Extension)])
        ext_data_list.extend([
            lib_ext
            for lib_ext in parse_dir_for_ext_type(root_dir, LibraryExtension)
        ])

    return _remove_disabled_extensions(ext_data_list)
Esempio n. 2
0
def get_installed_ui_extensions():
    """
    Returns a list of all UI extensions (fully parsed) under the given
    directory. This will also process the Library extensions and will add
    their path to the syspath of the UI extensions.

    Returns:
        list: list of components.Extension objects
    """
    ui_ext_list = list()
    lib_ext_list = list()

    # get a list of all directories that could include extensions
    ext_search_dirs = user_config.get_ext_root_dirs()
    logger.debug('Extension Directories: {}'.format(ext_search_dirs))

    # collect all library extensions. Their dir paths need to be added
    # to sys.path for all commands
    for root_dir in ext_search_dirs:
        lib_ext_list.extend(get_installed_lib_extensions(root_dir))
        # Get a list of all installed extensions in this directory
        # _parser.parse_dir_for_ext_type() returns a list of extensions
        # in given directory

    for root_dir in ext_search_dirs:
        for ext_info in parse_dir_for_ext_type(root_dir, Extension):
            # test if cache is valid for this ui_extension
            # it might seem unusual to create a ui_extension and then
            # re-load it from cache but minimum information about the
            # ui_extension needs to be passed to the cache module for proper
            # hash calculation and ui_extension recovery. at this point
            # `ui_extension` does not include any sub-components
            # (e.g, tabs, panels, etc) ui_extension object is very small and
            # its creation doesn't add much overhead.

            if _is_extension_enabled(ext_info):
                ui_extension = _parse_or_cache(ext_info)
                ui_ext_list.append(ui_extension)
            else:
                logger.info('Skipping disabled ui extension: {}'.format(
                    ext_info.name))

    # update extension master syspaths with standard pyrevit lib paths and
    # lib address of other lib extensions (to support extensions that provide
    # library only to be used by other extensions)
    # all other lib paths internal to the extension and tool bundles have
    # already been set inside the extension bundles and will take precedence
    # over paths added by this method (they're the first paths added to the
    # search paths list, and these paths will follow)
    for ui_extension in ui_ext_list:
        _update_extension_syspaths(ui_extension, lib_ext_list, [
            PYTHON_LIB_DIR, PYTHON_LIB_SITEPKGS_DIR, MAIN_LIB_DIR, MISC_LIB_DIR
        ])

    return ui_ext_list
Esempio n. 3
0
def get_installed_lib_extensions(root_dir):
    """
    Returns a list of all Library extensions (not parsed)
    under the given directory that are installed and active.

    Args:
        root_dir (str): Extensions directory address

    Returns:
        list: list of components.LibraryExtension objects
    """
    lib_ext_list = \
        [lib_ext for lib_ext in parse_dir_for_ext_type(root_dir,
                                                       LibraryExtension)]
    return _remove_disabled_extensions(lib_ext_list)
Esempio n. 4
0
def get_installed_ui_extensions():
    """
    Returns a list of all UI extensions (fully parsed) under the given directory. This will also process the
    Library extensions and will add their path to the syspath of the UI extensions.

    Returns:
        list: list of components.Extension objects
    """
    ui_ext_list = list()
    lib_ext_list = list()

    # get a list of all directories that could include extensions
    ext_search_dirs = user_config.get_ext_root_dirs()
    logger.debug('Extension Directories: {}'.format(ext_search_dirs))

    # collect all library extensions. Their dir paths need to be added to sys.path for all commands
    for root_dir in ext_search_dirs:
        lib_ext_list.extend(get_installed_lib_extensions(root_dir))
        # Get a list of all installed extensions in this directory
        # _parser.parse_dir_for_ext_type() returns a list of extensions in given directory

    for root_dir in ext_search_dirs:
        for ext_info in parse_dir_for_ext_type(root_dir, Extension):
            # test if cache is valid for this ui_extension
            # it might seem unusual to create a ui_extension and then re-load it from cache but minimum information
            # about the ui_extension needs to be passed to the cache module for proper hash calculation and
            # ui_extension recovery. at this point `ui_extension` does not include any sub-components
            #  (e.g, tabs, panels, etc) ui_extension object is very small and its creation doesn't add much overhead.

            if _is_extension_enabled(ext_info):
                ui_extension = _parse_or_cache(ext_info)
                ui_ext_list.append(ui_extension)
            else:
                logger.info('Skipping disabled ui extension: {}'.format(
                    ext_info.name))

    # update extension master syspaths with lib address of other lib extensions
    # this is to support extensions that provide library only to be used by other extensions
    for ui_extension in ui_ext_list:
        _update_extension_syspaths(ui_extension, lib_ext_list)

    return ui_ext_list