diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index c8842ee4..08f6d40c 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -676,6 +676,38 @@ octoprint.filemanager.preprocessor :return: The `file_object` as passed in or None, or a replaced version to use instead for further processing. :rtype: AbstractFileWrapper or None +.. _sec-plugins-hook-printer-factory: + +octoprint.printer.factory +~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. py:function:: hook(components, *args, **kwargs) + + Return a :class:`~octoprint.printer.PrinterInstance` instance to use as global printer object. This will + be called only once during initial server startup. + + The provided ``components`` is a dictionary containing the already initialized system components: + + * ``plugin_manager``: The :class:`~octoprint.plugin.core.PluginManager` + * ``printer_profile_manager``: The :class:`~octoprint.printer.profile.PrinterProfileManager` + * ``event_bus``: The :class:`~octoprint.events.EventManager` + * ``analysis_queue``: The :class:`~octoprint.filemanager.analysis.AnalysisQueue` + * ``slicing_manager``: The :class:`~octoprint.slicing.SlicingManager` + * ``file_manager``: The :class:`~octoprint.filemanager.FileManager` + * ``app_session_manager``: The :class:`~octoprint.server.util.flask.AppSessionManager` + * ``plugin_lifecycle_manager``: The :class:`~octoprint.server.LifecycleManager` + * ``user_manager``: The :class:`~octoprint.users.UserManager` + * ``preemptive_cache``: The :class:`~octoprint.server.util.flask.PreemptiveCache` + + If the factory returns anything but ``None``, it will be assigned to the global ``printer`` instance. + + If no of the registered factories return a printer instance, the default :class:`~octoprint.printer.standard.Printer` + class will be instantiated. + + :param dict components: System components to use for printer instance initialization + :return: The ``printer`` instance to use globally. + :rtype: PrinterInterface subclass or None + .. _sec-plugins-hook-server-http-bodysize: octoprint.server.http.bodysize diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 25fc5a94..e7e99aa4 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -196,6 +196,17 @@ class Server(object): pluginLifecycleManager = LifecycleManager(pluginManager) preemptiveCache = PreemptiveCache(os.path.join(self._settings.getBaseFolder("data"), "preemptive_cache_config.yaml")) + # setup access control + userManagerName = self._settings.get(["accessControl", "userManager"]) + try: + clazz = octoprint.util.get_class(userManagerName) + userManager = clazz() + except AttributeError as e: + self._logger.exception("Could not instantiate user manager {}, falling back to FilebasedUserManager!".format(userManagerName)) + userManager = octoprint.users.FilebasedUserManager() + finally: + userManager.enabled = self._settings.getBoolean(["accessControl", "enabled"]) + components = dict( plugin_manager=pluginManager, printer_profile_manager=printerProfileManager, @@ -223,18 +234,6 @@ class Server(object): printer = Printer(fileManager, analysisQueue, printerProfileManager) components.update(dict(printer=printer)) - # setup access control - userManagerName = self._settings.get(["accessControl", "userManager"]) - try: - clazz = octoprint.util.get_class(userManagerName) - userManager = clazz() - except AttributeError as e: - self._logger.exception("Could not instantiate user manager {}, falling back to FilebasedUserManager!".format(userManagerName)) - userManager = octoprint.users.FilebasedUserManager() - finally: - userManager.enabled = self._settings.getBoolean(["accessControl", "enabled"]) - components["user_manager"] = userManager - def octoprint_plugin_inject_factory(name, implementation): if not isinstance(implementation, octoprint.plugin.OctoPrintPlugin): return None