From 361162aac2ed906b393d05bc4a69d0e41a8a4457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 11 Mar 2021 17:43:55 +0100 Subject: [PATCH 01/11] =?UTF-8?q?=F0=9F=91=B7=20Disable=20maintenance->dev?= =?UTF-8?q?el=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Turns out it doesn't trigger the build action, so we'd never see pre-commit runs on those merges - we really really don't want that. Manual it is :/ --- .github/workflows/nightly_merge.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/nightly_merge.yml b/.github/workflows/nightly_merge.yml index fc74e5415..4d54ff64c 100644 --- a/.github/workflows/nightly_merge.yml +++ b/.github/workflows/nightly_merge.yml @@ -23,11 +23,11 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: 🔀 Merge maintenance into devel - uses: robotology/gh-action-nightly-merge@v1.3.2 - with: - stable_branch: "maintenance" - development_branch: "devel" - allow_ff: false - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + #- name: 🔀 Merge maintenance into devel + # uses: robotology/gh-action-nightly-merge@v1.3.2 + # with: + # stable_branch: "maintenance" + # development_branch: "devel" + # allow_ff: false + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 90f1a44c2de70496d7ef8c5c6a40aa352a19a28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 12 Mar 2021 18:11:59 +0100 Subject: [PATCH 02/11] =?UTF-8?q?=F0=9F=94=8A=20Increase=20timings=20loggi?= =?UTF-8?q?ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now can also log on entering the decorated function. --- src/octoprint/filemanager/storage.py | 1 + src/octoprint/server/api/files.py | 2 ++ src/octoprint/util/__init__.py | 39 ++++++++++++++++------------ 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index 4c9662145..bc3d59d40 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -1508,6 +1508,7 @@ class LocalFileStorage(StorageInterface): logtarget=__name__ + ".timings", message="{func}({func_args},{func_kwargs}) took {timing:.2f}ms", incl_func_args=True, + log_enter=True, ) def _list_folder(self, path, base="", force_refresh=False, **kwargs): def get_size(nodes): diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index 10a0a6a04..17cd6b038 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -247,6 +247,8 @@ def _getFileDetails(origin, path, recursive=True): logtarget=__name__ + ".timings", message="{func}({func_args},{func_kwargs}) took {timing:.2f}ms", incl_func_args=True, + log_enter=True, + message_enter="Entering {func}({func_args},{func_kwargs})...", ) def _getFileList( origin, path=None, filter=None, recursive=False, level=0, allow_from_cache=True diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index 6648645bf..ac27abb8e 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -1900,33 +1900,38 @@ def time_this( expand_logtarget=False, message="{func} took {timing:.2f}ms", incl_func_args=False, + log_enter=False, + message_enter="Entering {func}...", ): def decorator(f): + func = fqfn(f) + + lt = logtarget + if expand_logtarget: + lt += "." + func + + logger = logging.getLogger(lt) + @wraps(f) def wrapper(*args, **kwargs): + data = {"func": func} + if incl_func_args and logger.isEnabledFor(logging.DEBUG): + data.update( + func_args=",".join(map(repr, args)), + func_kwargs=",".join( + map(lambda x: "{}={!r}".format(x[0], x[1]), kwargs.items()) + ), + ) + if log_enter: + logger.debug(message_enter.format(**data), extra=data) + start = time.time() try: return f(*args, **kwargs) finally: timing = (time.time() - start) * 1000 - func = fqfn(f) - - lt = logtarget - if expand_logtarget: - lt += "." + func - - logger = logging.getLogger(lt) if logger.isEnabledFor(logging.DEBUG): - data = {"func": func, "timing": timing} - if incl_func_args: - data.update( - func_args=",".join(map(repr, args)), - func_kwargs=",".join( - map( - lambda x: "{}={!r}".format(x[0], x[1]), kwargs.items() - ) - ), - ) + data.update(timing=timing) logger.debug(message.format(**data), extra=data) return wrapper From 89273598ae987965b7835d9f66d45c5942eba613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 12 Mar 2021 18:12:38 +0100 Subject: [PATCH 03/11] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Don't=20calculate=20?= =?UTF-8?q?last=20modified=20twice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/filemanager/storage.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index bc3d59d40..954d18807 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -1536,11 +1536,8 @@ class LocalFileStorage(StorageInterface): try: with self._filelist_cache_mutex: cache = self._filelist_cache.get(path) - if ( - not force_refresh - and cache - and cache[0] >= self.last_modified(path, recursive=True) - ): + lm = self.last_modified(path, recursive=True) + if not force_refresh and cache and cache[0] >= lm: return enrich_folders(cache[1]) metadata = self._get_metadata(path) @@ -1681,7 +1678,7 @@ class LocalFileStorage(StorageInterface): continue self._filelist_cache[path] = ( - self.last_modified(path, recursive=True), + lm, result, ) return enrich_folders(result) From f64abb22b3cd1c2b73d483f8a04edf5b9999b728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 12 Mar 2021 18:13:11 +0100 Subject: [PATCH 04/11] =?UTF-8?q?=F0=9F=90=9B=20Fix=20file=20name=20valida?= =?UTF-8?q?tion=20never=20validating?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/server/api/files.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index 17cd6b038..385daee99 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -218,7 +218,7 @@ def readGcodeFile(target, filename): if target not in [FileDestinations.LOCAL, FileDestinations.SDCARD]: abort(404) - if filename != fileManager.sanitize(target, filename): + if not _validate(target, filename): abort(404) recursive = False @@ -735,7 +735,7 @@ def gcodeFileCommand(filename, target): if target not in [FileDestinations.LOCAL, FileDestinations.SDCARD]: abort(404) - if filename != fileManager.sanitize(target, filename): + if not _validate(target, filename): abort(404) # valid file commands, dict mapping command name to mandatory parameters @@ -1101,7 +1101,7 @@ def gcodeFileCommand(filename, target): @no_firstrun_access @Permissions.FILES_DELETE.require(403) def deleteGcodeFile(filename, target): - if filename != fileManager.sanitize(target, filename): + if not _validate(target, filename): abort(404) if not _verifyFileExists(target, filename) and not _verifyFolderExists( @@ -1166,6 +1166,12 @@ def _getCurrentFile(): return None, None +def _validate(target, filename): + return filename == "/".join( + map(lambda x: fileManager.sanitize_name(target, x), filename.split("/")) + ) + + class WerkzeugFileWrapper(octoprint.filemanager.util.AbstractFileWrapper): """ A wrapper around a Werkzeug ``FileStorage`` object. From 1c916681949098176fb6c88cfe7781366eb953b0 Mon Sep 17 00:00:00 2001 From: cp2004 <31997505+cp2004@users.noreply.github.com> Date: Sat, 13 Mar 2021 17:39:16 +0000 Subject: [PATCH 05/11] :bug: Fix log validation `path` in this context is just `octoprint.log`, so the path validation is useless - it will always look in the basedir, because that is where Tornado has been told to look. No other validators do the same as far as I can see (timelapse and files). Closes #4045 :art: Pretty --- src/octoprint/server/__init__.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 66580108f..6a92032bb 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -766,13 +766,9 @@ class Server(object): ) } - valid_log = ( - lambda path: not octoprint.util.is_hidden_path(path) - and path.endswith(".log") - and os.path.realpath(os.path.abspath(path)).startswith( - settings().getBaseFolder("logs") - ) - ) + valid_log = lambda path: not octoprint.util.is_hidden_path( + path + ) and path.endswith(".log") log_path_validator = { "path_validation": util.tornado.path_validation_factory( valid_log, From aa9a2335ce6095f40284d85e649434cf3d22c7e9 Mon Sep 17 00:00:00 2001 From: cp2004 <31997505+cp2004@users.noreply.github.com> Date: Sat, 13 Mar 2021 21:36:37 +0000 Subject: [PATCH 06/11] :pencil2: Show meaningful message when software update is blocked And log when it is undervoltage. The problem here was twofold: first, a very generic message asking to check the log confused users. Second, there was nothing logged when it said check the logs. So, this changes that so the message is escaped and displayed in the pnotify and when the update is blocked for undervoltage this is logged. This does not add logging for other methods, since it seems unnecessary to me. Closes #4024 --- src/octoprint/plugins/softwareupdate/__init__.py | 8 ++++++-- .../softwareupdate/static/js/softwareupdate.js | 15 +++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 9203baa7d..45f951961 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -1086,10 +1086,14 @@ class SoftwareUpdatePlugin( and not self._settings.get_boolean(["ignore_throttled"]) ): # currently throttled, we refuse to run + message = ( + "System is currently throttled, refusing to update " + "anything due to possible stability issues" + ) + self._logger.error(message) flask.abort( 409, - description="System is currently throttled, refusing to update " - "anything due to possible stability issues", + description=message, ) if self._printer.is_printing() or self._printer.is_paused(): diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index b090c2651..56e8b6f75 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -680,13 +680,20 @@ $(function () { gettext("Updating, please wait.") ); }) - .fail(function () { + .fail(function (response) { self.updateInProgress = false; + var message = + "

