Merge branch 'maintenance' into devel

This commit is contained in:
Gina Häußge committed 2022-08-02 15:43:35 +02:00
commit e524da88d6
15 files changed
+93 -99

No files matched your search

+39 -64
View File
@@ -262,55 +262,38 @@ class OctoPrintDevelCommands(click.MultiCommand):
"--list", "list_files", is_flag=True, help="List all available files and exit"
)
def command(files, all_files, list_files):
import os.path
import shutil
from pathlib import Path
available_files = {
"core": {
"source": "static/less/octoprint.less",
"output": "static/css/octoprint.css",
},
"login": {
"source": "static/less/login.less",
"output": "static/css/login.css",
},
"recovery": {
"source": "static/less/recovery.less",
"output": "static/css/recovery.css",
},
"plugin_announcements": {
"source": "plugins/announcements/static/less/announcements.less",
"output": "plugins/announcements/static/css/announcements.css",
},
"plugin_appkeys_core": {
"source": "plugins/appkeys/static/less/appkeys.less",
"output": "plugins/appkeys/static/css/appkeys.css",
},
"plugin_appkeys_authdialog": {
"source": "plugins/appkeys/static/less/authdialog.less",
"output": "plugins/appkeys/static/css/authdialog.css",
},
"plugin_backup": {
"source": "plugins/backup/static/less/backup.less",
"output": "plugins/backup/static/css/backup.css",
},
"plugin_gcodeviewer": {
"source": "plugins/gcodeviewer/static/less/gcodeviewer.less",
"output": "plugins/gcodeviewer/static/css/gcodeviewer.css",
},
"plugin_logging": {
"source": "plugins/logging/static/less/logging.less",
"output": "plugins/logging/static/css/logging.css",
},
"plugin_pluginmanager": {
"source": "plugins/pluginmanager/static/less/pluginmanager.less",
"output": "plugins/pluginmanager/static/css/pluginmanager.css",
},
"plugin_softwareupdate": {
"source": "plugins/softwareupdate/static/less/softwareupdate.less",
"output": "plugins/softwareupdate/static/css/softwareupdate.css",
},
}
# src/octoprint
octoprint_base = Path(__file__).parent.parent
available_files = {}
for less_file in Path(octoprint_base, "static", "less").glob("*.less"):
# Check corresponding css file exists
# Less files can be imported, not all need building
css_file = Path(less_file.parent.parent, "css", f"{less_file.stem}.css")
if css_file.exists():
available_files[less_file.stem] = {
"source": str(less_file),
"output": str(css_file),
}
path_to_plugins = Path(octoprint_base, "plugins")
for plugin in Path(path_to_plugins).iterdir():
for less_file in Path(plugin, "static", "less").glob("*.less"):
name = f"plugin_{plugin.name}"
if less_file.stem != plugin.name:
name += f"_{less_file.stem}"
# Check there is a corresponding CSS file first
css_file = Path(
less_file.parent.parent, "css", f"{less_file.stem}.css"
)
if css_file.exists():
available_files[name] = {
"source": str(less_file),
"output": str(css_file),
}
if list_files:
click.echo("Available files to build:")
@@ -329,7 +312,6 @@ class OctoPrintDevelCommands(click.MultiCommand):
# Check that lessc is installed
less = shutil.which("lessc")
if not less:
click.echo(
"lessc is not installed/not available, please install it first"
@@ -339,26 +321,19 @@ class OctoPrintDevelCommands(click.MultiCommand):
)
sys.exit(1)
# Find the folder of the `octoprint` package
# Two folders up from this file
octoprint = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
for file in files:
if file not in available_files.keys():
click.echo(f"Unknown file {file}")
for less_file in files:
if less_file not in available_files.keys():
click.echo(f"Unknown file {less_file}")
sys.exit(1)
source_path = os.path.join(octoprint, available_files[file]["source"])
output_path = os.path.join(octoprint, available_files[file]["output"])
# Check the target file exists
if not os.path.exists(source_path):
click.echo(f"Target file {source_path} does not exist")
continue
# Build command line, with necessary options
# TODO -x is deprecated, find replacement?
less_command = [less, "-x", source_path, output_path]
less_command = [
less,
"-x",
available_files[less_file]["source"],
available_files[less_file]["output"],
]
self.command_caller.call(less_command)
+2 -2
View File
@@ -164,7 +164,7 @@ class StorageInterface:
:param string path: the path of the new folder
:param bool ignore_existing: if set to True, no error will be raised if the folder to be added already exists
:param unicode display: display name of the folder
:param str display: display name of the folder
:return: the sanitized name of the new folder to be used for future references to the folder
"""
raise NotImplementedError()
@@ -220,7 +220,7 @@ class StorageInterface:
:param list links: any links to add with the file
:param bool allow_overwrite: if set to True no error will be raised if the file already exists and the existing file
and its metadata will just be silently overwritten
:param unicode display: display name of the file
:param str display: display name of the file
:return: the sanitized name of the file to be used for future references to it
"""
raise NotImplementedError()
@@ -480,8 +480,10 @@ var doParse = function () {
center_j = Number(args[j].slice(1));
break;
case "g":
if (args[j].charAt(1).toLowerCase() === "2") direction = -1;
if (args[j].charAt(1).toLowerCase() === "3") direction = 1;
if (args[j].charAt(1) === "2" || args[j].charAt(2) === "2")
direction = -1;
else if (args[j].charAt(1) === "3" || args[j].charAt(2) === "3")
direction = 1;
break;
}
}
@@ -711,6 +711,13 @@ class SoftwareUpdatePlugin(
def on_settings_load(self):
# ensure we don't persist check configs we receive on the API
data = dict(octoprint.plugin.SettingsPlugin.on_settings_load(self))
# set credentials flag
credentials = self._settings.get(["credentials"])
data["credentials"] = {}
for key, value in credentials.items():
data["credentials"][f"{key}_set"] = bool(value)
if "checks" in data:
del data["checks"]
@@ -65,6 +65,7 @@ $(function () {
self.config_pipEnableCheck = ko.observable();
self.config_minimumFreeStorage = ko.observable();
self.config_githubToken = ko.observable();
self.config_githubTokenSet = ko.observable(false);
self.error_checkoutFolder = ko.pureComputed(function () {
return (
@@ -334,6 +335,10 @@ $(function () {
self.config_minimumFreeStorage(
self.settings.settings.plugins.softwareupdate.minimum_free_storage()
);
self.config_githubTokenSet(
self.settings.settings.plugins.softwareupdate.credentials.github_set()
);
};
self._copyConfigBack = function () {
@@ -1,7 +1,12 @@
<div class="control-group">
<label class="control-label">{{ _('GitHub Access Token') }}</label>
<div class="controls">
<!-- ko if : config_githubTokenSet -->
<input type="text" class="input-block-level" data-bind="value: config_githubToken" placeholder="{{ _('Token entered but hidden for privacy reasons')|edq }}">
<!-- /ko -->
<!-- ko ifnot : config_githubTokenSet -->
<input type="text" class="input-block-level" data-bind="value: config_githubToken" placeholder="{{ _('Enter a new token...')|edq }}">
<!-- /ko -->
<span class="help-block">{{ _('Set this if you keep running into rate limiting issues. <a href="%(url)s" target="_blank" rel="noopener noreferer">See here for how to obtain a token</a>.', url="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token") }}</span>
</div>
</div>
@@ -38,9 +38,7 @@ def _git(args, cwd, hide_stderr=False):
else:
return None, None
stdout = p.communicate()[0].strip()
if sys.version >= "3":
stdout = stdout.decode()
stdout = p.communicate()[0].strip().decode()
if p.returncode != 0:
return p.returncode, None
+1 -1
View File
@@ -6,7 +6,7 @@ import base64
import logging
import sys
PY3 = sys.version_info[0] == 3 # should now always be true, kept for plugins
PY3 = sys.version_info >= (3, 0) # should now always be True, kept for plugins
import flask as _flask
import flask_login
+1 -1
View File
@@ -265,7 +265,7 @@ class ReverseProxiedEnvironment:
# sensible defaults
if header_prefix is None:
header_prefix = ["x-script-name"]
header_prefix = ["x-script-name", "x-forwarded-prefix"]
if header_scheme is None:
header_scheme = ["x-forwarded-proto", "x-scheme"]
if header_host is None:
+2 -3
View File
@@ -77,7 +77,7 @@ def to_unicode(
s_or_u: Union[str, bytes], encoding: str = "utf-8", errors: str = "strict"
) -> str:
"""
Make sure ``s_or_u`` is a unicode string (str).
Make sure ``s_or_u`` is a string (str).
Arguments:
s_or_u (str or bytes): The value to convert
@@ -202,7 +202,6 @@ def warning_factory(warning_type):
"__dict__",
"__doc__",
"__str__",
"__unicode__",
"__repr__",
"__getattribute__",
"__setattr__",
@@ -1618,7 +1617,7 @@ class CaseInsensitiveSet(Set):
"""
Basic case insensitive set
Any str or unicode values will be stored and compared in lower case. Other value types are left as-is.
Any str values will be stored and compared in lower case. Other value types are left as-is.
"""
def __init__(self, *args):
+6 -1
View File
@@ -587,8 +587,13 @@ class gcode:
else:
e = 0
# calculate 3d arc length
arcLengthXYZ = math.sqrt(
(oldPos.z - pos.z) ** 2 + ((endAngle - startAngle) * r) ** 2
)
# move time in x, y, z, will be 0 if no movement happened
moveTimeXYZ = abs((oldPos - pos).length / feedrate)
moveTimeXYZ = abs(arcLengthXYZ / feedrate)
# time needed for extruding, will be 0 if no extrusion happened
extrudeTime = abs(e / feedrate)