def plugin_manager(init=False, plugin_folders=None, plugin_types=None, plugin_entry_points=None, plugin_disabled_list=None): global _instance if _instance is None: if init: if plugin_folders is None: plugin_folders = (settings().getBaseFolder("plugins"), os.path.abspath( os.path.join( os.path.dirname( os.path.realpath(__file__)), "..", "plugins"))) if plugin_types is None: plugin_types = [ StartupPlugin, ShutdownPlugin, TemplatePlugin, SettingsPlugin, SimpleApiPlugin, AssetPlugin, BlueprintPlugin, EventHandlerPlugin, SlicerPlugin, AppPlugin, ProgressPlugin ] if plugin_entry_points is None: plugin_entry_points = "octoprint.plugin" if plugin_disabled_list is None: all_plugin_settings = settings().get(["plugins"]) plugin_disabled_list = [] for key in all_plugin_settings: if "enabled" in all_plugin_settings[ key] and not all_plugin_settings[key]: plugin_disabled_list.append(key) _instance = PluginManager( plugin_folders, plugin_types, plugin_entry_points, plugin_disabled_list=plugin_disabled_list) else: raise ValueError("Plugin Manager not initialized yet") return _instance
def plugin_manager(init=False, plugin_folders=None, plugin_bases=None, plugin_entry_points=None, plugin_disabled_list=None, plugin_blacklist=None, plugin_restart_needing_hooks=None, plugin_obsolete_hooks=None, plugin_considered_bundled=None, plugin_validators=None, compatibility_ignored_list=None): """ Factory method for initially constructing and consecutively retrieving the :class:`~octoprint.plugin.core.PluginManager` singleton. Arguments: init (boolean): A flag indicating whether this is the initial call to construct the singleton (True) or not (False, default). If this is set to True and the plugin manager has already been initialized, a :class:`ValueError` will be raised. The same will happen if the plugin manager has not yet been initialized and this is set to False. plugin_folders (list): A list of folders (as strings containing the absolute path to them) in which to look for potential plugin modules. If not provided this defaults to the configured ``plugins`` base folder and ``src/plugins`` within OctoPrint's code base. plugin_bases (list): A list of recognized plugin base classes for which to look for provided implementations. If not provided this defaults to :class:`~octoprint.plugin.OctoPrintPlugin`. plugin_entry_points (list): A list of entry points pointing to modules which to load as plugins. If not provided this defaults to the entry point ``octoprint.plugin``. plugin_disabled_list (list): A list of plugin identifiers that are currently disabled. If not provided this defaults to all plugins for which ``enabled`` is set to ``False`` in the settings. plugin_blacklist (list): A list of plugin identifiers/identifier-version tuples that are currently blacklisted. plugin_restart_needing_hooks (list): A list of hook namespaces which cause a plugin to need a restart in order be enabled/disabled. Does not have to contain full hook identifiers, will be matched with startswith similar to logging handlers plugin_obsolete_hooks (list): A list of hooks that have been declared obsolete. Plugins implementing them will not be enabled since they might depend on functionality that is no longer available. plugin_considered_bundled (list): A list of plugin identifiers that are considered bundled plugins even if installed separately. plugin_validators (list): A list of additional plugin validators through which to process each plugin. compatibility_ignored_list (list): A list of plugin keys for which it will be ignored if they are flagged as incompatible. This is for development purposes only and should not be used in production. Returns: PluginManager: A fully initialized :class:`~octoprint.plugin.core.PluginManager` instance to be used for plugin management tasks. Raises: ValueError: ``init`` was True although the plugin manager was already initialized, or it was False although the plugin manager was not yet initialized. """ global _instance if _instance is not None: if init: raise ValueError("Plugin Manager already initialized") else: if init: if plugin_bases is None: plugin_bases = [OctoPrintPlugin] if plugin_restart_needing_hooks is None: plugin_restart_needing_hooks = [ "octoprint.server.http.*", "octoprint.printer.factory", "octoprint.access.permissions", "octoprint.timelapse.extensions" ] if plugin_obsolete_hooks is None: plugin_obsolete_hooks = ["octoprint.comm.protocol.gcode"] if plugin_considered_bundled is None: plugin_considered_bundled = ["firmware_check", "file_check"] if plugin_validators is None: plugin_validators = [_validate_plugin] else: plugin_validators.append(_validate_plugin) _instance = PluginManager( plugin_folders, plugin_bases, plugin_entry_points, logging_prefix="octoprint.plugins.", plugin_disabled_list=plugin_disabled_list, plugin_blacklist=plugin_blacklist, plugin_restart_needing_hooks=plugin_restart_needing_hooks, plugin_obsolete_hooks=plugin_obsolete_hooks, plugin_considered_bundled=plugin_considered_bundled, plugin_validators=plugin_validators, compatibility_ignored_list=compatibility_ignored_list) else: raise ValueError("Plugin Manager not initialized yet") return _instance
def plugin_manager(init=False, plugin_folders=None, plugin_types=None, plugin_entry_points=None, plugin_disabled_list=None, plugin_restart_needing_hooks=None, plugin_obsolete_hooks=None, plugin_validators=None): """ Factory method for initially constructing and consecutively retrieving the :class:`~octoprint.plugin.core.PluginManager` singleton. Arguments: init (boolean): A flag indicating whether this is the initial call to construct the singleton (True) or not (False, default). If this is set to True and the plugin manager has already been initialized, a :class:`ValueError` will be raised. The same will happen if the plugin manager has not yet been initialized and this is set to False. plugin_folders (list): A list of folders (as strings containing the absolute path to them) in which to look for potential plugin modules. If not provided this defaults to the configured ``plugins`` base folder and ``src/plugins`` within OctoPrint's code base. plugin_types (list): A list of recognized plugin types for which to look for provided implementations. If not provided this defaults to the plugin types found in :mod:`octoprint.plugin.types` without :class:`~octoprint.plugin.OctoPrintPlugin`. plugin_entry_points (list): A list of entry points pointing to modules which to load as plugins. If not provided this defaults to the entry point ``octoprint.plugin``. plugin_disabled_list (list): A list of plugin identifiers that are currently disabled. If not provided this defaults to all plugins for which ``enabled`` is set to ``False`` in the settings. plugin_restart_needing_hooks (list): A list of hook namespaces which cause a plugin to need a restart in order be enabled/disabled. Does not have to contain full hook identifiers, will be matched with startswith similar to logging handlers plugin_obsolete_hooks (list): A list of hooks that have been declared obsolete. Plugins implementing them will not be enabled since they might depend on functionality that is no longer available. plugin_validators (list): A list of additional plugin validators through which to process each plugin. Returns: PluginManager: A fully initialized :class:`~octoprint.plugin.core.PluginManager` instance to be used for plugin management tasks. Raises: ValueError: ``init`` was True although the plugin manager was already initialized, or it was False although the plugin manager was not yet initialized. """ global _instance if _instance is not None: if init: raise ValueError("Plugin Manager already initialized") else: if init: if plugin_types is None: plugin_types = [ StartupPlugin, ShutdownPlugin, TemplatePlugin, SettingsPlugin, SimpleApiPlugin, AssetPlugin, BlueprintPlugin, EventHandlerPlugin, SlicerPlugin, AppPlugin, ProgressPlugin, WizardPlugin, UiPlugin ] if plugin_restart_needing_hooks is None: plugin_restart_needing_hooks = ["octoprint.server.http"] if plugin_obsolete_hooks is None: plugin_obsolete_hooks = ["octoprint.comm.protocol.gcode"] if plugin_validators is None: plugin_validators = [_validate_plugin] else: plugin_validators.append(_validate_plugin) _instance = PluginManager( plugin_folders, plugin_types, plugin_entry_points, logging_prefix="octoprint.plugins.", plugin_disabled_list=plugin_disabled_list, plugin_restart_needing_hooks=plugin_restart_needing_hooks, plugin_obsolete_hooks=plugin_obsolete_hooks, plugin_validators=plugin_validators) else: raise ValueError("Plugin Manager not initialized yet") return _instance
def plugin_manager(init=False, plugin_folders=None, plugin_types=None, plugin_entry_points=None, plugin_disabled_list=None): """ Factory method for initially constructing and consecutively retrieving the :class:`~octoprint.plugin.core.PluginManager` singleton. Arguments: init (boolean): A flag indicating whether this is the initial call to construct the singleton (True) or not (False, default). If this is set to True and the plugin manager has already been initialized, a :class:`ValueError` will be raised. The same will happen if the plugin manager has not yet been initialized and this is set to False. plugin_folders (list): A list of folders (as strings containing the absolute path to them) in which to look for potential plugin modules. If not provided this defaults to the configured ``plugins`` base folder and ``src/plugins`` within OctoPrint's code base. plugin_types (list): A list of recognized plugin types for which to look for provided implementations. If not provided this defaults to the plugin types found in :mod:`octoprint.plugin.types` without :class:`~octoprint.plugin.OctoPrintPlugin`. plugin_entry_points (list): A list of entry points pointing to modules which to load as plugins. If not provided this defaults to the entry point ``octoprint.plugin``. plugin_disabled_list (list): A list of plugin identifiers that are currently disabled. If not provided this defaults to all plugins for which ``enabled`` is set to ``False`` in the settings. Returns: PluginManager: A fully initialized :class:`~octoprint.plugin.core.PluginManager` instance to be used for plugin management tasks. Raises: ValueError: ``init`` was True although the plugin manager was already initialized, or it was False although the plugin manager was not yet initialized. """ global _instance if _instance is not None: if init: raise ValueError("Plugin Manager already initialized") else: if init: if plugin_folders is None: plugin_folders = (settings().getBaseFolder("plugins"), (os.path.abspath( os.path.join( os.path.dirname( os.path.realpath(__file__)), "..", "plugins")), True)) if plugin_types is None: plugin_types = [ StartupPlugin, ShutdownPlugin, TemplatePlugin, SettingsPlugin, SimpleApiPlugin, AssetPlugin, BlueprintPlugin, EventHandlerPlugin, SlicerPlugin, AppPlugin, ProgressPlugin ] if plugin_entry_points is None: plugin_entry_points = "octoprint.plugin" if plugin_disabled_list is None: all_plugin_settings = settings().get(["plugins"]) plugin_disabled_list = [] for key in all_plugin_settings: if "enabled" in all_plugin_settings[ key] and not all_plugin_settings[key]: plugin_disabled_list.append(key) _instance = PluginManager( plugin_folders, plugin_types, plugin_entry_points, logging_prefix="octoprint.plugins.", plugin_disabled_list=plugin_disabled_list) else: raise ValueError("Plugin Manager not initialized yet") return _instance