From f2b9337faed6858d023f9cf15d25daa53de8b79d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 16 Jul 2015 13:58:28 +0200 Subject: [PATCH] WizardPlugins can now report back more details In case a wizard plugin needs to communicate more info with its frontend, such as which kind of information is missing, this is now possible through a new API endpoint that will collect such information from the plugins and provide it to callees. --- src/octoprint/plugin/__init__.py | 3 ++- src/octoprint/plugin/types.py | 3 +++ src/octoprint/server/api/__init__.py | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/octoprint/plugin/__init__.py b/src/octoprint/plugin/__init__.py index 21976d08..447e4791 100644 --- a/src/octoprint/plugin/__init__.py +++ b/src/octoprint/plugin/__init__.py @@ -103,7 +103,8 @@ def plugin_manager(init=False, plugin_folders=None, plugin_types=None, plugin_en EventHandlerPlugin, SlicerPlugin, AppPlugin, - ProgressPlugin] + ProgressPlugin, + WizardPlugin] if plugin_entry_points is None: plugin_entry_points = "octoprint.plugin" if plugin_disabled_list is None: diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index 70d7b5b7..e593a880 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -455,6 +455,9 @@ class WizardPlugin(OctoPrintPlugin, ReloadNeedingPlugin): def is_wizard_required(self): return False + def get_wizard_details(self): + return dict() + class SimpleApiPlugin(OctoPrintPlugin): """ diff --git a/src/octoprint/server/api/__init__.py b/src/octoprint/server/api/__init__.py index 47215573..150fba3a 100644 --- a/src/octoprint/server/api/__init__.py +++ b/src/octoprint/server/api/__init__.py @@ -98,6 +98,24 @@ def pluginCommand(name): #~~ first run setup +@api.route("/setup/wizard", methods=["GET"]) +def wizardState(): + if not s().getBoolean(["server", "firstRun"]) and not admin_permission.can(): + abort(403) + + result = dict() + wizard_plugins = octoprint.server.pluginManager.get_implementations(octoprint.plugin.WizardPlugin) + for implementation in wizard_plugins: + name = implementation._identifier + try: + required = implementation.is_wizard_required() + details = implementation.get_wizard_details() + except: + logging.getLogger(__name__).exception("There was an error fetching wizard details for {}, ignoring".format(name)) + else: + result[name] = dict(required=required, details=details) + + return jsonify(result) @api.route("/setup", methods=["POST"]) def firstRunSetup():