Merge branch 'maintenance' into devel

This commit is contained in:
Gina Häußge committed 2021-11-01 16:34:21 +01:00
commit bcea4839f6
37 files changed
+298 -70

No files matched your search

+4
View File
@@ -398,6 +398,10 @@ class TemplatePlugin(OctoPrintPlugin, ReloadNeedingPlugin):
``TemplatePlugin`` is a :class:`~octoprint.plugin.core.ReloadNeedingPlugin`.
"""
@property
def template_folder_key(self):
return f"plugin_{self._identifier}"
def get_template_configs(self):
"""
Allows configuration of injected navbar, sidebar, tab and settings templates (and also additional templates of
@@ -108,7 +108,7 @@
<p>{{ _('Restore settings & files from an uploaded backup archive.') }}</p>
{% set plugin_backup_upload_form_id='settings-backup-upload' %}
{% include "snippets/plugin/backup/backup_plugin_upload_form.jinja2" %}
{% include "snippets/backup_plugin_upload_form.jinja2" %}
</div>
<div data-bind="visible: !restoreSupported()">
@@ -5,4 +5,4 @@
</p>{% endtrans %}
{% set plugin_backup_upload_form_id='wizard-backup-upload' %}
{% include "snippets/plugin/backup/backup_plugin_upload_form.jinja2" %}
{% include "snippets/backup_plugin_upload_form.jinja2" %}
@@ -18,10 +18,10 @@ from octoprint.util.version import (
)
SENTRY_URL_SERVER = (
"https://3d510fcb31be49c8a811639b7ed18377@o118517.ingest.sentry.io/1373987"
"https://6600411b6f6b4a959d53037e782a8f73@o118517.ingest.sentry.io/1373987"
)
SENTRY_URL_COREUI = (
"https://c6ab43a97f224198ae62a6e11e253cf0@o118517.ingest.sentry.io/1374096"
"https://72b9fc82150d47bead5c940ccbd05995@o118517.ingest.sentry.io/1374096"
)
SETTINGS_DEFAULTS = {
@@ -371,6 +371,7 @@ $(function () {
self._configureLayerSlider(layerSliderElement);
self._configureLayerCommandSlider(commandSliderElement);
self._configureContainerElement(containerElement);
self.settings.firstRequest.done(function () {
var initResult = GCODE.ui.init({
@@ -475,6 +476,18 @@ $(function () {
.on("slide", self.changeCommandRange);
};
self._configureContainerElement = function (containerElement) {
// Prevent the default browser action for the mouse wheel down event. The desired behavor is to have the
// gocde canvas pan on mouse down + drag, which happens. But if we don't prevent the default action, the browser
// will also scroll the entire page.
containerElement.mousedown(function (event) {
// Middle mouse button
if (event.which === 2) {
event.preventDefault();
}
});
};
self.loadFile = function (path, date) {
self.enableReload(false);
self.needsLoad = false;
@@ -50,7 +50,7 @@ $(function () {
return !item.enabled;
}
},
"popularity",
"name",
[],
[
["bundled", "3rdparty"],
@@ -138,7 +138,7 @@ $(function () {
return !plugin.abandoned;
}
},
"title",
"popularity",
["filter_installed", "filter_incompatible"],
[],
0
@@ -158,11 +158,11 @@
</div>
<div class="modal-body">
<form class="form-horizontal" onsubmit="return false;">
{% include "snippets/plugins/softwareupdate/versionTracking.jinja2" %}
{% include "snippets/plugins/softwareupdate/trackedBranch.jinja2" %}
{% include "snippets/plugins/softwareupdate/checkoutFolder.jinja2" %}
{% include "snippets/plugins/softwareupdate/pipTarget.jinja2" %}
{% include "snippets/plugins/softwareupdate/pipEnableCheck.jinja2" %}
{% include "snippets/versionTracking.jinja2" %}
{% include "snippets/trackedBranch.jinja2" %}
{% include "snippets/checkoutFolder.jinja2" %}
{% include "snippets/pipTarget.jinja2" %}
{% include "snippets/pipEnableCheck.jinja2" %}
<div class="control-group">
<label class="control-label">{{ _('Version cache TTL') }}</label>
<div class="controls">
@@ -7,9 +7,9 @@
</p>{% endtrans %}
<form class="form-horizontal" onsubmit="return false;">
{% include "snippets/plugins/softwareupdate/versionTracking.jinja2" %}
{% include "snippets/plugins/softwareupdate/checkoutFolder.jinja2" %}
{% include "snippets/plugins/softwareupdate/trackedBranch.jinja2" %}
{% include "snippets/versionTracking.jinja2" %}
{% include "snippets/checkoutFolder.jinja2" %}
{% include "snippets/trackedBranch.jinja2" %}
</form>
{% trans %}<p>
@@ -1,6 +1,6 @@
<h3>{{ _('Anonymous Usage Tracking') }}</h3>
{% include "snippets/plugins/tracking/trackingDescription.jinja2" %}
{% include "snippets/trackingDescription.jinja2" %}
<form class="form-horizontal" onsubmit="return false;">
<div class="control-group">
@@ -59,4 +59,4 @@
</div>
</form>
{% include "snippets/plugins/tracking/trackingDetails.jinja2" %}
{% include "snippets/trackingDetails.jinja2" %}
@@ -1,8 +1,8 @@
<h3>{{ _('Configure Anonymous Usage Tracking') }}</h3>
{% include "snippets/plugins/tracking/trackingDescription.jinja2" %}
{% include "snippets/trackingDescription.jinja2" %}
{% include "snippets/plugins/tracking/trackingDetails.jinja2" %}
{% include "snippets/trackingDetails.jinja2" %}
<p>
{{ _('<strong>Note:</strong> You can always change your decision and also access more granular controls via Settings > Anonymous Usage Tracking.') }}
+33 -13
View File
@@ -254,8 +254,6 @@ class Server:
self._lifecycle_callbacks = defaultdict(list)
self._template_searchpaths = []
self._intermediary_server = None
def run(self):
@@ -1338,9 +1336,13 @@ class Server:
OctoPrintFlaskResponse,
OctoPrintJsonEncoder,
OctoPrintSessionInterface,
PrefixAwareJinjaEnvironment,
ReverseProxiedEnvironment,
)
# we must set this here because setting app.debug will access app.jinja_env
app.jinja_environment = PrefixAwareJinjaEnvironment
app.config["TEMPLATES_AUTO_RELOAD"] = True
app.config["JSONIFY_PRETTYPRINT_REGULAR"] = False
@@ -1536,12 +1538,9 @@ class Server:
import octoprint.util.jinja
filesystem_loader = octoprint.util.jinja.FilteredFileSystemLoader(
[], path_filter=lambda x: not octoprint.util.is_hidden_path(x)
)
filesystem_loader.searchpath = self._template_searchpaths
app.jinja_env.prefix_loader = jinja2.PrefixLoader({})
loaders = [app.jinja_loader, filesystem_loader]
loaders = [app.jinja_loader, app.jinja_env.prefix_loader]
if octoprint.util.is_running_from_source():
from markdown import markdown
@@ -1556,8 +1555,16 @@ class Server:
)
)
jinja_loader = jinja2.ChoiceLoader(loaders)
app.jinja_loader = jinja_loader
# TODO: Remove this in 2.0.0
warning_message = "Loading plugin template '{template}' from '{filename}' without plugin prefix, this is deprecated and will soon no longer be supported."
loaders.append(
octoprint.util.jinja.WarningLoader(
octoprint.util.jinja.PrefixChoiceLoader(app.jinja_env.prefix_loader),
warning_message,
)
)
app.jinja_loader = jinja2.ChoiceLoader(loaders)
self._register_template_plugins()
@@ -1728,14 +1735,27 @@ class Server:
)
def _register_additional_template_plugin(self, plugin):
import octoprint.util.jinja
folder = plugin.get_template_folder()
if folder is not None and folder not in self._template_searchpaths:
self._template_searchpaths.append(folder)
if (
folder is not None
and plugin.template_folder_key not in app.jinja_env.prefix_loader.mapping
):
loader = octoprint.util.jinja.FilteredFileSystemLoader(
[plugin.get_template_folder()],
path_filter=lambda x: not octoprint.util.is_hidden_path(x),
)
app.jinja_env.prefix_loader.mapping[plugin.template_folder_key] = loader
def _unregister_additional_template_plugin(self, plugin):
folder = plugin.get_template_folder()
if folder is not None and folder in self._template_searchpaths:
self._template_searchpaths.remove(folder)
if (
folder is not None
and plugin.template_folder_key in app.jinja_env.prefix_loader.mapping
):
del app.jinja_env.prefix_loader.mapping[plugin.template_folder_key]
def _setup_blueprints(self):
# do not remove or the index view won't be found
+23 -12
View File
@@ -34,6 +34,11 @@ from octoprint.server.util.flask import (
from octoprint.settings import settings, valid_boolean_trues
from octoprint.util import sv, time_this
try:
from urllib.parse import quote as urlquote
except ImportError:
from urllib import quote as urlquote # noqa: F401
# ~~ GCODE file handling
_file_cache = {}
@@ -322,7 +327,7 @@ def _getFileList(
"resource": url_for(
".readGcodeFile",
target=FileDestinations.SDCARD,
filename=f["name"],
filename=urlquote(f["name"]),
_external=True,
)
},
@@ -384,7 +389,7 @@ def _getFileList(
"resource": url_for(
".readGcodeFile",
target=FileDestinations.LOCAL,
filename=path + file_or_folder["name"],
filename=urlquote(path + file_or_folder["name"]),
_external=True,
)
}
@@ -438,14 +443,14 @@ def _getFileList(
"resource": url_for(
".readGcodeFile",
target=FileDestinations.LOCAL,
filename=file_or_folder["path"],
filename=urlquote(file_or_folder["path"]),
_external=True,
),
"download": url_for("index", _external=True)
+ "downloads/files/"
+ FileDestinations.LOCAL
+ "/"
+ file_or_folder["path"],
+ urlquote(file_or_folder["path"]),
}
result.append(file_or_folder)
@@ -684,7 +689,7 @@ def uploadGcodeFile(target):
location = url_for(
".readGcodeFile",
target=FileDestinations.LOCAL,
filename=filename,
filename=urlquote(filename),
_external=True,
)
files.update(
@@ -699,7 +704,7 @@ def uploadGcodeFile(target):
+ "downloads/files/"
+ FileDestinations.LOCAL
+ "/"
+ filename,
+ urlquote(filename),
},
}
}
@@ -709,7 +714,7 @@ def uploadGcodeFile(target):
location = url_for(
".readGcodeFile",
target=FileDestinations.SDCARD,
filename=sdFilename,
filename=urlquote(sdFilename),
_external=True,
)
files.update(
@@ -761,7 +766,7 @@ def uploadGcodeFile(target):
location = url_for(
".readGcodeFile",
target=FileDestinations.LOCAL,
filename=added_folder,
filename=urlquote(added_folder),
_external=True,
)
folder = {
@@ -1031,7 +1036,10 @@ def gcodeFileCommand(filename, target):
abort(404, description="Unknown profile")
location = url_for(
".readGcodeFile", target=target, filename=full_path, _external=True
".readGcodeFile",
target=target,
filename=urlquote(full_path),
_external=True,
)
result = {
"name": destination,
@@ -1044,7 +1052,7 @@ def gcodeFileCommand(filename, target):
+ "downloads/files/"
+ target
+ "/"
+ full_path,
+ urlquote(full_path),
},
}
@@ -1149,7 +1157,10 @@ def gcodeFileCommand(filename, target):
fileManager.move_folder(target, filename, destination)
location = url_for(
".readGcodeFile", target=target, filename=destination, _external=True
".readGcodeFile",
target=target,
filename=urlquote(destination),
_external=True,
)
result = {
"name": name,
@@ -1163,7 +1174,7 @@ def gcodeFileCommand(filename, target):
+ "downloads/files/"
+ target
+ "/"
+ destination
+ urlquote(destination)
)
r = make_response(jsonify(result), 201)
+7 -2
View File
@@ -21,6 +21,11 @@ from octoprint.server.util.flask import (
)
from octoprint.settings import settings, valid_boolean_trues
try:
from urllib.parse import quote as urlquote
except ImportError:
from urllib import quote as urlquote # noqa: F401
_DATA_FORMAT_VERSION = "v2"
# ~~ timelapse handling
@@ -137,7 +142,7 @@ def getTimelapseData():
finished_list = []
for f in files:
output = dict(f)
output["url"] = url_for("index") + "downloads/timelapse/" + f["name"]
output["url"] = url_for("index") + "downloads/timelapse/" + urlquote(f["name"])
finished_list.append(output)
result = {
@@ -157,7 +162,7 @@ def getTimelapseData():
@Permissions.TIMELAPSE_DOWNLOAD.require(403)
def downloadTimelapse(filename):
return redirect_to_tornado(
request, url_for("index") + "downloads/timelapse/" + filename
request, url_for("index") + "downloads/timelapse/" + urlquote(filename)
)
+31
View File
@@ -14,6 +14,7 @@ from os import scandir
import flask
import flask.json
import flask.sessions
import flask.templating
import flask_assets
import flask_login
import netaddr
@@ -591,6 +592,36 @@ class OctoPrintSessionInterface(flask.sessions.SecureCookieSessionInterface):
return super().save_session(app, session, response)
# ~~ jinja environment
class PrefixAwareJinjaEnvironment(flask.templating.Environment):
def __init__(self, *args, **kwargs):
flask.templating.Environment.__init__(self, *args, **kwargs)
self.prefix_loader = None
self._cached_templates = {}
def join_path(self, template, parent):
if parent and "/" in parent:
prefix, _ = parent.split("/", 1)
if template in self._templates_for_prefix(prefix) and not template.startswith(
prefix + "/"
):
return prefix + "/" + template
return template
def _templates_for_prefix(self, prefix):
if prefix in self._cached_templates:
return self._cached_templates[prefix]
templates = []
if prefix in self.prefix_loader.mapping:
templates = self.prefix_loader.mapping[prefix].list_templates()
self._cached_templates[prefix] = templates
return templates
# ~~ passive login helper
_cached_local_networks = None
+6
View File
@@ -1484,6 +1484,12 @@ def _process_template_config(name, implementation, rule, config=None, counter=1)
if "template" not in data:
data["template"] = rule["template"](name)
data["template"] = implementation.template_folder_key + "/" + data["template"]
if "template_header" in data:
data["template_header"] = (
implementation.template_folder_key + "/" + data["template_header"]
)
if "name" not in data:
data["name"] = implementation._plugin_name
+1 -1
View File
@@ -90,7 +90,7 @@ default_settings = {
"port": None,
"baudrate": None,
"exclusive": True,
"lowLatency": True,
"lowLatency": False,
"autoconnect": False,
"log": False,
"timeout": {
@@ -426,5 +426,11 @@
});
};
OctoPrintClient.escapePath = function (path) {
return _.map(path.split("/"), function (p) {
return encodeURIComponent(p);
}).join("/");
};
return OctoPrintClient;
});
+4 -4
View File
@@ -14,19 +14,19 @@
};
var resourceForLocation = function (location) {
return url + "/" + location;
return url + "/" + OctoPrintClient.escapePath(location);
};
var downloadForLocation = function (location) {
return downloadUrl + "/" + location;
return downloadUrl + "/" + OctoPrintClient.escapePath(location);
};
var downloadForEntry = function (location, filename) {
return downloadForLocation(location) + "/" + filename;
return downloadForLocation(location) + "/" + OctoPrintClient.escapePath(filename);
};
var resourceForEntry = function (location, filename) {
return resourceForLocation(location) + "/" + filename;
return resourceForLocation(location) + "/" + OctoPrintClient.escapePath(filename);
};
var preProcessList = function (response) {
@@ -11,15 +11,15 @@
var bulkDownloadUrl = "downloads/timelapses";
var timelapseUrl = function (filename) {
return url + "/" + filename;
return url + "/" + OctoPrintClient.escapePath(filename);
};
var timelapseDownloadUrl = function (filename) {
return downloadUrl + "/" + filename;
return downloadUrl + "/" + OctoPrintClient.escapePath(filename);
};
var unrenderedTimelapseUrl = function (name) {
return url + "/unrendered/" + name;
return url + "/unrendered/" + OctoPrintClient.escapePath(name);
};
var OctoPrintTimelapseClient = function (base) {
+1
View File
@@ -39,6 +39,7 @@ $(function () {
.fail(function () {
usernameElement.val("");
passwordElement.val("");
usernameElement.focus();
overlayElement.removeClass("in");
errorElement.addClass("in");
+36
View File
@@ -110,6 +110,42 @@ class SelectedFilesWithConversionLoader(SelectedFilesLoader):
return contents
class PrefixChoiceLoader(BaseLoader):
def __init__(self, loader):
self.loader = loader
def get_source(self, environment, template):
for prefix in sorted(self.loader.mapping.keys()):
try:
return self.loader.mapping[prefix].get_source(environment, template)
except TemplateNotFound:
pass
raise TemplateNotFound(template)
class WarningLoader(BaseLoader):
"""
Logs a warning if the loader is used to successfully load a template.
"""
def __init__(self, loader, warning_message):
self.loader = loader
self.warning_message = warning_message
def get_source(self, environment, template):
import logging
try:
contents, filename, uptodate = self.loader.get_source(environment, template)
logging.getLogger(__name__).warning(
self.warning_message.format(template=template, filename=filename)
)
return contents, filename, uptodate
except TemplateNotFound:
raise
def get_all_template_paths(loader):
def walk_folder(folder):
files = []
+1 -4
View File
@@ -1,6 +1,3 @@
from octoprint.util import bom_aware_open
def load_from_file(file=None, path=None):
"""
Safely and performantly loads yaml data from the given source. Either a
@@ -12,7 +9,7 @@ def load_from_file(file=None, path=None):
"""
if path is not None:
assert file is None
with bom_aware_open(path, mode="rt", encoding="utf-8") as f:
with open(path, mode="rt", encoding="utf-8-sig") as f:
return load_from_file(file=f)
if file is not None: