♻️ refactor(setting): migration baseconfig
-refactor the migration for the baseconfig - remove old_config setting - change name for self.ConfigChangedAfterSave_Config()
This commit is contained in:
parent
c9b2d3a49b
commit
ef05c3e271
|
@ -132,7 +132,6 @@ class KlipperPlugin(
|
|||
debug_logging=False,
|
||||
configpath="~/",
|
||||
baseconfig="printer.cfg",
|
||||
old_config="",
|
||||
logpath="/tmp/klippy.log",
|
||||
reload_command="RESTART",
|
||||
restart_onsave=True,
|
||||
|
@ -242,16 +241,12 @@ class KlipperPlugin(
|
|||
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)
|
||||
|
||||
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")
|
||||
|
|
|
@ -122,19 +122,18 @@ def save_cfg(self, content, 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", "old_config"], content)
|
||||
|
||||
check_parse = self._settings.get(["configuration", "parse_check"])
|
||||
logger.log_debug(self, "check_parse on filesave: {}".format(check_parse))
|
||||
|
||||
if check_parse and not check_cfg(self, content):
|
||||
return False
|
||||
|
||||
logger.log_debug(self, "Writing Klipper config to {}".format(filepath))
|
||||
try:
|
||||
logger.log_debug(self, "Writing Klipper config to {}".format(filepath))
|
||||
with open(filepath, "w") as f:
|
||||
f.write(content)
|
||||
except IOError:
|
||||
|
|
|
@ -100,6 +100,7 @@ $(function () {
|
|||
}
|
||||
};
|
||||
|
||||
//initialize the modal window and return done when finished
|
||||
self.process = function (config) {
|
||||
return new Promise(function (resolve) {
|
||||
self.loadedConfig = config.content;
|
||||
|
@ -110,7 +111,6 @@ $(function () {
|
|||
editor.session.setValue(self.CfgContent());
|
||||
self.CfgChangedExtern = false;
|
||||
editor.setFontSize(self.settings.settings.plugins.klipper.configuration.fontsize());
|
||||
self.settings.settings.plugins.klipper.configuration.old_config(config.content);
|
||||
editor.clearSelection();
|
||||
self.klipperViewModel.sleep(500).then(
|
||||
function() {
|
||||
|
@ -123,13 +123,15 @@ $(function () {
|
|||
}
|
||||
|
||||
self.onDataUpdaterPluginMessage = function (plugin, data) {
|
||||
//receive from backend after a SAVE_CONFIG
|
||||
if (plugin == "klipper" && data.type == "reload" && data.subtype == "config") {
|
||||
self.klipperViewModel.consoleMessage("debug", "onDataUpdaterPluginMessage klipper reload baseconfig");
|
||||
self.ConfigChangedAfterSave();
|
||||
self.ConfigChangedAfterSave_Config();
|
||||
}
|
||||
};
|
||||
|
||||
self.ConfigChangedAfterSave = function () {
|
||||
//set externally changed config flag if the current file is the base config
|
||||
self.ConfigChangedAfterSave_Config = function () {
|
||||
if (!self.klipperViewModel.hasRight("CONFIG")) return;
|
||||
|
||||
if (self.CfgFilename() == self.settings.settings.plugins.klipper.configuration.baseconfig()) {
|
||||
|
@ -138,6 +140,7 @@ $(function () {
|
|||
}
|
||||
};
|
||||
|
||||
//check if the config was externally changed and ask for a reload
|
||||
self.checkExternChange = function() {
|
||||
var baseconfig = self.settings.settings.plugins.klipper.configuration.baseconfig();
|
||||
if (self.CfgChangedExtern && self.CfgFilename() == baseconfig) {
|
||||
|
@ -195,7 +198,7 @@ $(function () {
|
|||
|
||||
if (response.saved === true) {
|
||||
self.klipperViewModel.showPopUp("success", gettext("Save Config"), gettext("File saved."));
|
||||
self.loadedConfig = editor.session.getValue();
|
||||
self.loadedConfig = editor.session.getValue(); //set loaded config to current for resetting dirtyEditor
|
||||
if (closing) {
|
||||
editordialog.modal('hide');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue