Ejemplo n.º 1
0
def get_ext_packages(authorized_only=True):
    """
    Reads the list of registered plug-in extensions and returns a list of
    ExtensionPackage classes which contain information on the plug-in extension.

    Returns:
        list: list of registered plugin extensions (ExtensionPackage)
    """
    global EXTENSION_PACKAGES

    if EXTENSION_PACKAGES:
        return EXTENSION_PACKAGES
    else:
        EXTENSION_PACKAGES = []
        for ext_dir in user_config.get_ext_root_dirs():
            ext_pkg_deffile = op.join(ext_dir, PLUGIN_EXT_DEF_FILE)
            if op.exists(ext_pkg_deffile):
                ext_def_file = _ExtensionPackageDefinitionFile(ext_pkg_deffile)
                if authorized_only:
                    auth_pkgs = [
                        x for x in ext_def_file.defined_ext_packages
                        if x.user_has_access
                    ]
                else:
                    auth_pkgs = ext_def_file.defined_ext_packages

                EXTENSION_PACKAGES.extend(auth_pkgs)

        return EXTENSION_PACKAGES
Ejemplo n.º 2
0
def get_ext_packages(authorized_only=True):
    """
    Reads the list of registered plug-in extensions and returns a list of
    ExtensionPackage classes which contain information on the
    plug-in extension.

    Returns:
        list: list of registered plugin extensions (ExtensionPackage)
    """
    extpkgs = []
    for ext_dir in user_config.get_ext_root_dirs():
        extpkg_deffile = op.join(ext_dir, PLUGIN_EXT_DEF_FILE)
        mlogger.debug('Looking for %s', extpkg_deffile)
        # check for external ext def file
        if op.exists(extpkg_deffile):
            mlogger.debug('Found %s', extpkg_deffile)
            _update_extpkgs(extpkg_deffile, extpkgs)
        # check internals now
        internal_extpkg_defs = _find_internal_extpkgs(ext_dir)
        for int_def_file in internal_extpkg_defs:
            _update_extpkgs(int_def_file, extpkgs)

    if authorized_only:
        return [x for x in extpkgs if x.user_has_access]

    return extpkgs
Ejemplo n.º 3
0
def get_ext_packages(authorized_only=True):
    """
    Reads the list of registered plug-in extensions and returns a list of
    ExtensionPackage classes which contain information on the
    plug-in extension.

    Returns:
        list: list of registered plugin extensions (ExtensionPackage)
    """
    extpkgs = []
    for ext_dir in user_config.get_ext_root_dirs():
        # make a list of all availabe extension definition sources
        # default is under the extensions directory that ships with pyrevit
        extpkg_def_files = {op.join(ext_dir, PLUGIN_EXT_DEF_FILE)}
        # add other sources added by the user (using the cli)
        extpkg_def_files.update(user_config.get_ext_sources())
        for extpkg_def_file in extpkg_def_files:
            mlogger.debug('Looking for %s', extpkg_def_file)
            # check for external ext def file
            if op.exists(extpkg_def_file):
                mlogger.debug('Found %s', extpkg_def_file)
                _update_extpkgs(extpkg_def_file, extpkgs)
            # check internals now
            internal_extpkg_defs = _find_internal_extpkgs(ext_dir)
            for int_def_file in internal_extpkg_defs:
                _update_extpkgs(int_def_file, extpkgs)

    if authorized_only:
        return [x for x in extpkgs if x.user_has_access]

    return extpkgs
Ejemplo 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 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
Ejemplo n.º 5
0
    def is_installed(self):
        """
        Returns:
            bool: Checked whether this extension is installed or not.
        """
        for ext_dir in user_config.get_ext_root_dirs():
            for sub_dir in os.listdir(ext_dir):
                if op.isdir(op.join(ext_dir,
                                    sub_dir)) and sub_dir == self.ext_dirname:
                    return op.join(ext_dir, sub_dir)

        return ''
Ejemplo n.º 6
0
    def is_installed(self):
        """
        Returns:
            bool: Checked whether this extension is installed or not.
        """
        for ext_dir in user_config.get_ext_root_dirs():
            if op.exists(ext_dir):
                for sub_dir in os.listdir(ext_dir):
                    if op.isdir(op.join(ext_dir, sub_dir))\
                            and sub_dir == self.ext_dirname:
                        return op.join(ext_dir, sub_dir)
            else:
                mlogger.error('custom Extension path does not exist: %s',
                              ext_dir)

        return ''
Ejemplo n.º 7
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)
Ejemplo n.º 8
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
Ejemplo n.º 9
0
def get_ext_packages():
    """
    Reads the list of registered plug-in extensions and returns a list of ExtensionPackage classes which contain
    information on the plug-in extension.

    Returns:
        list: list of registered plugin extensions (ExtensionPackage)
    """
    global EXTENSION_PACKAGES

    if EXTENSION_PACKAGES:
        return EXTENSION_PACKAGES
    else:
        EXTENSION_PACKAGES = []
        for ext_dir in user_config.get_ext_root_dirs():
            ext_pkg_def_file_path = op.join(ext_dir, PLUGIN_EXT_DEF_FILE)
            if op.exists(ext_pkg_def_file_path):
                ext_def_file = _ExtensionPackageDefinitionFile(
                    ext_pkg_def_file_path)
                EXTENSION_PACKAGES.extend(ext_def_file.defined_ext_packages)

        return EXTENSION_PACKAGES
Ejemplo n.º 10
0
 def __init__(self, xaml_file_name):
     forms.WPFWindow.__init__(self, xaml_file_name)
     self._setup_ext_dirs_ui(user_config.get_ext_root_dirs())
     self._setup_ext_pkg_ui(plugins.extpackages.get_ext_packages())
Ejemplo n.º 11
0

def open_ext_dirs_in_explorer(ext_dirs_list):
    """Opens each folder provided by ext_dirs_list in window explorer.

    Args:
        ext_dirs_list (list): List of directories to be opened in explorer

    """

    for ext_dir in ext_dirs_list:
        coreutils.open_folder_in_explorer(ext_dir)


PYREVIT_CORE_RELOAD_COMMAND_NAME = 'pyRevitCorepyRevitpyRevittoolsReload'


def call_reload():
    from pyrevit.loader.sessionmgr import execute_command
    execute_command(PYREVIT_CORE_RELOAD_COMMAND_NAME)


# handles tool click in Revit interface:
# if Shift-Click on the tool, opens the extension package destinations in
# windows explorer
# otherwise, will show the Extension manager user interface
if __shiftclick__:
    open_ext_dirs_in_explorer(user_config.get_ext_root_dirs())
else:
    ExtensionsWindow('ExtensionsWindow.xaml').show_dialog()