Example #1
0
def _get_plugin_settings():
	logger = logging.getLogger(__name__)

	data = dict()

	def process_plugin_result(name, result):
		if result:
			try:
				jsonify(test=result)
			except:
				logger.exception("Error while jsonifying settings from plugin {}, please contact the plugin author about this".format(name))
				raise
			else:
				if "__enabled" in result:
					del result["__enabled"]
				data[name] = result

	for plugin in octoprint.plugin.plugin_manager().get_implementations(octoprint.plugin.SettingsPlugin):
		try:
			result = plugin.on_settings_load()
			process_plugin_result(plugin._identifier, result)
		except TypeError:
			logger.warn("Could not load settings for plugin {name} ({version}) since it called super(...)".format(name=plugin._plugin_name,
			                                                                                                      version=plugin._plugin_version))
			logger.warn("in a way which has issues due to OctoPrint's dynamic reloading after plugin operations.")
			logger.warn("Please contact the plugin's author and ask to update the plugin to use a direct call like")
			logger.warn("octoprint.plugin.SettingsPlugin.on_settings_load(self) instead.")
		except:
			logger.exception("Could not load settings for plugin {name} ({version})".format(version=plugin._plugin_version,
			                                                                                name=plugin._plugin_name))

	return data
Example #2
0
def _get_plugin_settings():
    logger = logging.getLogger(__name__)

    data = {}

    def process_plugin_result(name, result):
        if result:
            try:
                jsonify(test=result)
            except Exception:
                logger.exception(
                    "Error while jsonifying settings from plugin {}, please contact the plugin author about this"
                    .format(name))
                raise
            else:
                if "__enabled" in result:
                    del result["__enabled"]
                data[name] = result

    for plugin in octoprint.plugin.plugin_manager().get_implementations(
            octoprint.plugin.SettingsPlugin):
        try:
            result = plugin.on_settings_load()
            process_plugin_result(plugin._identifier, result)
        except Exception:
            logger.exception(
                "Could not load settings for plugin {name} ({version})".format(
                    version=plugin._plugin_version, name=plugin._plugin_name),
                extra={"plugin": plugin._identifier},
            )

    return data
Example #3
0
def _get_plugin_settings():
	logger = logging.getLogger(__name__)

	data = dict()

	def process_plugin_result(name, result):
		if result:
			try:
				jsonify(test=result)
			except:
				logger.exception("Error while jsonifying settings from plugin {}, please contact the plugin author about this".format(name))
				raise
			else:
				if "__enabled" in result:
					del result["__enabled"]
				data[name] = result

	for plugin in octoprint.plugin.plugin_manager().get_implementations(octoprint.plugin.SettingsPlugin):
		try:
			result = plugin.on_settings_load()
			process_plugin_result(plugin._identifier, result)
		except TypeError:
			logger.warn("Could not load settings for plugin {name} ({version}) since it called super(...)".format(name=plugin._plugin_name,
			                                                                                                      version=plugin._plugin_version))
			logger.warn("in a way which has issues due to OctoPrint's dynamic reloading after plugin operations.")
			logger.warn("Please contact the plugin's author and ask to update the plugin to use a direct call like")
			logger.warn("octoprint.plugin.SettingsPlugin.on_settings_load(self) instead.")
		except:
			logger.exception("Could not load settings for plugin {name} ({version})".format(version=plugin._plugin_version,
			                                                                                name=plugin._plugin_name),
			                 extra=dict(plugin=plugin._identifier))

	return data
