🎨 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
This commit is contained in:
parent
e099b10c93
commit
f8764e3220
|
@ -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):
|
||||
|
||||
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/configpath': " + cfg_path + " -> " + new_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", "configpath"], new_cfg_path)
|
||||
settings.set(["configuration", "config_path"], 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)
|
||||
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)
|
||||
|
||||
|
|
|
@ -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":
|
||||
|
|
|
@ -178,8 +178,8 @@ $(function () {
|
|||
self.shortStatus_navbar(msg);
|
||||
self.shortStatus_navbar_hover(baseText);
|
||||
}
|
||||
|
||||
self.shortStatus_sidebar(msg);
|
||||
message = msg.replace(/\n/gi, "<br />");
|
||||
self.shortStatus_sidebar(message);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -94,6 +94,7 @@ $(function () {
|
|||
if (!self.klipperViewModel.hasRight("CONFIG")) return;
|
||||
|
||||
var baseconfig = self.settings.settings.plugins.klipper.configuration.baseconfig();
|
||||
if (baseconfig != "") {
|
||||
self.klipperViewModel.consoleMessage("debug", "loadBaseConfig:" + baseconfig);
|
||||
OctoPrint.plugins.klipper.getCfg(baseconfig).done(function (response) {
|
||||
var config = {
|
||||
|
@ -102,6 +103,7 @@ $(function () {
|
|||
};
|
||||
self.klipperEditorViewModel.process(config).then();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
self.removeCfg = function (config) {
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
<div class="control-group">
|
||||
<label class="control-label">{{ _('Klipper Config Directory') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: settings.settings.plugins.klipper.configuration.configpath" />
|
||||
<input type="text" class="input-block-level" data-bind="value: settings.settings.plugins.klipper.configuration.config_path" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
|
@ -96,6 +96,12 @@
|
|||
</div>
|
||||
<!-- Macros -->
|
||||
<div class="tab-pane" id="macros">
|
||||
<div class="control-group">
|
||||
<span class="help-block">
|
||||
{{ _('These macros are only meant to be used in OctoPrint.') }}
|
||||
{{ _('They are not the ones that can be defined in the printer.cfg.') }}<br />
|
||||
</span>
|
||||
</div>
|
||||
<div class="control-group" style="margin-bottom: 0px;">
|
||||
<div class="controls" style="margin-left: 82px;">
|
||||
<div class="row-fluid">
|
||||
|
@ -160,9 +166,7 @@
|
|||
<div class="tab-pane" id="level">
|
||||
<div class="control-group">
|
||||
<span class="help-block">
|
||||
{{ _('This feature assists in manually leveling you print bed by moving the head to the defined points in
|
||||
sequence.<br />
|
||||
If you use a piece of paper for leveling, set "Probe Height" to the paper thickness eg. "0.1".') }}
|
||||
{{ _('This feature assists in manually leveling your print bed by moving the head to the defined points in sequence.<br />If you use a piece of paper for leveling, set "Probe Height" to the paper thickness eg. "0.1".') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
</div>
|
||||
<!-- ko if: settings.settings.plugins.klipper.configuration.shortStatus_sidebar -->
|
||||
<div id="shortStatus_SideBar" class="plugin-klipper-sidebar">
|
||||
<a title="{{ _('Go to OctoKlipper Tab') }}" data-bind="text: shortStatus_sidebar, click: navbarClicked"></a>
|
||||
<a title="{{ _('Go to OctoKlipper Tab') }}" data-bind="click: navbarClicked">
|
||||
<div data-bind="html: shortStatus_sidebar" class="msg"></div>
|
||||
</a>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
<div class="control-group" data-bind="visible: $root.loginState.hasPermissionKo($root.access.permissions.PLUGIN_KLIPPER_MACRO)">
|
||||
|
|
|
@ -1,3 +1,57 @@
|
|||
from . import logger
|
||||
|
||||
def migrate_old_settings(self, settings):
|
||||
'''
|
||||
For Old settings
|
||||
'''
|
||||
migrate_settings(settings, "serialport", "connection", "port")
|
||||
migrate_settings(settings, "replace_connection_panel", "connection", "replace_connection_panel")
|
||||
migrate_settings(settings, "probeHeight", "probe", "height")
|
||||
migrate_settings(settings, "probeLift", "probe", "lift")
|
||||
migrate_settings(settings, "probeSpeedXy", "probe", "speed_xy")
|
||||
migrate_settings(settings, "probeSpeedZ", "probe", "speed_z")
|
||||
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 an additional path
|
||||
|
||||
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):
|
||||
"""migrate setting in path configuration to new name
|
||||
|
||||
:param settings: the class of the mixin
|
||||
:type settings: class
|
||||
:param new: new name
|
||||
:type new: str
|
||||
:param old: the old name
|
||||
:type old: str
|
||||
"""
|
||||
|
||||
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 poll_status(self):
|
||||
self._printer.commands("STATUS")
|
||||
|
||||
|
@ -14,6 +68,7 @@ def file_exist(self, filepath):
|
|||
'''
|
||||
from os import path
|
||||
if not path.isfile(filepath):
|
||||
logger.log_debug(self, "File: <br />" + filepath + "<br /> does not exist!")
|
||||
send_message(
|
||||
self,
|
||||
type = "PopUp",
|
||||
|
|
Loading…
Reference in New Issue