From f8764e32208a1acd5df9c982f36db4d3488534d5 Mon Sep 17 00:00:00 2001
From: thelastWallE <12502210+thelastWallE@users.noreply.github.com>
Date: Sat, 13 Nov 2021 11:21:45 +0100
Subject: [PATCH] :art: fix migration/ add text to macros tab
- fix some migration problems for new versions
- add text to the macros tab
- adding breaklines for messages on sidebar
---
octoprint_klipper/__init__.py | 102 ++++++------------
octoprint_klipper/cfgUtils.py | 4 +-
octoprint_klipper/static/js/klipper.js | 4 +-
.../static/js/klipper_settings.js | 18 ++--
.../templates/klipper_settings.jinja2 | 12 ++-
.../templates/klipper_sidebar.jinja2 | 4 +-
octoprint_klipper/util.py | 55 ++++++++++
7 files changed, 112 insertions(+), 87 deletions(-)
diff --git a/octoprint_klipper/__init__.py b/octoprint_klipper/__init__.py
index 3a68e11..4315455 100644
--- a/octoprint_klipper/__init__.py
+++ b/octoprint_klipper/__init__.py
@@ -131,7 +131,7 @@ class KlipperPlugin(
),
configuration=dict(
debug_logging=False,
- configpath="~/",
+ config_path="~/",
baseconfig="printer.cfg",
logpath="/tmp/klippy.log",
reload_command="RESTART",
@@ -160,7 +160,7 @@ class KlipperPlugin(
return dict(
admin=[
["connection", "port"],
- ["configuration", "configpath"],
+ ["configuration", "config_path"],
["configuration", "replace_connection_panel"]
],
user=[
@@ -172,8 +172,8 @@ class KlipperPlugin(
def get_settings_version(self):
# Settings_Versionhistory:
# 3 = add shortstatus on navbar. migrate the navbar setting for this
- # 4 = -change of configpath to only path without filename
- # -parse configpath into path and baseconfig if not standard printer.cfg
+ # 4 = -change of configpath to config_path with only path without filename
+ # -parse configpath into config_path and baseconfig
# -switch setting for 'restart on editor save' to true if it was not set to manually
# -remove old_config
# -remove config on root settingsdirectory
@@ -183,75 +183,37 @@ class KlipperPlugin(
def on_settings_migrate(self, target, current):
settings = self._settings
if current is None:
- self.migrate_old_settings(settings)
+ util.migrate_old_settings(settings)
if current is not None and current < 3:
- self.migrate_settings_configuration(
+ self.migrate_settings_3(settings)
+
+ if current is not None and current < 4:
+ self.migrate_settings_4(settings)
+
+ def migrate_settings_3(self, settings):
+ util.migrate_settings_configuration(
settings,
"shortStatus_navbar",
"navbar",
)
- if current is not None and current < 4:
- self.migrate_settings_4(
- settings
- )
-
- def migrate_old_settings(self, settings):
- '''
- For Old settings
- '''
- self.migrate_settings(settings, "serialport", "connection", "port")
- self.migrate_settings(settings, "replace_connection_panel", "connection", "replace_connection_panel")
- self.migrate_settings(settings, "probeHeight", "probe", "height")
- self.migrate_settings(settings, "probeLift", "probe", "lift")
- self.migrate_settings(settings, "probeSpeedXy", "probe", "speed_xy")
- self.migrate_settings(settings, "probeSpeedZ", "probe", "speed_z")
- self.migrate_settings(settings, "configPath", "configuration", "configpath")
-
- if settings.has(["probePoints"]):
- points = settings.get(["probePoints"])
- points_new = [dict(name="", x=int(p["x"]), y=int(p["y"]), z=0) for p in points]
- settings.set(["probe", "points"], points_new)
- settings.remove(["probePoints"])
-
- def migrate_settings(self, settings, old, new, new2=""):
- """migrate setting to setting with additional group
-
- Args:
- settings (any): instance of self._settings
- old (str): the old setting to migrate
- new (str): group or only new setting if there is no new2
- new2 (str, optional): the new setting to migrate to. Defaults to "".
- """ ''''''
- if settings.has([old]):
- if new2 != "":
- logger.log_info(self, "migrate setting for '" + old + "' -> '" + new + "/" + new2 + "'")
- settings.set([new, new2], settings.get([old]))
- else:
- logger.log_info(self, "migrate setting for '" + old + "' -> '" + new + "'")
- settings.set([new], settings.get([old]))
- settings.remove([old])
-
- def migrate_settings_configuration(self, settings, new, old):
- if settings.has(["configuration", old]):
- logger.log_info(self, "migrate setting for 'configuration/" + old + "' -> 'configuration/" + new + "'")
- settings.set(["configuration", new], settings.get(["configuration", old]))
- settings.remove(["configuration", old])
-
def migrate_settings_4(self, settings):
-
- cfg_path = settings.get(["configuration", "configpath"])
-
- new_cfg_path, baseconfig = os.path.split(cfg_path)
- logger.log_info(self, "migrate setting for 'configuration/configpath': " + cfg_path + " -> " + new_cfg_path)
- logger.log_info(self, "migrate setting for 'configuration/baseconfig': printer.cfg -> " + baseconfig)
- settings.set(["configuration", "configpath"], new_cfg_path)
- settings.set(["configuration", "baseconfig"], baseconfig)
-
- if settings.get(["configuration", "reload_command"]) != "manually" :
- logger.log_info(self, "migrate setting for 'configuration/restart_onsave': False -> True")
- settings.set(["configuration", "restart_onsave"], True)
+ if settings.has(["configuration", "configpath"]):
+ cfg_path = settings.get(["configuration", "configpath"])
+ new_cfg_path, baseconfig = os.path.split(cfg_path)
+ logger.log_info(self, "migrate setting for 'configuration/config_path': " + cfg_path + " -> " + new_cfg_path)
+ logger.log_info(self, "migrate setting for 'configuration/baseconfig': printer.cfg -> " + baseconfig)
+ settings.set(["configuration", "config_path"], new_cfg_path)
+ settings.set(["configuration", "baseconfig"], baseconfig)
+ settings.remove(["configuration", "configpath"])
+ if (
+ settings.has(["configuration", "reload_command"])
+ and settings.get(["configuration", "reload_command"]) == "manually"
+ ):
+ logger.log_info(self, "migrate setting for 'configuration/restart_onsave': True -> False")
+ settings.set(["configuration", "restart_onsave"], False)
+ settings.remove(["configuration", "reload_command"])
if settings.has(["config"]):
logger.log_info(self, "remove old setting for 'config'")
@@ -447,7 +409,7 @@ class KlipperPlugin(
from octoprint.server.util.tornado import LargeResponseHandler, path_validation_factory
from octoprint.util import is_hidden_path
configpath = os.path.expanduser(
- self._settings.get(["configuration", "configpath"])
+ self._settings.get(["configuration", "config_path"])
)
bak_path = os.path.join(self.get_plugin_data_folder(), "configs", "")
@@ -506,7 +468,7 @@ class KlipperPlugin(
@Permissions.PLUGIN_KLIPPER_CONFIG.require(403)
def restore_backup(self, filename):
configpath = os.path.expanduser(
- self._settings.get(["configuration", "configpath"])
+ self._settings.get(["configuration", "config_path"])
)
data_folder = self.get_plugin_data_folder()
backupfile = os.path.realpath(os.path.join(data_folder, "configs", filename))
@@ -519,7 +481,7 @@ class KlipperPlugin(
@Permissions.PLUGIN_KLIPPER_CONFIG.require(403)
def get_config(self, filename):
cfg_path = os.path.expanduser(
- self._settings.get(["configuration", "configpath"])
+ self._settings.get(["configuration", "config_path"])
)
full_path = os.path.realpath(os.path.join(cfg_path, filename))
response = cfgUtils.get_cfg(self, full_path)
@@ -531,7 +493,7 @@ class KlipperPlugin(
@Permissions.PLUGIN_KLIPPER_CONFIG.require(403)
def delete_config(self, filename):
cfg_path = os.path.expanduser(
- self._settings.get(["configuration", "configpath"])
+ self._settings.get(["configuration", "config_path"])
)
full_path = os.path.realpath(os.path.join(cfg_path, filename))
if (
@@ -553,7 +515,7 @@ class KlipperPlugin(
def list_configs(self):
files = cfgUtils.list_cfg_files(self, "")
path = os.path.expanduser(
- self._settings.get(["configuration", "configpath"])
+ self._settings.get(["configuration", "config_path"])
)
return flask.jsonify(files = files, path = path, max_upload_size = MAX_UPLOAD_SIZE)
diff --git a/octoprint_klipper/cfgUtils.py b/octoprint_klipper/cfgUtils.py
index 07b8481..477057d 100644
--- a/octoprint_klipper/cfgUtils.py
+++ b/octoprint_klipper/cfgUtils.py
@@ -32,7 +32,7 @@ def list_cfg_files(self, path):
cfg_path = os.path.join(self.get_plugin_data_folder(), "configs", "*")
else:
cfg_path = os.path.expanduser(
- self._settings.get(["configuration", "configpath"])
+ self._settings.get(["configuration", "config_path"])
)
cfg_path = os.path.join(cfg_path, "*.cfg")
cfg_files = glob.glob(cfg_path)
@@ -127,7 +127,7 @@ def save_cfg(self, content, filename):
)
- configpath = os.path.expanduser(self._settings.get(["configuration", "configpath"]))
+ configpath = os.path.expanduser(self._settings.get(["configuration", "config_path"]))
if filename == "":
filename = self._settings.get(["configuration", "baseconfig"])
if filename[-4:] != ".cfg":
diff --git a/octoprint_klipper/static/js/klipper.js b/octoprint_klipper/static/js/klipper.js
index 61121b5..9c41b64 100644
--- a/octoprint_klipper/static/js/klipper.js
+++ b/octoprint_klipper/static/js/klipper.js
@@ -178,8 +178,8 @@ $(function () {
self.shortStatus_navbar(msg);
self.shortStatus_navbar_hover(baseText);
}
-
- self.shortStatus_sidebar(msg);
+ message = msg.replace(/\n/gi, "
");
+ self.shortStatus_sidebar(message);
};
diff --git a/octoprint_klipper/static/js/klipper_settings.js b/octoprint_klipper/static/js/klipper_settings.js
index b14a945..29d2b06 100644
--- a/octoprint_klipper/static/js/klipper_settings.js
+++ b/octoprint_klipper/static/js/klipper_settings.js
@@ -94,14 +94,16 @@ $(function () {
if (!self.klipperViewModel.hasRight("CONFIG")) return;
var baseconfig = self.settings.settings.plugins.klipper.configuration.baseconfig();
- self.klipperViewModel.consoleMessage("debug", "loadBaseConfig:" + baseconfig);
- OctoPrint.plugins.klipper.getCfg(baseconfig).done(function (response) {
- var config = {
- content: response.response.config,
- file: baseconfig,
- };
- self.klipperEditorViewModel.process(config).then();
- });
+ if (baseconfig != "") {
+ self.klipperViewModel.consoleMessage("debug", "loadBaseConfig:" + baseconfig);
+ OctoPrint.plugins.klipper.getCfg(baseconfig).done(function (response) {
+ var config = {
+ content: response.response.config,
+ file: baseconfig,
+ };
+ self.klipperEditorViewModel.process(config).then();
+ });
+ }
};
self.removeCfg = function (config) {
diff --git a/octoprint_klipper/templates/klipper_settings.jinja2 b/octoprint_klipper/templates/klipper_settings.jinja2
index 8930d21..3209946 100644
--- a/octoprint_klipper/templates/klipper_settings.jinja2
+++ b/octoprint_klipper/templates/klipper_settings.jinja2
@@ -52,7 +52,7 @@