Example #4
0
def getSettings():
	logger = logging.getLogger(__name__)

	s = settings()

	connectionOptions = get_connection_options()

	data = {
		"api": {
			"enabled": s.getBoolean(["api", "enabled"]),
			"key": s.get(["api", "key"]) if admin_permission.can() else "n/a",
			"allowCrossOrigin": s.get(["api", "allowCrossOrigin"])
		},
		"appearance": {
			"name": s.get(["appearance", "name"]),
			"color": s.get(["appearance", "color"]),
			"colorTransparent": s.getBoolean(["appearance", "colorTransparent"]),
			"defaultLanguage": s.get(["appearance", "defaultLanguage"])
		},
		"printer": {
			"defaultExtrusionLength": s.getInt(["printerParameters", "defaultExtrusionLength"])
		},
		"webcam": {
			"streamUrl": s.get(["webcam", "stream"]),
			"snapshotUrl": s.get(["webcam", "snapshot"]),
			"ffmpegPath": s.get(["webcam", "ffmpeg"]),
			"bitrate": s.get(["webcam", "bitrate"]),
			"ffmpegThreads": s.get(["webcam", "ffmpegThreads"]),
			"watermark": s.getBoolean(["webcam", "watermark"]),
			"flipH": s.getBoolean(["webcam", "flipH"]),
			"flipV": s.getBoolean(["webcam", "flipV"]),
			"rotate90": s.getBoolean(["webcam", "rotate90"])
		},
		"feature": {
			"gcodeViewer": s.getBoolean(["gcodeViewer", "enabled"]),
			"temperatureGraph": s.getBoolean(["feature", "temperatureGraph"]),
			"waitForStart": s.getBoolean(["feature", "waitForStartOnConnect"]),
			"alwaysSendChecksum": s.getBoolean(["feature", "alwaysSendChecksum"]),
			"sdSupport": s.getBoolean(["feature", "sdSupport"]),
			"sdRelativePath": s.getBoolean(["feature", "sdRelativePath"]),
			"sdAlwaysAvailable": s.getBoolean(["feature", "sdAlwaysAvailable"]),
			"swallowOkAfterResend": s.getBoolean(["feature", "swallowOkAfterResend"]),
			"repetierTargetTemp": s.getBoolean(["feature", "repetierTargetTemp"]),
			"externalHeatupDetection": s.getBoolean(["feature", "externalHeatupDetection"]),
			"keyboardControl": s.getBoolean(["feature", "keyboardControl"]),
			"pollWatched": s.getBoolean(["feature", "pollWatched"]),
			"ignoreIdenticalResends": s.getBoolean(["feature", "ignoreIdenticalResends"])
		},
		"serial": {
			"port": connectionOptions["portPreference"],
			"baudrate": connectionOptions["baudratePreference"],
			"portOptions": connectionOptions["ports"],
			"baudrateOptions": connectionOptions["baudrates"],
			"autoconnect": s.getBoolean(["serial", "autoconnect"]),
			"timeoutConnection": s.getFloat(["serial", "timeout", "connection"]),
			"timeoutDetection": s.getFloat(["serial", "timeout", "detection"]),
			"timeoutCommunication": s.getFloat(["serial", "timeout", "communication"]),
			"timeoutTemperature": s.getFloat(["serial", "timeout", "temperature"]),
			"timeoutSdStatus": s.getFloat(["serial", "timeout", "sdStatus"]),
			"log": s.getBoolean(["serial", "log"]),
			"additionalPorts": s.get(["serial", "additionalPorts"]),
			"longRunningCommands": s.get(["serial", "longRunningCommands"]),
			"checksumRequiringCommands": s.get(["serial", "checksumRequiringCommands"]),
			"helloCommand": s.get(["serial", "helloCommand"]),
			"ignoreErrorsFromFirmware": s.getBoolean(["serial", "ignoreErrorsFromFirmware"]),
			"disconnectOnErrors": s.getBoolean(["serial", "disconnectOnErrors"]),
			"triggerOkForM29": s.getBoolean(["serial", "triggerOkForM29"]),
			"supportResendsWithoutOk": s.getBoolean(["serial", "supportResendsWithoutOk"]),
			"maxTimeoutsIdle": s.getInt(["serial", "maxCommunicationTimeouts", "idle"]),
			"maxTimeoutsPrinting": s.getInt(["serial", "maxCommunicationTimeouts", "printing"]),
			"maxTimeoutsLong": s.getInt(["serial", "maxCommunicationTimeouts", "long"])
		},
		"folder": {
			"uploads": s.getBaseFolder("uploads"),
			"timelapse": s.getBaseFolder("timelapse"),
			"timelapseTmp": s.getBaseFolder("timelapse_tmp"),
			"logs": s.getBaseFolder("logs"),
			"watched": s.getBaseFolder("watched")
		},
		"temperature": {
			"profiles": s.get(["temperature", "profiles"]),
			"cutoff": s.getInt(["temperature", "cutoff"])
		},
		"system": {
			"actions": s.get(["system", "actions"]),
			"events": s.get(["system", "events"])
		},
		"terminalFilters": s.get(["terminalFilters"]),
		"scripts": {
			"gcode": {
				"afterPrinterConnected": None,
				"beforePrintStarted": None,
				"afterPrintCancelled": None,
				"afterPrintDone": None,
				"beforePrintPaused": None,
				"afterPrintResumed": None,
				"snippets": dict()
			}
		},
		"server": {
			"commands": {
				"systemShutdownCommand": s.get(["server", "commands", "systemShutdownCommand"]),
				"systemRestartCommand": s.get(["server", "commands", "systemRestartCommand"]),
				"serverRestartCommand": s.get(["server", "commands", "serverRestartCommand"])
			},
			"diskspace": {
				"warning": s.getInt(["server", "diskspace", "warning"]),
				"critical": s.getInt(["server", "diskspace", "critical"])
			}
		}
	}

	gcode_scripts = s.listScripts("gcode")
	if gcode_scripts:
		data["scripts"] = dict(gcode=dict())
		for name in gcode_scripts:
			data["scripts"]["gcode"][name] = s.loadScript("gcode", name, source=True)

	def process_plugin_result(name, result):
		if result:
			try:
				jsonify(test=result)
			except:
				logger.exception("Error while jsonifying settings from plugin {}, please contact the plugin author about this".format(name))

			if not "plugins" in data:
				data["plugins"] = dict()
			if "__enabled" in result:
				del result["__enabled"]
			data["plugins"][name] = result

	for plugin in octoprint.plugin.plugin_manager().get_implementations(octoprint.plugin.SettingsPlugin):
		try:
			result = plugin.on_settings_load()
			process_plugin_result(plugin._identifier, result)
		except TypeError:
			logger.warn("Could not load settings for plugin {name} ({version}) since it called super(...)".format(name=plugin._plugin_name, version=plugin._plugin_version))
			logger.warn("in a way which has issues due to OctoPrint's dynamic reloading after plugin operations.")
			logger.warn("Please contact the plugin's author and ask to update the plugin to use a direct call like")
			logger.warn("octoprint.plugin.SettingsPlugin.on_settings_load(self) instead.")
		except:
			logger.exception("Could not load settings for plugin {name} ({version})".format(version=plugin._plugin_version, name=plugin._plugin_name))

	return jsonify(data)
Example #5
0
def getSettings():
    logger = logging.getLogger(__name__)

    s = settings()

    connectionOptions = get_connection_options()

    data = {
        "api": {
            "enabled": s.getBoolean(["api", "enabled"]),
            "key": s.get(["api", "key"]) if admin_permission.can() else "n/a",
            "allowCrossOrigin": s.get(["api", "allowCrossOrigin"])
        },
        "appearance": {
            "name": s.get(["appearance", "name"]),
            "color": s.get(["appearance", "color"]),
            "colorTransparent":
            s.getBoolean(["appearance", "colorTransparent"]),
            "defaultLanguage": s.get(["appearance", "defaultLanguage"])
        },
        "printer": {
            "defaultExtrusionLength":
            s.getInt(["printerParameters", "defaultExtrusionLength"])
        },
        "webcam": {
            "streamUrl": s.get(["webcam", "stream"]),
            "snapshotUrl": s.get(["webcam", "snapshot"]),
            "ffmpegPath": s.get(["webcam", "ffmpeg"]),
            "bitrate": s.get(["webcam", "bitrate"]),
            "ffmpegThreads": s.get(["webcam", "ffmpegThreads"]),
            "watermark": s.getBoolean(["webcam", "watermark"]),
            "flipH": s.getBoolean(["webcam", "flipH"]),
            "flipV": s.getBoolean(["webcam", "flipV"]),
            "rotate90": s.getBoolean(["webcam", "rotate90"])
        },
        "feature": {
            "gcodeViewer":
            s.getBoolean(["gcodeViewer", "enabled"]),
            "temperatureGraph":
            s.getBoolean(["feature", "temperatureGraph"]),
            "waitForStart":
            s.getBoolean(["feature", "waitForStartOnConnect"]),
            "alwaysSendChecksum":
            s.getBoolean(["feature", "alwaysSendChecksum"]),
            "sdSupport":
            s.getBoolean(["feature", "sdSupport"]),
            "sdAlwaysAvailable":
            s.getBoolean(["feature", "sdAlwaysAvailable"]),
            "swallowOkAfterResend":
            s.getBoolean(["feature", "swallowOkAfterResend"]),
            "repetierTargetTemp":
            s.getBoolean(["feature", "repetierTargetTemp"]),
            "grbl":
            s.getBoolean(["feature", "grbl"]),
            "zaxis":
            s.getBoolean(["feature", "zaxis"]),
            "externalHeatupDetection":
            s.getBoolean(["feature", "externalHeatupDetection"]),
            "keyboardControl":
            s.getBoolean(["feature", "keyboardControl"])
        },
        "serial": {
            "port":
            connectionOptions["portPreference"],
            "baudrate":
            connectionOptions["baudratePreference"],
            "portOptions":
            connectionOptions["ports"],
            "baudrateOptions":
            connectionOptions["baudrates"],
            "autoconnect":
            s.getBoolean(["serial", "autoconnect"]),
            "timeoutConnection":
            s.getFloat(["serial", "timeout", "connection"]),
            "timeoutDetection":
            s.getFloat(["serial", "timeout", "detection"]),
            "timeoutCommunication":
            s.getFloat(["serial", "timeout", "communication"]),
            "timeoutTemperature":
            s.getFloat(["serial", "timeout", "temperature"]),
            "timeoutSdStatus":
            s.getFloat(["serial", "timeout", "sdStatus"]),
            "log":
            s.getBoolean(["serial", "log"]),
            "additionalPorts":
            s.get(["serial", "additionalPorts"]),
            "longRunningCommands":
            s.get(["serial", "longRunningCommands"])
        },
        "folder": {
            "uploads": s.getBaseFolder("uploads"),
            "timelapse": s.getBaseFolder("timelapse"),
            "timelapseTmp": s.getBaseFolder("timelapse_tmp"),
            "logs": s.getBaseFolder("logs"),
            "watched": s.getBaseFolder("watched")
        },
        "temperature": {
            "profiles": s.get(["temperature", "profiles"]),
            "cutoff": s.getInt(["temperature", "cutoff"])
        },
        "system": {
            "actions": s.get(["system", "actions"]),
            "events": s.get(["system", "events"])
        },
        "terminalFilters": s.get(["terminalFilters"]),
        "scripts": {
            "gcode": {
                "afterPrinterConnected": None,
                "beforePrintStarted": None,
                "afterPrintCancelled": None,
                "afterPrintDone": None,
                "beforePrintPaused": None,
                "afterPrintResumed": None,
                "snippets": dict()
            }
        }
    }

    gcode_scripts = s.listScripts("gcode")
    if gcode_scripts:
        data["scripts"] = dict(gcode=dict())
        for name in gcode_scripts:
            data["scripts"]["gcode"][name] = s.loadScript("gcode",
                                                          name,
                                                          source=True)

    def process_plugin_result(name, result):
        if result:
            try:
                jsonify(test=result)
            except:
                logger.exception(
                    "Error while jsonifying settings from plugin {}, please contact the plugin author about this"
                    .format(name))

            if not "plugins" in data:
                data["plugins"] = dict()
            if "__enabled" in result:
                del result["__enabled"]
            data["plugins"][name] = result

    for plugin in octoprint.plugin.plugin_manager().get_implementations(
            octoprint.plugin.SettingsPlugin):
        try:
            result = plugin.on_settings_load()
            process_plugin_result(plugin._identifier, result)
        except TypeError:
            logger.warn(
                "Could not load settings for plugin {name} ({version}) since it called super(...)"
                .format(name=plugin._plugin_name,
                        version=plugin._plugin_version))
            logger.warn(
                "in a way which has issues due to OctoPrint's dynamic reloading after plugin operations."
            )
            logger.warn(
                "Please contact the plugin's author and ask to update the plugin to use a direct call like"
            )
            logger.warn(
                "octoprint.plugin.SettingsPlugin.on_settings_load(self) instead."
            )
        except:
            logger.exception(
                "Could not load settings for plugin {name} ({version})".format(
                    version=plugin._plugin_version, name=plugin._plugin_name))

    #print("settings.py getSettings: data", data["plugins"])
    return jsonify(data)