From d81504c12e84c07a767176f93a40f61f790ce3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 11 Apr 2022 16:51:22 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20Fix=20folder=20saving=20&=20?= =?UTF-8?q?config=20migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings._config has been turned into a read-only view by the recent refactoring of the settings hierarchy. Refactored our use as needed to still function and added deprecated decorator to getter and setter property to communicate this change in behaviour. _config wasn't documented, so it is not part of the official API and thus this doesn't qualify as a breaking change, however there might be plugins there that went beyond the documented API and use it in some way (possibly even stuff I have written in the past), so best give them a heads-up. Closes #4486 --- src/octoprint/server/api/settings.py | 1 + src/octoprint/settings.py | 67 +++++++++++++++++----------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index c48642a70..14d065804 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -490,6 +490,7 @@ def _saveSettings(data): s.setBaseFolder(folder, future[folder]) except Exception: + logger.exception("Something went wrong while saving a folder path") abort(400, description="At least one of the configured folders is invalid") if "api" in data: diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 649090240..c92eced73 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -34,6 +34,7 @@ from yaml import YAMLError from octoprint.util import ( CaseInsensitiveSet, atomic_write, + deprecated, dict_merge, fast_deepcopy, generate_api_key, @@ -862,7 +863,6 @@ class Settings: self._map = HierarchicalChainMap({}, default_settings) self.load_overlays(overlays) - self._config = None self._dirty = False self._dirty_time = 0 self._last_config_hash = None @@ -1125,7 +1125,7 @@ class Settings: @property def config_yaml(self): - return yaml.dump(self._config) + return yaml.dump(self.config) @property def config_hash(self): @@ -1140,10 +1140,28 @@ class Settings: return self._last_config_hash @property - def _config(self): + def config(self): + """ + A view of the local config as stored in config.yaml + + Does not support modifications, they will be thrown away silently. If you need to + modify anything in the settings, utilize the provided set and remove methods. + """ return self._map.top_map + @property + @deprecated( + "Settings._config has been deprecated and is a read-only view. Please use Settings.config or the set & remove methods instead.", + since="1.8.0", + ) + def _config(self): + return self.config + @_config.setter + @deprecated( + "Setting of Settings._config has been deprecated. Please use the set & remove methods instead and get in touch if you have a usecase they don't cover.", + since="1.8.0", + ) def _config(self, value): self._map.top_map = value @@ -1174,11 +1192,14 @@ class Settings: # ~~ load and save def load(self, migrate=False): + config = None + mtime = None + if os.path.exists(self._configfile) and os.path.isfile(self._configfile): with open(self._configfile, encoding="utf-8", errors="replace") as f: try: - self._config = yaml.load_from_file(file=f) - self._mtime = self.last_modified + config = yaml.load_from_file(file=f) + mtime = self.last_modified except YAMLError as e: details = str(e) @@ -1198,8 +1219,11 @@ class Settings: ) # changed from else to handle cases where the file exists, but is empty / 0 bytes - if not self._config or not isinstance(self._config, dict): - self._config = {} + if not config or not isinstance(config, dict): + config = {} + + self._map.top_map = config + self._mtime = mtime if migrate: self._migrate_config() @@ -1293,7 +1317,7 @@ class Settings: def _migrate_config(self, config=None, persist=False): if config is None: - config = self._config + config = self._map.top_map persist = True dirty = False @@ -1315,6 +1339,9 @@ class Settings: dirty = migrate(config) or dirty if dirty and persist: + self._map.top_map = ( + config # we need to write it back here or the changes will be lost + ) self.save(force=True) def _migrate_gcode_scripts(self, config): @@ -1833,7 +1860,7 @@ class Settings: permissions=0o600, max_permissions=0o666, ) as configFile: - yaml.save_to_file(self._config, file=configFile) + yaml.save_to_file(self._map.top_map, file=configFile) self._dirty = False except Exception: self._logger.exception("Error while saving config.yaml!") @@ -2072,10 +2099,7 @@ class Settings: folder = default_folder try: - del self._config["folder"][type] - if not len(self._config["folder"]): - del self._config["folder"] - self._mark_dirty() + self.remove(["folder", type]) self.save() except KeyError: pass @@ -2270,23 +2294,12 @@ class Settings: currentPath = self.getBaseFolder(type) defaultPath = self._get_default_folder(type) - if ( - (path is None or path == defaultPath) - and "folder" in self._config - and type in self._config["folder"] - ): - del self._config["folder"][type] - if not self._config["folder"]: - del self._config["folder"] - self._mark_dirty() + if path is None or path == defaultPath: + self.remove(["folder", type]) elif (path != currentPath and path != defaultPath) or force: if validate: _validate_folder(path, check_writable=True, deep_check_writable=True) - - if "folder" not in self._config: - self._config["folder"] = {} - self._config["folder"][type] = path - self._mark_dirty() + self.set(["folder", type], path, force=force) def saveScript(self, script_type, name, script): script_folder = self.getBaseFolder("scripts") From 2ecc1c944f9f00bbd4a3e273f0c591e74d06305d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 12 Apr 2022 14:26:55 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=A5=85=20Only=20use=20the=20first=20v?= =?UTF-8?q?alue=20pair=20for=20a=20temp=20sensor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This protects against lines from the printer like T:210.04 /210.00 B:52.00 /52.00 @:85 B:1234.0 /1234.0 We've seen *so* much weird stuff out there in firmware, let's better be safe rather than sorry and rule out latter values from overwriting former values just in case. --- src/octoprint/util/comm.py | 4 ++++ tests/util/test_comm_helpers.py | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 9677002ae..d06b9529b 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -6268,6 +6268,10 @@ def parse_temperature_line(line, current): for match in re.finditer(regex_temp, line): values = match.groupdict() sensor = values["sensor"] + if sensor in result: + # sensor already seen, let's not overwrite stuff + continue + toolnum = values.get("toolnum", None) tool_number = int(toolnum) if toolnum is not None and len(toolnum) else None if tool_number and tool_number > max_tool_num: diff --git a/tests/util/test_comm_helpers.py b/tests/util/test_comm_helpers.py index ac600b978..7bcf90386 100644 --- a/tests/util/test_comm_helpers.py +++ b/tests/util/test_comm_helpers.py @@ -330,6 +330,16 @@ class TestCommHelpers(unittest.TestCase): }, 0, ), + ( + # Only first occurrence of a sensor should be used, second B gets ignored + "T:210.04 /210.00 B:52.00 /52.00 @:85 B:1234.0 /1234.0", + 0, + { + "T0": (210.04, 210.0), + "B": (52.00, 52.0), + }, + 0, + ), ) @unpack def test_process_temperature_line(self, line, current, expected_result, expected_max): From 45598764e6c7f6257de87a98d15964209ddc9e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 12 Apr 2022 15:30:56 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=94=96=20Preparing=20release=20of=201?= =?UTF-8?q?.8.0rc5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/plugins/errortracking/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/plugins/errortracking/__init__.py b/src/octoprint/plugins/errortracking/__init__.py index e15b1bb57..ad47d8a25 100644 --- a/src/octoprint/plugins/errortracking/__init__.py +++ b/src/octoprint/plugins/errortracking/__init__.py @@ -18,10 +18,10 @@ from octoprint.util.version import ( ) SENTRY_URL_SERVER = ( - "https://b39cd0dcaea5404798ec3eb193b291db@o118517.ingest.sentry.io/1373987" + "https://890bd6bca44a4b7e92918b0ba74049ca@o118517.ingest.sentry.io/1373987" ) SENTRY_URL_COREUI = ( - "https://ab48b21452fe424eaf79468aa6c94bd7@o118517.ingest.sentry.io/1374096" + "https://1f4ba2d14bfc4b1c9a861fde1c1d452d@o118517.ingest.sentry.io/1374096" ) SETTINGS_DEFAULTS = { From 53dbde2ef97c6152841fce3fd35ff43252f4931e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 12 Apr 2022 16:21:41 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=94=96=20staging/maintenance=20is=20n?= =?UTF-8?q?ow=201.8.0rc6.dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .versioneer-lookup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.versioneer-lookup b/.versioneer-lookup index cafc426ae..d1d2e65bc 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -29,10 +29,10 @@ improve/.* 1.8.0 3fe45661cd79c5137d9d4f5f4adb4d9519bc2084 pep440-dev staging/bugfix 1.7.4 59cbfadf8922d85b9df40f8d0173e8c21724c3b8 pep440-dev bug/.* 1.7.4 59cbfadf8922d85b9df40f8d0173e8c21724c3b8 pep440-dev -# staging/maintenance is currently the branch for preparation of 1.8.0rc4 +# staging/maintenance is currently the branch for preparation of 1.8.0rc6 # so is regressionfix/... -staging/maintenance 1.8.0rc5 c5b095a8b905d759c84acab5e8a65ed3170d124c pep440-dev -regressionfix/.* 1.8.0rc5 c5b095a8b905d759c84acab5e8a65ed3170d124c pep440-dev +staging/maintenance 1.8.0rc6 45598764e6c7f6257de87a98d15964209ddc9e09 pep440-dev +regressionfix/.* 1.8.0rc6 45598764e6c7f6257de87a98d15964209ddc9e09 pep440-dev # staging/devel is currently inactive (but has the 1.4.1rc4 namespace) staging/devel 1.4.1rc4 650d54d1885409fa1d411eb54b9e8c7ff428910f pep440-dev