" + + gettext( + "The update could not be started. Is it already active? Please consult octoprint.log for details." + ) + + "

" +
+                        _.escape(response.responseJSON.error) +
+                        "
"; + self._showPopup({ title: gettext("Update not started!"), - text: gettext( - "The update could not be started. Is it already active? Please consult octoprint.log for details." - ), + text: message, type: "error", hide: false, buttons: { From 7ea6969e13c9843b858a3d31535db73bcf448595 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 14 Mar 2021 09:02:17 -0500 Subject: [PATCH 07/11] Prevent script error in build setup --- docs/development/environment.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/development/environment.rst b/docs/development/environment.rst index 93756517b..9f3e05d6b 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -74,7 +74,7 @@ If you also want to be able to build the documentation that resides in the ``doc the *Python 3* environment and install the docs dependencies as well: * ``source venv3/bin/activate`` (Linux, macOS) or ``source venv3/Scripts/activate`` (Git Bash under Windows, see below) - * ``pip install -e .[develop,plugins,docs]`` + * ``pip install -e '.[develop,plugins,docs]'`` Go to the directory `docs` and you can then build the documentation: @@ -116,10 +116,10 @@ Then: virtualenv --python=python3 venv3 source ./venv2/bin/activate pip install --upgrade pip - pip install -e .[develop,plugins] + pip install -e '.[develop,plugins]' source ./venv3/bin/activate pip install --upgrade pip - pip install -e .[develop,plugins,docs] + pip install -e '.[develop,plugins,docs]' pre-commit install git config blame.ignoreRevsFile .git-blame-ignore-revs @@ -162,10 +162,10 @@ Open the Git Bash you just installed and in that: virtualenv --python=C:\Python38\python.exe venv3 source ./venv2/Scripts/activate python -m pip install --upgrade pip - pip install -e .[develop,plugins] + pip install -e '.[develop,plugins]' source ./venv3/Scripts/activate pip install --upgrade pip - python -m pip install -e .[develop,plugins,docs] + python -m pip install -e '.[develop,plugins,docs]' pre-commit install git config blame.ignoreRevsFile .git-blame-ignore-revs @@ -241,7 +241,7 @@ You'll need a user account with administrator privileges. virtualenv venv source venv/bin/activate pip install --upgrade pip - pip install -e .[develop,plugins] + pip install -e '.[develop,plugins]' pre-commit install git config blame.ignoreRevsFile .git-blame-ignore-revs @@ -291,7 +291,7 @@ PyCharm * Name: Update OctoPrint dependencies * Program: ``$ModuleSdkPath$`` - * Parameters: ``-m pip install -e .[develop,plugins]`` + * Parameters: ``-m pip install -e '.[develop,plugins]'`` * Working directory: ``$ProjectFileDir$`` Note that sadly that seems to cause some hiccups on current PyCharm versions due to ``$PyInterpreterDirectory$`` @@ -320,7 +320,7 @@ PyCharm the documentation, see above on how to set this up. Note that this requires you to also have installed the additional ``docs`` dependencies into the Python 3 venv as - described above via ``pip install -e .[develop,plugins,docs]``. + described above via ``pip install -e '.[develop,plugins,docs]'``. - Settings > Tools > File Watchers (you might have to enable this, it's a bundled plugin), add new: From 9ab2ba29b91d82bf4ef72f2d85b62aa5df278720 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 14 Mar 2021 06:21:55 -0500 Subject: [PATCH 08/11] Update temperature message regex --- AUTHORS.md | 1 + docs/configuration/config_yaml.rst | 4 ++-- src/octoprint/settings.py | 2 +- src/octoprint/static/js/app/viewmodels/settings.js | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index fae1ed362..81c0070d6 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -139,6 +139,7 @@ date of first contribution): * [Miroslav Šedivý](https://github.com/eumiro) * [Costas Basdekis](https://github.com/costas-basdekis) * [Joe Martella](https://github.com/martellaj) + * [Scott Lahteine](https://github.com/thinkyhead) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index 56a0a5fce..a945a6c2a 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -1132,9 +1132,9 @@ Use `Javascript regular expressions Date: Mon, 15 Mar 2021 14:21:15 +0100 Subject: [PATCH 09/11] =?UTF-8?q?=F0=9F=90=9B=20Fix=20file=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Was broken when debug logging was disabled due to timeThis decorator. --- src/octoprint/util/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index ac27abb8e..b8de4d210 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -1914,7 +1914,7 @@ def time_this( @wraps(f) def wrapper(*args, **kwargs): - data = {"func": func} + data = {"func": func, "func_args": "?", "func_kwargs": "?"} if incl_func_args and logger.isEnabledFor(logging.DEBUG): data.update( func_args=",".join(map(repr, args)), From 770492a955af22bb87d015a3d7918b67504eb938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 15 Mar 2021 14:57:17 +0100 Subject: [PATCH 10/11] =?UTF-8?q?=F0=9F=94=92=20Make=20sure=20to=20validat?= =?UTF-8?q?e=20log=20paths=20for=20zip=20bundle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also do the same for timelapses. For individual files, the LargeResponseHandler takes care of this validation. For zip downloads however, we need to do it. An earlier refactoring accidentally applied the same logic to the invididual downloads as well, though in a broken way, this now fixes behaviour in both variants. --- src/octoprint/server/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index 6a92032bb..961b5600c 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -760,8 +760,10 @@ class Server(object): } timelapses_path_validator = { "path_validation": util.tornado.path_validation_factory( - lambda path: not octoprint.util.is_hidden_path(path) - and octoprint.timelapse.valid_timelapse(path), + lambda path: valid_timelapse(path) + and os.path.realpath(os.path.abspath(path)).startswith( + settings().getBaseFolder("timelapse") + ), status_code=400, ) } @@ -777,7 +779,10 @@ class Server(object): } logs_path_validator = { "path_validation": util.tornado.path_validation_factory( - valid_log, + lambda path: valid_log(path) + and os.path.realpath(os.path.abspath(path)).startswith( + settings().getBaseFolder("logs") + ), status_code=400, ) } From b9374a2d7f5cfaa13a153796a669c62d850ffcd9 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Thu, 11 Mar 2021 06:09:03 +0000 Subject: [PATCH 11/11] Import ABC from collections.abc for Python 3.10 compatibility. --- AUTHORS.md | 1 + src/octoprint/util/__init__.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index fae1ed362..db978f380 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -139,6 +139,7 @@ date of first contribution): * [Miroslav Šedivý](https://github.com/eumiro) * [Costas Basdekis](https://github.com/costas-basdekis) * [Joe Martella](https://github.com/martellaj) + * [Karthikeyan Singaravelan](https://github.com/tirkarthi) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index b8de4d210..33dc92862 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -26,6 +26,13 @@ import warnings from functools import wraps from typing import Union +try: + # Python 3.4+ + from collections.abc import Iterable, MutableMapping, Set +except ImportError: + # Python 2.7 + from collections import Iterable, MutableMapping, Set + import frozendict import past.builtins @@ -978,7 +985,7 @@ def dict_flatten(dictionary, prefix="", separator="."): result = {} for k, v in dictionary.items(): key = prefix + separator + k if prefix else k - if isinstance(v, collections.MutableMapping): + if isinstance(v, MutableMapping): result.update(dict_flatten(v, prefix=key, separator=separator)) else: result[key] = v @@ -1722,11 +1729,6 @@ class CountedEvent(object): class InvariantContainer(object): def __init__(self, initial_data=None, guarantee_invariant=None): - try: - from collections.abc import Iterable - except ImportError: - # Python < 3.8 - from collections import Iterable from threading import RLock if guarantee_invariant is None: @@ -1847,7 +1849,7 @@ class TypeAlreadyInQueue(Exception): self.type = t -class CaseInsensitiveSet(collections.Set): +class CaseInsensitiveSet(Set): """ Basic case insensitive set