🐞 fix: Cfg: parse configpath for new setting
-parse old configpath setting into configpath and baseconfig settings -load config on start with the filename from the baseconfig setting
This commit is contained in:
parent
2efb8ca37b
commit
f494fc00c1
|
@ -131,6 +131,7 @@ class KlipperPlugin(
|
|||
configuration=dict(
|
||||
debug_logging=False,
|
||||
configpath="~/",
|
||||
baseconfig="printer.cfg",
|
||||
old_config="",
|
||||
logpath="/tmp/klippy.log",
|
||||
reload_command="RESTART",
|
||||
|
@ -171,10 +172,12 @@ class KlipperPlugin(
|
|||
# Settings_Versionhistory:
|
||||
# 3 = add shortstatus on navbar. migrate the navbar setting for this
|
||||
# 4 = -change of configpath to only path without filename
|
||||
# -add setting for restart checkbox on editor save
|
||||
# -parse configpath into path and baseconfig if not standard printer.cfg
|
||||
# -switch setting for 'restart on editor save' to true if it was not set to manually
|
||||
# -remove old_config
|
||||
# -remove config on root settingsdirectory
|
||||
return 4
|
||||
|
||||
|
||||
#migrate Settings
|
||||
def on_settings_migrate(self, target, current):
|
||||
settings = self._settings
|
||||
|
@ -189,23 +192,10 @@ class KlipperPlugin(
|
|||
)
|
||||
|
||||
if current is not None and current < 4:
|
||||
self.migrate_settings_configuration(
|
||||
settings,
|
||||
"old_config",
|
||||
"temp_config",
|
||||
self.migrate_settings_4(
|
||||
settings
|
||||
)
|
||||
|
||||
cfg_path = settings.get(["configuration", "configpath"])
|
||||
if cfg_path.find("printer.cfg") != -1:
|
||||
new_cfg_path = cfg_path.replace("printer.cfg","")
|
||||
logger.log_info(self, "migrate setting for 'configuration/configpath': " + cfg_path + " -> " + new_cfg_path)
|
||||
settings.set(["configuration", "configpath"], new_cfg_path)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def migrate_old_settings(self, settings):
|
||||
'''
|
||||
For Old settings
|
||||
|
@ -248,6 +238,32 @@ class KlipperPlugin(
|
|||
settings.set(["configuration", new], settings.get(["configuration", old]))
|
||||
settings.remove(["configuration", old])
|
||||
|
||||
def migrate_settings_4(self, settings):
|
||||
|
||||
cfg_path = settings.get(["configuration", "configpath"])
|
||||
if cfg_path.find("printer.cfg") != -1:
|
||||
new_cfg_path = cfg_path.replace("printer.cfg","")
|
||||
logger.log_info(self, "migrate setting for 'configuration/configpath': " + cfg_path + " -> " + new_cfg_path)
|
||||
settings.set(["configuration", "configpath"], new_cfg_path)
|
||||
else:
|
||||
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(["config"]):
|
||||
logger.log_info(self, "remove old setting for 'config'")
|
||||
settings.remove(["config"])
|
||||
|
||||
if settings.has(["configuration", "old_config"]):
|
||||
logger.log_info(self, "remove old setting for 'configuration/old_config'")
|
||||
settings.remove(["configuration", "old_config"])
|
||||
|
||||
|
||||
# -- Template Plugin
|
||||
def get_template_configs(self):
|
||||
|
|
|
@ -71,7 +71,7 @@ def get_cfg(self, file):
|
|||
cfg_path = os.path.expanduser(
|
||||
self._settings.get(["configuration", "configpath"])
|
||||
)
|
||||
file = os.path.join(cfg_path, "printer.cfg")
|
||||
file = os.path.join(cfg_path, self._settings.get(["configuration", "baseconfig"]))
|
||||
if util.file_exist(self, file):
|
||||
logger.log_debug(self, "get_cfg_files Path: " + file)
|
||||
try:
|
||||
|
@ -95,7 +95,7 @@ def get_cfg(self, file):
|
|||
response['text'] = gettext("File not found!")
|
||||
return response
|
||||
|
||||
def save_cfg(self, content, filename="printer.cfg"):
|
||||
def save_cfg(self, content, filename):
|
||||
"""Save the configuration file to given file.
|
||||
|
||||
Args:
|
||||
|
@ -115,13 +115,15 @@ def save_cfg(self, content, filename="printer.cfg"):
|
|||
content = content.encode('utf-8')
|
||||
|
||||
configpath = os.path.expanduser(self._settings.get(["configuration", "configpath"]))
|
||||
if filename == "":
|
||||
filename = self._settings.get(["configuration", "baseconfig"])
|
||||
if filename[-4:] != ".cfg":
|
||||
filename += ".cfg"
|
||||
filepath = os.path.join(configpath, filename)
|
||||
|
||||
logger.log_debug(self, "save filepath: {}".format(filepath))
|
||||
|
||||
self._settings.set(["configuration", "temp_config"], content)
|
||||
self._settings.set(["configuration", "old_config"], content)
|
||||
|
||||
check_parse = self._settings.get(["configuration", "parse_check"])
|
||||
logger.log_debug(self, "check_parse on filesave: {}".format(check_parse))
|
||||
|
|
|
@ -185,24 +185,7 @@ $(function () {
|
|||
}
|
||||
};
|
||||
|
||||
self.loadLastSession = function () {
|
||||
if (self.settings.settings.plugins.klipper.configuration.old_config() != "") {
|
||||
self.klipperViewModel.consoleMessage(
|
||||
"info",
|
||||
"lastSession:" +
|
||||
self.settings.settings.plugins.klipper.configuration.old_config()
|
||||
);
|
||||
if (editor.session) {
|
||||
editor.session.setValue(
|
||||
self.settings.settings.plugins.klipper.configuration.old_config()
|
||||
);
|
||||
editor.clearSelection();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.reloadFromFile = function () {
|
||||
|
||||
OctoPrint.plugins.klipper.getCfg(self.CfgFilename())
|
||||
.done(function (response) {
|
||||
self.klipperViewModel.consoleMessage("debug", "reloadFromFile done");
|
||||
|
|
|
@ -86,11 +86,12 @@ $(function () {
|
|||
|
||||
self.loadBaseConfig = function () {
|
||||
if (!self.klipperViewModel.hasRight("CONFIG")) return;
|
||||
|
||||
OctoPrint.plugins.klipper.getCfg("printer.cfg").done(function (response) {
|
||||
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: "printer.cfg",
|
||||
file: baseconfig,
|
||||
};
|
||||
self.klipperEditorViewModel.process(config).then();
|
||||
});
|
||||
|
|
|
@ -31,9 +31,6 @@
|
|||
<button class="btn btn-small" data-bind="click: reloadFromFile" title="{{ _('Reload from file') }}">
|
||||
<i class="fas fa-upload"></i> {{ _('Reload from file') }}
|
||||
</button>
|
||||
<button class="btn btn-small" data-bind="click: loadLastSession" title="{{ _('Reload last version') }}">
|
||||
<i class="fas fa-redo"></i> {{ _('Reload last version') }}
|
||||
</button>
|
||||
<button class="btn btn-small" data-bind="click: checkSyntax" title="{{ _('Check Syntax') }}">
|
||||
<i class="fas fa-spell-check"></i> {{ _('Check Syntax') }}
|
||||
</button>
|
||||
|
|
|
@ -55,6 +55,12 @@
|
|||
<input type="text" class="input-block-level" data-bind="value: settings.settings.plugins.klipper.configuration.configpath" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" title="The filename of the base .cfg that is loaded for Klipper.(default is printer.cfg)">{{ _('Klipper Base Config Filename') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: settings.settings.plugins.klipper.configuration.baseconfig" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ _('Klipper Log File') }}</label>
|
||||
<div class="controls">
|
||||
|
|
Loading…
Reference in New Issue