Merge branch 'maintenance' into devel
This commit is contained in:
commit
d2452c007e
12 files changed
+95
-63
No files matched your search
@@ -1492,6 +1492,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):
|
||||
@@ -1519,11 +1520,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)
|
||||
@@ -1664,7 +1662,7 @@ class LocalFileStorage(StorageInterface):
|
||||
continue
|
||||
|
||||
self._filelist_cache[path] = (
|
||||
self.last_modified(path, recursive=True),
|
||||
lm,
|
||||
result,
|
||||
)
|
||||
return enrich_folders(result)
|
||||
|
||||
@@ -1076,10 +1076,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():
|
||||
|
||||
@@ -680,13 +680,20 @@ $(function () {
|
||||
gettext("Updating, please wait.")
|
||||
);
|
||||
})
|
||||
.fail(function () {
|
||||
.fail(function (response) {
|
||||
self.updateInProgress = false;
|
||||
var message =
|
||||
"<p>" +
|
||||
gettext(
|
||||
"The update could not be started. Is it already active? Please consult octoprint.log for details."
|
||||
) +
|
||||
"</p><pre>" +
|
||||
_.escape(response.responseJSON.error) +
|
||||
"</pre>";
|
||||
|
||||
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: {
|
||||
|
||||
@@ -755,19 +755,17 @@ class Server:
|
||||
}
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -776,7 +774,10 @@ class Server:
|
||||
}
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -215,7 +215,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
|
||||
@@ -244,6 +244,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
|
||||
@@ -730,7 +732,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
|
||||
@@ -1094,7 +1096,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(
|
||||
@@ -1159,6 +1161,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.
|
||||
|
||||
@@ -397,7 +397,7 @@ default_settings = {
|
||||
"terminalFilters": [
|
||||
{
|
||||
"name": "Suppress temperature messages",
|
||||
"regex": r"(Send: (N\d+\s+)?M105)|(Recv:\s+(ok\s+((P|B|N)\d+\s+)*)?(B|T\d*):\d+)",
|
||||
"regex": r"(Send: (N\d+\s+)?M105)|(Recv:\s+(ok\s+([PBN]\d+\s+)*)?([BCLPR]|T\d*):-?\d+)",
|
||||
},
|
||||
{
|
||||
"name": "Suppress SD status messages",
|
||||
|
||||
@@ -406,7 +406,8 @@ $(function () {
|
||||
self.addTerminalFilter = function () {
|
||||
self.terminalFilters.push({
|
||||
name: "New",
|
||||
regex: "(Send:\\s+(N\\d+\\s+)?M105)|(Recv:\\s+(ok\\s+)?.*(B|T\\d*):\\d+)"
|
||||
regex:
|
||||
"(Send:\\s+(N\\d+\\s+)?M105)|(Recv:\\s+(ok\\s+([PBN]\\d+\\s+)*)?.*([BCLPR]|T\\d*):-?\\d+)"
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,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
|
||||
|
||||
from octoprint import UMASK
|
||||
@@ -970,7 +977,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
|
||||
@@ -1677,7 +1684,6 @@ class CountedEvent:
|
||||
|
||||
class InvariantContainer:
|
||||
def __init__(self, initial_data=None, guarantee_invariant=None):
|
||||
from collections.abc import Iterable
|
||||
from threading import RLock
|
||||
|
||||
if guarantee_invariant is None:
|
||||
@@ -1798,7 +1804,7 @@ class TypeAlreadyInQueue(Exception):
|
||||
self.type = t
|
||||
|
||||
|
||||
class CaseInsensitiveSet(collections.Set):
|
||||
class CaseInsensitiveSet(Set):
|
||||
"""
|
||||
Basic case insensitive set
|
||||
|
||||
@@ -1849,33 +1855,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, "func_args": "?", "func_kwargs": "?"}
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user