Merge branch 'maintenance' into devel
This commit is contained in:
commit
b2e37cd73e
8 files changed
+178
-41
No files matched your search
@@ -8,7 +8,7 @@ import pprint
|
||||
|
||||
import click
|
||||
|
||||
from octoprint import FatalStartupError, init_settings
|
||||
from octoprint import FatalStartupError, init_pluginsystem, init_settings
|
||||
from octoprint.cli import get_ctx_obj_option, standard_options
|
||||
from octoprint.util import yaml
|
||||
|
||||
@@ -41,6 +41,17 @@ def _set_helper(settings, path, value, data_type=None):
|
||||
settings.save()
|
||||
|
||||
|
||||
def _init_pluginsettings(ctx):
|
||||
try:
|
||||
ctx.obj.plugin_manager = init_pluginsystem(
|
||||
ctx.obj.settings, safe_mode=get_ctx_obj_option(ctx, "safe_mode", False)
|
||||
)
|
||||
except FatalStartupError as e:
|
||||
click.echo(str(e), err=True)
|
||||
click.echo("There was a fatal error initializing the plugin manager.", err=True)
|
||||
ctx.exit(-1)
|
||||
|
||||
|
||||
# ~~ "octoprint config" commands
|
||||
|
||||
|
||||
@@ -112,6 +123,8 @@ def remove_command(ctx, path):
|
||||
def append_value_command(ctx, path, value, as_json=False):
|
||||
"""Appends value to list behind config path."""
|
||||
path = _to_settings_path(path)
|
||||
if len(path) == 0 or path[0] == "plugins":
|
||||
_init_pluginsettings(ctx)
|
||||
|
||||
if as_json:
|
||||
try:
|
||||
@@ -141,6 +154,8 @@ def append_value_command(ctx, path, value, as_json=False):
|
||||
def insert_value_command(ctx, path, index, value, as_json=False):
|
||||
"""Inserts value at index of list behind config key."""
|
||||
path = _to_settings_path(path)
|
||||
if len(path) == 0 or path[0] == "plugins":
|
||||
_init_pluginsettings(ctx)
|
||||
|
||||
if as_json:
|
||||
try:
|
||||
@@ -169,6 +184,8 @@ def insert_value_command(ctx, path, index, value, as_json=False):
|
||||
def remove_value_command(ctx, path, value, as_json=False):
|
||||
"""Removes value from list at config path."""
|
||||
path = _to_settings_path(path)
|
||||
if len(path) == 0 or path[0] == "plugins":
|
||||
_init_pluginsettings(ctx)
|
||||
|
||||
if as_json:
|
||||
try:
|
||||
@@ -204,6 +221,8 @@ def remove_value_command(ctx, path, value, as_json=False):
|
||||
def get_command(ctx, path, as_json=False, as_yaml=False, as_raw=False):
|
||||
"""Retrieves value from config path."""
|
||||
path = _to_settings_path(path)
|
||||
if len(path) == 0 or path[0] == "plugins":
|
||||
_init_pluginsettings(ctx)
|
||||
value = ctx.obj.settings.get(path, merged=True)
|
||||
|
||||
if as_json:
|
||||
@@ -228,6 +247,7 @@ def get_command(ctx, path, as_json=False, as_yaml=False, as_raw=False):
|
||||
@click.pass_context
|
||||
def effective_command(ctx, as_json=False, as_yaml=False, as_raw=False):
|
||||
"""Retrieves the full effective config."""
|
||||
_init_pluginsettings(ctx)
|
||||
value = ctx.obj.settings.effective
|
||||
|
||||
if as_json:
|
||||
|
||||
@@ -1 +1 @@
|
||||
#webcam_video_container{width:100%;position:relative;outline:0}#webcam_video_container .video-controls{position:absolute;bottom:0;right:8px;z-index:10;opacity:.4}#webcam_video_container:hover .video-controls{opacity:1}#webcam_video_container #webcam_hls,#webcam_video_container #webcam_rtsp{width:100%;height:100%}#webcam_video_container .webcam_rotated{position:relative;width:100%;padding-bottom:56.25%;display:flex;justify-content:center;align-items:center;margin:auto}#webcam_video_container .webcam_rotated .rotation_target{position:absolute;transform:rotate(-90deg);width:100%}#webcam_img_container,#webcam_video_container .webcam_unrotated{width:100%;position:relative}#webcam_video_container .webcam_rotated .rotation_target div{width:100%;height:100%}#webcam_img_container{outline:0;background-color:#000}#webcam_img_container .keycontrol_overlay{position:absolute;left:10px;right:10px;bottom:10px;background:rgba(0,0,0,.5);font-size:85%;color:#fff;padding:0}#webcam_img_container .keycontrol_overlay kbd{border:1px solid #eee;border-radius:3px;margin-left:2px;margin-right:2px;font-size:90%;padding:2px;min-width:1em}#webcam_img_container .keycontrol_overlay .keycontrol_overlay_heading{position:relative;padding:10px;font-weight:700}#webcam_img_container .keycontrol_overlay .keycontrol_overlay_column{position:relative;width:45%;padding:10px;float:left}#webcam_img_container .nowebcam{position:absolute;top:0;left:0;right:0;bottom:0}#webcam_img_container .nowebcam .text{color:#fff;text-align:center;position:relative;margin:auto;width:80%;top:50%;transform:translateY(-50%);display:block}#webcam_img_container .nowebcam .text.webcam_loading{animation:pulsate 3s ease-out;animation-iteration-count:infinite}#webcam_img_container .webcam_rotated{position:relative;width:100%;padding-bottom:100%;pointer-events:none}#webcam_img_container .webcam_rotated .webcam_fixed_ratio{position:absolute;transform:rotate(-90deg);top:0;bottom:0;pointer-events:none}#webcam_img_container .webcam_rotated .webcam_fixed_ratio .webcam_fixed_ratio_inner{width:100%;height:100%;pointer-events:none}#webcam_img_container .webcam_unrotated .webcam_fixed_ratio{width:100%;pointer-events:none;padding-bottom:100%;position:relative}#webcam_img_container .webcam_unrotated .webcam_fixed_ratio.ratio43{padding-bottom:75%}#webcam_img_container .webcam_unrotated .webcam_fixed_ratio.ratio169{padding-bottom:56.25%}#webcam_img_container .webcam_unrotated .webcam_fixed_ratio.ratio1610{padding-bottom:62.5%}#webcam_img_container .webcam_unrotated .webcam_fixed_ratio .webcam_fixed_ratio_inner{position:absolute;top:0;bottom:0;left:0;right:0;pointer-events:none}#webcam_img_container img{width:100%;height:100%;object-fit:contain}#webcamTestContainer{min-height:384px}
|
||||
.classicwebcam_aspect_ratio_mixin{aspect-ratio:1}.classicwebcam_aspect_ratio_mixin.ratio43{aspect-ratio:4/3}.classicwebcam_aspect_ratio_mixin.ratio169{aspect-ratio:16/9}.classicwebcam_aspect_ratio_mixin.ratio1610{aspect-ratio:16/10}.classicwebcam_flexbox_mixin{width:100%;display:flex;justify-content:center;align-items:center}#webcam_video_container{width:100%;position:relative;outline:0}#webcam_video_container .video-controls{position:absolute;bottom:0;right:8px;z-index:10;opacity:.4}#webcam_video_container:hover .video-controls{opacity:1}#webcam_video_container #webcam_hls,#webcam_video_container #webcam_rtsp{width:100%;height:100%}#webcam_video_container .webcam_rotated,#webcam_video_container .webcam_unrotated{position:relative;width:100%;display:flex;justify-content:center;align-items:center;aspect-ratio:1}#webcam_video_container .webcam_rotated.ratio43,#webcam_video_container .webcam_unrotated.ratio43{aspect-ratio:4/3}#webcam_video_container .webcam_rotated.ratio169,#webcam_video_container .webcam_unrotated.ratio169{aspect-ratio:16/9}#webcam_video_container .webcam_rotated.ratio1610,#webcam_video_container .webcam_unrotated.ratio1610{aspect-ratio:16/10}#webcam_video_container .webcam_rotated .rotation_target,#webcam_video_container .webcam_rotated .rotation_target div,#webcam_video_container .webcam_unrotated .rotation_target,#webcam_video_container .webcam_unrotated .rotation_target div{width:100%;display:flex;justify-content:center;align-items:center}#webcam_video_container .webcam_rotated{aspect-ratio:1}#webcam_video_container .webcam_rotated .rotation_target{position:absolute;transform:rotate(-90deg)}#webcam_video_container .webcam_rotated .rotation_target div{height:100%}#webcam_img_container{width:100%;position:relative;outline:0;background-color:#000}#webcam_img_container .keycontrol_overlay{position:absolute;left:10px;right:10px;bottom:10px;background:rgba(0,0,0,.5);font-size:85%;color:#fff;padding:0}#webcam_img_container .keycontrol_overlay kbd{border:1px solid #eee;border-radius:3px;margin-left:2px;margin-right:2px;font-size:90%;padding:2px;min-width:1em}#webcam_img_container .keycontrol_overlay .keycontrol_overlay_heading{position:relative;padding:10px;font-weight:700}#webcam_img_container .keycontrol_overlay .keycontrol_overlay_column{position:relative;width:45%;padding:10px;float:left}#webcam_img_container .nowebcam{position:absolute;top:0;left:0;right:0;bottom:0}#webcam_img_container .nowebcam .text{color:#fff;text-align:center;position:relative;margin:auto;width:80%;top:50%;transform:translateY(-50%);display:block}#webcam_img_container .nowebcam .text.webcam_loading{animation:pulsate 3s ease-out;animation-iteration-count:infinite}#webcam_img_container .webcam_rotated{position:relative;width:100%;padding-bottom:100%;pointer-events:none}#webcam_img_container .webcam_rotated .webcam_fixed_ratio{position:absolute;transform:rotate(-90deg);top:0;bottom:0;pointer-events:none}#webcam_img_container .webcam_rotated .webcam_fixed_ratio .webcam_fixed_ratio_inner{width:100%;height:100%;pointer-events:none}#webcam_img_container .webcam_unrotated .webcam_fixed_ratio{width:100%;pointer-events:none;aspect-ratio:1;position:relative}#webcam_img_container .webcam_unrotated .webcam_fixed_ratio.ratio43{aspect-ratio:4/3}#webcam_img_container .webcam_unrotated .webcam_fixed_ratio.ratio169{aspect-ratio:16/9}#webcam_img_container .webcam_unrotated .webcam_fixed_ratio.ratio1610{aspect-ratio:16/10}#webcam_img_container .webcam_unrotated .webcam_fixed_ratio .webcam_fixed_ratio_inner{position:absolute;top:0;bottom:0;left:0;right:0;pointer-events:none}#webcam_img_container img{width:100%;height:100%;object-fit:contain}#webcamTestContainer{min-height:384px}
|
||||
@@ -25,6 +25,14 @@ $(function () {
|
||||
}
|
||||
});
|
||||
|
||||
self.webcamClass = ko.pureComputed(function () {
|
||||
if (self.settings.rotate90()) {
|
||||
return "webcam_rotated " + self.webcamRatioClass();
|
||||
} else {
|
||||
return "webcam_unrotated " + self.webcamRatioClass();
|
||||
}
|
||||
});
|
||||
|
||||
self.onBeforeBinding = function () {
|
||||
// Subscribe to rotation event to ensure we update calculations.
|
||||
// We need to wait for the CSS to be updated by KO, thus we use a timeout to
|
||||
@@ -289,11 +297,10 @@ $(function () {
|
||||
// accommodate the rotation). The target is centered in the container and
|
||||
// rotated around its center, so after we manually resized the container
|
||||
// everything will layout nicely.
|
||||
if (rotationContainer && player.videoWidth && player.videoHeight) {
|
||||
// Calculate the height the video will have in the UI, based on the
|
||||
// video width and the aspect ratio.
|
||||
var aspectRatio = player.videoWidth / player.videoHeight;
|
||||
var height = aspectRatio * rotationContainer.offsetWidth;
|
||||
if (rotationContainer) {
|
||||
// we'll go with an aspect ration of 1:1 for rotated videos, same as
|
||||
// for mjpg streams
|
||||
var height = rotationContainer.offsetWidth;
|
||||
|
||||
// Enforce the height on the rotation container and the rotation target.
|
||||
// Width of the container will be 100%, height will be calculated
|
||||
|
||||
@@ -1,3 +1,26 @@
|
||||
.classicwebcam_aspect_ratio_mixin {
|
||||
aspect-ratio: 1;
|
||||
|
||||
&.ratio43 {
|
||||
aspect-ratio: 4 / 3;
|
||||
}
|
||||
|
||||
&.ratio169 {
|
||||
aspect-ratio: 16 / 9;
|
||||
}
|
||||
|
||||
&.ratio1610 {
|
||||
aspect-ratio: 16 / 10;
|
||||
}
|
||||
}
|
||||
|
||||
.classicwebcam_flexbox_mixin {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#webcam_video_container {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
@@ -23,30 +46,29 @@
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.webcam_rotated {
|
||||
.webcam_rotated,
|
||||
.webcam_unrotated {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
padding-bottom: 56.25%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin: auto;
|
||||
.classicwebcam_flexbox_mixin();
|
||||
.classicwebcam_aspect_ratio_mixin();
|
||||
|
||||
.rotation_target {
|
||||
position: absolute;
|
||||
transform: rotate(-90deg);
|
||||
width: 100%;
|
||||
|
||||
.classicwebcam_flexbox_mixin();
|
||||
div {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
.classicwebcam_flexbox_mixin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.webcam_unrotated {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
.webcam_rotated {
|
||||
aspect-ratio: 1;
|
||||
.rotation_target {
|
||||
position: absolute;
|
||||
transform: rotate(-90deg);
|
||||
div {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,19 +163,7 @@
|
||||
width: 100%;
|
||||
pointer-events: none;
|
||||
|
||||
padding-bottom: 100%;
|
||||
|
||||
&.ratio43 {
|
||||
padding-bottom: 75%;
|
||||
}
|
||||
|
||||
&.ratio169 {
|
||||
padding-bottom: 56.25%;
|
||||
}
|
||||
|
||||
&.ratio1610 {
|
||||
padding-bottom: 62.5%;
|
||||
}
|
||||
.classicwebcam_aspect_ratio_mixin();
|
||||
|
||||
position: relative;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<!-- /ko -->
|
||||
</div>
|
||||
</div>
|
||||
<div data-bind="css: { webcam_rotated: settings.rotate90(), webcam_unrotated: !settings.rotate90() }">
|
||||
<div data-bind="css: webcamClass">
|
||||
<div class="rotation_target">
|
||||
<div data-bind="css: { flipH: settings.flipH(), flipV: settings.flipV() }">
|
||||
<video id="webcam_webrtc" muted autoplay playsinline style="width: 100%" data-bind="visible: webcamWebRTCEnabled()"></video>
|
||||
|
||||
@@ -938,11 +938,10 @@ class Server:
|
||||
# camera snapshot
|
||||
(
|
||||
r"/downloads/camera/current",
|
||||
util.tornado.UrlProxyHandler,
|
||||
util.tornado.WebcamSnapshotHandler,
|
||||
joined_dict(
|
||||
{
|
||||
"url": self._settings.get(["webcam", "snapshot"]),
|
||||
"as_attachment": True,
|
||||
"as_attachment": "snapshot",
|
||||
},
|
||||
camera_permission_validator,
|
||||
),
|
||||
|
||||
@@ -1379,6 +1379,106 @@ class StaticDataHandler(
|
||||
self.finish()
|
||||
|
||||
|
||||
class GeneratingDataHandler(
|
||||
RequestlessExceptionLoggingMixin, CorsSupportMixin, tornado.web.RequestHandler
|
||||
):
|
||||
"""
|
||||
A `RequestHandler` that generates data from a generator function and returns it to the client.
|
||||
|
||||
Arguments:
|
||||
generator (function): A generator function that returns the data to be written to the client. The function
|
||||
will be called without any parameters.
|
||||
content_type (str): The content type with which to respond. Defaults to `text/plain`
|
||||
as_attachment (bool | str): Whether to serve files with `Content-Disposition: attachment` header (`True`)
|
||||
or not. Defaults to `False`. If a string is given it will be used as the filename of the attachment.
|
||||
access_validation (function): Callback to call in the `get` method to validate access to the resource. Will
|
||||
be called with `self.request` as parameter which contains the full tornado request object. Should raise
|
||||
a `tornado.web.HTTPError` if access is not allowed in which case the request will not be further processed.
|
||||
Defaults to `None` and hence no access validation being performed.
|
||||
"""
|
||||
|
||||
def initialize(
|
||||
self,
|
||||
generator=None,
|
||||
content_type="text/plain",
|
||||
as_attachment=False,
|
||||
access_validation=None,
|
||||
):
|
||||
super().initialize()
|
||||
self._generator = generator
|
||||
self._content_type = content_type
|
||||
self._as_attachment = as_attachment
|
||||
self._access_validation = access_validation
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def get(self, *args, **kwargs):
|
||||
if self._access_validation is not None:
|
||||
self._access_validation(self.request)
|
||||
|
||||
self.set_status(200)
|
||||
self.set_header("Content-Type", self._content_type)
|
||||
self.set_content_disposition()
|
||||
for data in self._generator():
|
||||
self.write(data)
|
||||
yield self.flush()
|
||||
self.finish()
|
||||
|
||||
def set_content_disposition(self):
|
||||
if self._as_attachment:
|
||||
if isinstance(self._as_attachment, str):
|
||||
self.set_header(
|
||||
"Content-Disposition", f"attachment; filename={self._as_attachment}"
|
||||
)
|
||||
else:
|
||||
self.set_header("Content-Disposition", "attachment")
|
||||
|
||||
|
||||
class WebcamSnapshotHandler(GeneratingDataHandler):
|
||||
"""
|
||||
`GeneratingDataHandler` that returns a snapshot from the configured webcam.
|
||||
|
||||
Arguments:
|
||||
as_attachment (bool | str): Whether to serve files with `Content-Disposition: attachment` header (`True`)
|
||||
or not. Defaults to `False`. If a string is given it will be used as the filename of the attachment.
|
||||
access_validation (function): Callback to call in the `get` method to validate access to the resource. Will
|
||||
be called with `self.request` as parameter which contains the full tornado request object. Should raise
|
||||
a `tornado.web.HTTPError` if access is not allowed in which case the request will not be further processed.
|
||||
Defaults to `None` and hence no access validation being performed.
|
||||
"""
|
||||
|
||||
def initialize(self, as_attachment=False, access_validation=None):
|
||||
super().initialize(
|
||||
content_type="image/jpeg",
|
||||
as_attachment=as_attachment,
|
||||
access_validation=access_validation,
|
||||
)
|
||||
|
||||
@tornado.gen.coroutine
|
||||
def get(self, *args, **kwargs):
|
||||
if self._access_validation is not None:
|
||||
self._access_validation(self.request)
|
||||
|
||||
import functools
|
||||
|
||||
from octoprint.webcams import get_snapshot_webcam
|
||||
|
||||
webcam = get_snapshot_webcam()
|
||||
if not webcam:
|
||||
raise tornado.web.HTTPError(404)
|
||||
|
||||
generator = functools.partial(
|
||||
webcam.providerPlugin.take_webcam_snapshot, webcam.config.name
|
||||
)
|
||||
|
||||
self.set_status(200)
|
||||
self.set_header("Content-Type", self._content_type)
|
||||
self.set_content_disposition()
|
||||
for data in generator():
|
||||
self.write(data)
|
||||
yield self.flush()
|
||||
self.finish()
|
||||
|
||||
|
||||
class DeprecatedEndpointHandler(CorsSupportMixin, tornado.web.RequestHandler):
|
||||
"""
|
||||
`tornado.web.RequestHandler <http://tornado.readthedocs.org/en/branch4.0/web.html#request-handlers>`_ that redirects
|
||||
|
||||
@@ -1647,7 +1647,8 @@ class Settings:
|
||||
if default_value is not None:
|
||||
value = dict_merge(default_value, value)
|
||||
except KeyError:
|
||||
raise NoSuchSettingsPath()
|
||||
# no default value, so nothing to merge
|
||||
pass
|
||||
|
||||
if callable(preprocessor):
|
||||
value = preprocessor(value)
|
||||
|
||||
Reference in new issue
Block a user