🐳 chore: spelling and keyparameters

This commit is contained in:
thelastWallE 2021-10-06 23:14:57 +02:00
parent dbeb0bfcce
commit 3c940bb786
5 changed files with 73 additions and 31 deletions

View File

@ -369,6 +369,14 @@ class KlipperPlugin(
util.update_status(self, "error", "Klipper: Error") util.update_status(self, "error", "Klipper: Error")
logger.log_error(self, payload["error"]) logger.log_error(self, payload["error"])
def processAtCommand(self, comm_instance, phase, command, parameters, tags=None, *args, **kwargs):
if command != "SWITCHCONFIG":
return
config = parameters
logger.log_info(self, "SWITCHCONFIG detected config:{}".format(config))
return None
# -- GCODE Hook # -- GCODE Hook
def on_parse_gcode(self, comm, line, *args, **kwargs): def on_parse_gcode(self, comm, line, *args, **kwargs):
@ -484,7 +492,7 @@ class KlipperPlugin(
raise raise
return NO_CONTENT return NO_CONTENT
# Get a list of all backuped configfiles # Get a list of all backed up configfiles
@octoprint.plugin.BlueprintPlugin.route("/backup/list", methods=["GET"]) @octoprint.plugin.BlueprintPlugin.route("/backup/list", methods=["GET"])
@restricted_access @restricted_access
@Permissions.PLUGIN_KLIPPER_CONFIG.require(403) @Permissions.PLUGIN_KLIPPER_CONFIG.require(403)
@ -492,7 +500,7 @@ class KlipperPlugin(
files = cfgUtils.list_cfg_files(self, "backup") files = cfgUtils.list_cfg_files(self, "backup")
return flask.jsonify(files = files) return flask.jsonify(files = files)
# restore a backuped configfile # restore a backed up configfile
@octoprint.plugin.BlueprintPlugin.route("/backup/restore/<filename>", methods=["GET"]) @octoprint.plugin.BlueprintPlugin.route("/backup/restore/<filename>", methods=["GET"])
@restricted_access @restricted_access
@Permissions.PLUGIN_KLIPPER_CONFIG.require(403) @Permissions.PLUGIN_KLIPPER_CONFIG.require(403)
@ -571,7 +579,7 @@ class KlipperPlugin(
Filecontent = data.get("DataToSave", []) Filecontent = data.get("DataToSave", [])
saved = cfgUtils.save_cfg(self, Filecontent, filename) saved = cfgUtils.save_cfg(self, Filecontent, filename)
if saved == True: if saved == True:
util.send_message(self, "reload", "configlist", "", "") util.send_message(self, type = "reload", subtype = "configlist")
return flask.jsonify(saved = saved) return flask.jsonify(saved = saved)
# restart klipper # restart klipper
@ -634,6 +642,7 @@ def __plugin_load__():
__plugin_hooks__ = { __plugin_hooks__ = {
"octoprint.server.http.routes": __plugin_implementation__.route_hook, "octoprint.server.http.routes": __plugin_implementation__.route_hook,
"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions, "octoprint.access.permissions": __plugin_implementation__.get_additional_permissions,
"octoprint.comm.protocol.atcommand.sending": __plugin_implementation__.processAtCommand,
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.on_parse_gcode, "octoprint.comm.protocol.gcode.received": __plugin_implementation__.on_parse_gcode,
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information "octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
} }

View File

@ -15,6 +15,7 @@ except ImportError:
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
import StringIO import StringIO
def list_cfg_files(self, path: str) -> list: def list_cfg_files(self, path: str) -> list:
"""Generate list of config files. """Generate list of config files.
@ -53,6 +54,7 @@ def list_cfg_files(self, path: str) -> list:
logger.log_debug(self, "list_cfg_files " + str(len(files)) + ": " + f) logger.log_debug(self, "list_cfg_files " + str(len(files)) + ": " + f)
return files return files
def get_cfg(self, file): def get_cfg(self, file):
"""Get the content of a configuration file. """Get the content of a configuration file.
@ -95,6 +97,7 @@ def get_cfg(self, file):
response['text'] = gettext("File not found!") response['text'] = gettext("File not found!")
return response return response
def save_cfg(self, content, filename): def save_cfg(self, content, filename):
"""Save the configuration file to given file. """Save the configuration file to given file.
@ -138,12 +141,13 @@ def save_cfg(self, content, filename):
logger.log_error(self, "Error: Couldn't open Klipper config file: {}".format(filepath)) logger.log_error(self, "Error: Couldn't open Klipper config file: {}".format(filepath))
return False return False
else: else:
logger.log_debug(self, "Writen Klipper config to {}".format(filepath)) logger.log_debug(self, "Written Klipper config to {}".format(filepath))
return True return True
finally: finally:
f.close() f.close()
copy_cfg_to_backup(self, filepath) copy_cfg_to_backup(self, filepath)
def check_cfg(self, data): def check_cfg(self, data):
"""Checks the given data on parsing errors. """Checks the given data on parsing errors.
@ -172,6 +176,7 @@ def check_cfg(self, data):
logger.log_debug(self, "check_cfg: OK") logger.log_debug(self, "check_cfg: OK")
return True return True
def show_error_message(self, error): def show_error_message(self, error):
error.message = error.message.replace('\\n', '') error.message = error.message.replace('\\n', '')
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
@ -187,9 +192,14 @@ def show_error_message(self, error):
) )
util.send_message( util.send_message(
self, 'PopUp', 'warning', 'Invalid Config data\n', ('\n' + str(error)) self,
type = 'PopUp',
subtype = 'warning',
title = 'Invalid Config data\n',
payload = ('\n' + str(error))
) )
def is_float_ok(self, dataToValidated): def is_float_ok(self, dataToValidated):
sections_search_list = [ sections_search_list = [
@ -215,17 +225,18 @@ def is_float_ok(self, dataToValidated):
) )
util.send_message( util.send_message(
self, self,
"PopUp", type = "PopUp",
"warning", subtype = "warning",
"Invalid Config data\n", title = "Invalid Config data\n",
"\n" payload = "\n"
+ "Invalid Value for <b>" + x + "</b> in Section: <b>" + y + "</b>\n" + "Invalid Value for <b>" + x + "</b> in Section: <b>" + y + "</b>\n"
+ "{}".format(str(error)) + "{}".format(str(error))
) )
return False return False
else: else:
return True return True
def copy_cfg(self, file, dst): def copy_cfg(self, file, dst):
"""Copy the config file to the destination. """Copy the config file to the destination.
@ -255,6 +266,7 @@ def copy_cfg(self, file, dst):
return True return True
return False return False
def copy_cfg_to_backup(self, src): def copy_cfg_to_backup(self, src):
"""Copy the config file to backup directory of OctoKlipper. """Copy the config file to backup directory of OctoKlipper.
@ -292,8 +304,6 @@ def copy_cfg_to_backup(self, src):
) )
return False return False
else: else:
logger.log_debug(self, "CfgBackup " + dst + " writen") logger.log_debug(self, "CfgBackup " + dst + " written")
return True return True

View File

@ -2,16 +2,32 @@ from . import util
def log_info(self, message): def log_info(self, message):
self._octoklipper_logger.info(message) self._octoklipper_logger.info(message)
util.send_message(self, "log", "info", message, message) util.send_message(
self,
type = "log",
subtype = "info",
title = message,
payload = message
)
def log_debug(self, message): def log_debug(self, message):
self._octoklipper_logger.debug(message) self._octoklipper_logger.debug(message)
self._logger.info(message) self._logger.info(message)
# sends a message to frontend(in klipper.js -> self.onDataUpdaterPluginMessage) and write it to the console. util.send_message(
# _mtype, subtype=debug/info, title of message, message) self,
util.send_message(self, "console", "debug", message, message) type = "console",
subtype = "debug",
title = message,
payload = message
)
def log_error(self, error): def log_error(self, error):
self._octoklipper_logger.error(error) self._octoklipper_logger.error(error)
self._logger.error(error) self._logger.error(error)
util.send_message(self, "log", "error", error, error) util.send_message(
self,
type = "log",
subtype = "error",
title = error,
payload = error
)

View File

@ -86,6 +86,7 @@ $(function () {
self.loadBaseConfig = function () { self.loadBaseConfig = function () {
if (!self.klipperViewModel.hasRight("CONFIG")) return; if (!self.klipperViewModel.hasRight("CONFIG")) return;
var baseconfig = self.settings.settings.plugins.klipper.configuration.baseconfig(); var baseconfig = self.settings.settings.plugins.klipper.configuration.baseconfig();
self.klipperViewModel.consoleMessage("debug", "loadBaseConfig:" + baseconfig); self.klipperViewModel.consoleMessage("debug", "loadBaseConfig:" + baseconfig);
OctoPrint.plugins.klipper.getCfg(baseconfig).done(function (response) { OctoPrint.plugins.klipper.getCfg(baseconfig).done(function (response) {
@ -246,8 +247,6 @@ $(function () {
self.klipperEditorViewModel.process(config).then( self.klipperEditorViewModel.process(config).then(
function() { self.showEditor(); } function() { self.showEditor(); }
); );
}); });
}; };

View File

@ -1,8 +1,12 @@
def poll_status(self): def poll_status(self):
self._printer.commands("STATUS") self._printer.commands("STATUS")
def update_status(self, type, status): def update_status(self, subtype, status):
send_message(self, "status", type, status, status) send_message(
self,
type = "status",
subtype = subtype,
payload = status)
def file_exist(self, filepath): def file_exist(self, filepath):
''' '''
@ -10,8 +14,12 @@ def file_exist(self, filepath):
''' '''
from os import path from os import path
if not path.isfile(filepath): if not path.isfile(filepath):
send_message(self, "PopUp", "warning", "OctoKlipper Settings", send_message(
"File: <br />" + filepath + "<br /> does not exist!") self,
type = "PopUp",
subtype = "warning",
title = "OctoKlipper Settings",
payload = "File: <br />" + filepath + "<br /> does not exist!")
return False return False
else: else:
return True return True
@ -24,7 +32,7 @@ def key_exist(dict, key1, key2):
else: else:
return True return True
def send_message(self, type, subtype, title, payload): def send_message(self, type, subtype, title = "", payload = ""):
""" """
Send Message over API to FrontEnd Send Message over API to FrontEnd
""" """
@ -32,10 +40,10 @@ def send_message(self, type, subtype, title, payload):
self._plugin_manager.send_plugin_message( self._plugin_manager.send_plugin_message(
self._identifier, self._identifier,
dict( dict(
time=datetime.datetime.now().strftime("%H:%M:%S"), time = datetime.datetime.now().strftime("%H:%M:%S"),
type=type, type = type,
subtype=subtype, subtype = subtype,
title=title, title = title,
payload=payload payload = payload
) )
) )