Merge branch 'maintenance' into devel

This commit is contained in:
Gina Häußge committed 2021-07-13 15:50:19 +02:00
commit 7f5700e0f9
18 files changed
+501 -97

No files matched your search

+31
View File
@@ -1698,6 +1698,37 @@ octoprint.system.additional_commands
:return: a list of command specifications
:rtype: list
.. _sec-plugins-hook-systeminfo-additional_bundle_files:
octoprint.systeminfo.additional_bundle_files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. py:function:: additional_bundle_files_hook(*args, **kwargs)
.. versionadded:: 1.7.0
Allows bundled plugins to extend the list of files to include in the systeminfo bundle.
Note that this hook will ignore third party plugins. Handlers must return a dictionary
mapping file names in the bundle to either local log paths on disk or a ``callable``
that will be called to generate the file's content inside the bundle.
**Example**
Add a plugin's ``console`` log file to the systeminfo bundle:
.. code-block:: python
def get_additional_bundle_files(*args, **kwargs):
console_log = self._settings.get_plugin_logfile_path(postfix="console")
return {os.path.basename(console_log): console_log}
__plugin_hooks__ = {
"octoprint.systeminfo.additional_bundle_files": get_additional_bundle_files
}
:return: a dictionary mapping bundle file names to bundle file content
:rtype: dict
.. _sec-plugins-hook-timelapse-extensions:
octoprint.timelapse.extensions
+34 -4
View File
@@ -39,7 +39,7 @@ def get_systeminfo(environment_detector, connectivity_checker, additional_fields
return flattened
def get_systeminfo_bundle(systeminfo, logbase, printer=None):
def get_systeminfo_bundle(systeminfo, logbase, printer=None, plugin_manager=None):
from octoprint.util import to_bytes
systeminfotxt = []
@@ -80,13 +80,41 @@ def get_systeminfo_bundle(systeminfo, logbase, printer=None):
for log in (
"octoprint.log",
"serial.log",
"plugin_softwareupdate_console.log",
"plugin_pluginmanager_console.log",
):
logpath = os.path.join(logbase, log)
if os.path.exists(logpath):
z.write(logpath, arcname=log, compress_type=compress_type)
# add additional bundle contents from bundled plugins
if plugin_manager:
for name, hook in plugin_manager.get_hooks(
"octoprint.systeminfo.additional_bundle_files"
).items():
try:
plugin = plugin_manager.get_plugin_info(name)
if not plugin.bundled:
# we only support this for bundled plugins because we don't want
# third party logs to blow up the bundles
continue
logs = hook()
for log, content in logs.items():
if isinstance(content, str):
# log path
if os.path.exists(content) and os.access(content, os.R_OK):
z.write(content, arcname=log, compress_type=compress_type)
elif callable(content):
# content generating callable
z.writestr(log, to_bytes(content()), compress_type=compress_type)
except Exception:
logging.getLogger(__name__).exception(
"Error while retrieving additional bundle contents for plugin {}".format(
name
),
extra={"plugin": name},
)
return z
@@ -137,7 +165,9 @@ def systeminfo_command(ctx, path, **kwargs):
zipfilename = os.path.join(path, get_systeminfo_bundle_name())
click.echo(f"Writing systeminfo bundle to {zipfilename}...")
z = get_systeminfo_bundle(systeminfo, settings.getBaseFolder("logs"))
z = get_systeminfo_bundle(
systeminfo, settings.getBaseFolder("logs"), plugin_manager=plugin_manager
)
try:
with open(zipfilename, "wb") as f:
for data in z:
+2 -2
View File
@@ -1103,7 +1103,7 @@ class WizardPlugin(OctoPrintPlugin, ReloadNeedingPlugin):
* the current and seen versions are identical
* the current version is None and the seen version is not
* the current version is less or equal than the seen one
* the seen version is not None and the current version is less or equal than the seen one
.. code-block:: none
@@ -1155,7 +1155,7 @@ class WizardPlugin(OctoPrintPlugin, ReloadNeedingPlugin):
return (
(current == seen)
or (current is None and seen is not None)
or (current <= seen)
or (seen is not None and current <= seen)
)
@@ -239,6 +239,12 @@ class PluginManagerPlugin(
},
]
# Additional bundle contents
def get_additional_bundle_files(self, *args, **kwargs):
console_log = self._settings.get_plugin_logfile_path(postfix="console")
return {os.path.basename(console_log): console_log}
##~~ StartupPlugin
def on_after_startup(self):
@@ -2124,6 +2130,7 @@ def __plugin_load__():
"octoprint.ui.web.templatetypes": __plugin_implementation__.get_template_types,
"octoprint.events.register_custom_events": _register_custom_events,
"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions,
"octoprint.systeminfo.additional_bundle_files": __plugin_implementation__.get_additional_bundle_files,
}
global __plugin_helpers__
@@ -1 +1 @@
#settings_plugin_pluginmanager_pluginlist{height:calc(-350vh);display:block;width:auto;overflow-x:hidden;padding-right:2px;margin-bottom:1em;position:relative;border-top:1px solid #eee;padding-top:6px}#settings_plugin_pluginmanager_pluginlist>table{margin-top:0}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name .prop,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name .prop{white-space:nowrap}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a.disabled,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_orphanlist{display:block;width:auto;max-height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px;margin-bottom:1em}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_id,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_id{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a.disabled,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_repositorydialog h4{position:relative}#settings_plugin_pluginmanager_repositorydialog h4 a.dropdown-toggle{color:inherit;text-decoration:none;font-size:14px}#settings_plugin_pluginmanager_repositorydialog h4 ul.dropdown-menu{font-size:14px}#settings_plugin_pluginmanager_repositorydialog .form-search{text-align:center;margin-bottom:5px!important}#settings_plugin_pluginmanager_repositorydialog .form-inline{padding:5px 10px 5px 5px;margin-bottom:0}#settings_plugin_pluginmanager_repositorydialog .form-inline .help-block{margin-bottom:0;font-size:85%}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable{overflow:hidden;width:100%;height:400px;background-image:url(../img/repo_unavailable.png);text-align:center;display:table}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty div,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable div{display:table-cell;vertical-align:middle}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list{width:auto;height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry{border-bottom:1px solid #ddd;padding:5px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .meta{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .stats .prop{white-space:nowrap}#settings_plugin_pluginmanager_workingdialog_output .message{font-weight:700}#settings_plugin_pluginmanager_workingdialog_output .error{font-weight:700;color:#900}#settings_plugin_pluginmanager_workingdialog_output .stdout{color:#333}#settings_plugin_pluginmanager_workingdialog_output .stderr{color:#900}#settings_plugin_pluginmanager_workingdialog_output .call{color:#009}
#settings_plugin_pluginmanager_pluginlist{height:calc(100vh - 450px);display:block;width:auto;overflow-x:hidden;padding-right:2px;margin-bottom:1em;position:relative;border-top:1px solid #eee;padding-top:6px}#settings_plugin_pluginmanager_pluginlist>table{margin-top:0}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_name .prop,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_name .prop{white-space:nowrap}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_pluginlist table td.settings_plugin_plugin_manager_plugins_actions a.disabled,#settings_plugin_pluginmanager_pluginlist table th.settings_plugin_plugin_manager_plugins_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_orphanlist{display:block;width:auto;max-height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px;margin-bottom:1em}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_id,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_id{text-overflow:ellipsis;text-align:left}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions{text-align:center;width:80px}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a{text-decoration:none;color:#000}#settings_plugin_pluginmanager_orphanlist table td.settings_plugin_plugin_manager_orphans_actions a.disabled,#settings_plugin_pluginmanager_orphanlist table th.settings_plugin_plugin_manager_orphans_actions a.disabled{color:#ccc;cursor:default}#settings_plugin_pluginmanager_repositorydialog h4{position:relative}#settings_plugin_pluginmanager_repositorydialog h4 a.dropdown-toggle{color:inherit;text-decoration:none;font-size:14px}#settings_plugin_pluginmanager_repositorydialog h4 ul.dropdown-menu{font-size:14px}#settings_plugin_pluginmanager_repositorydialog .form-search{text-align:center;margin-bottom:5px!important}#settings_plugin_pluginmanager_repositorydialog .form-inline{padding:5px 10px 5px 5px;margin-bottom:0}#settings_plugin_pluginmanager_repositorydialog .form-inline .help-block{margin-bottom:0;font-size:85%}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable{overflow:hidden;width:100%;height:400px;background-image:url(../img/repo_unavailable.png);text-align:center;display:table}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_empty div,#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_unavailable div{display:table-cell;vertical-align:middle}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list{width:auto;height:400px;overflow-x:hidden;overflow-y:scroll;padding-right:2px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry{border-bottom:1px solid #ddd;padding:5px}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .meta{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}#settings_plugin_pluginmanager_repositorydialog #settings_plugin_pluginmanager_repositorydialog_list .entry .stats .prop{white-space:nowrap}#settings_plugin_pluginmanager_workingdialog_output .message{font-weight:700}#settings_plugin_pluginmanager_workingdialog_output .error{font-weight:700;color:#900}#settings_plugin_pluginmanager_workingdialog_output .stdout{color:#333}#settings_plugin_pluginmanager_workingdialog_output .stderr{color:#900}#settings_plugin_pluginmanager_workingdialog_output .call{color:#009}
@@ -2,7 +2,7 @@
}
#settings_plugin_pluginmanager_pluginlist {
height: calc(100vh - 450px);
height: ~"calc(100vh - 450px)";
display: block;
width: auto;
overflow-x: hidden;
+274 -37
View File
@@ -4,6 +4,7 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
import copy
import datetime
import hashlib
import logging
import logging.handlers
@@ -41,6 +42,8 @@ MINIMUM_PYTHON = "2.7.9"
MINIMUM_SETUPTOOLS = "39.0.1"
MINIMUM_PIP = "9.0.3"
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
##~~ Plugin
@@ -85,6 +88,11 @@ class SoftwareUpdatePlugin(
self._overlay_cache_ttl = 0
self._overlay_cache_timestamp = None
self._update_log = []
self._update_log_path = None
self._update_log_dirty = False
self._update_log_mutex = threading.RLock()
self._environment_supported = True
self._environment_versions = {}
self._environment_ready = threading.Event()
@@ -107,6 +115,11 @@ class SoftwareUpdatePlugin(
)
self._load_version_cache()
self._update_log_path = os.path.join(
self.get_plugin_data_folder(), "updatelog.yaml"
)
self._load_update_log()
self._overlay_cache_ttl = self._settings.get_int(["check_overlay_ttl"]) * 60
def refresh_checks(name, plugin):
@@ -145,6 +158,38 @@ class SoftwareUpdatePlugin(
},
]
# Additional bundle contents
def get_additional_bundle_files(self, *args, **kwargs):
console_log = self._settings.get_plugin_logfile_path(postfix="console")
def updatelog():
if not self._update_log:
self._load_update_log()
result = []
for entry in self._update_log:
line = "{datetime} - {display_name} - {current_version} -> {target_version} - {success} - {text}".format(
datetime=entry["datetime"].replace("T", " "),
display_name=entry["display_name"],
current_version=entry["current_version"],
target_version=entry["target_version"],
success="SUCCESS" if entry["success"] else "FAILED",
text=entry["text"]
+ (
" (Release notes: {})".format(entry["release_notes"])
if entry["release_notes"]
else ""
),
)
result.append(line)
return "\n".join(result)
return {
os.path.basename(console_log): console_log,
"plugin_softwareupdate_update.log": updatelog,
}
def on_startup(self, host, port):
console_logging_handler = logging.handlers.RotatingFileHandler(
self._settings.get_plugin_logfile_path(postfix="console"),
@@ -490,6 +535,106 @@ class SoftwareUpdatePlugin(
pass
self._version_cache_dirty = True
def _load_update_log(self):
if not os.path.isfile(self._update_log_path):
return
import yaml
try:
with open(self._update_log_path, encoding="utf-8") as f:
data = yaml.safe_load(f)
except Exception:
self._logger.exception("Error while loading update log from disk")
else:
# clean up data older than updatelog_cutoff hours
before_cleanup = len(data)
cutoff = (
datetime.datetime.now()
- datetime.timedelta(minutes=self._settings.get_int(["updatelog_cutoff"]))
).strftime(DATETIME_FORMAT)
data = sorted(
list(
filter(
lambda x: x.get("datetime") and x["datetime"] > cutoff,
data,
)
),
key=lambda x: x["datetime"],
)
cleaned_up = len(data) - before_cleanup
if cleaned_up:
self._logger.info(f"Cleaned up {cleaned_up} old update log entries")
with self._update_log_mutex:
self._update_log = data
self._update_log_dirty = False
self._logger.info("Loaded update log from disk")
def _save_update_log(self):
import yaml
from octoprint.util import atomic_write
with self._update_log_mutex:
with atomic_write(
self._update_log_path, mode="wt", max_permissions=0o666
) as file_obj:
yaml.safe_dump(
sorted(self._update_log, key=lambda x: x["datetime"]),
stream=file_obj,
default_flow_style=False,
indent=2,
allow_unicode=True,
)
self._update_log_dirty = False
self._logger.info("Saved update log to disk")
def _add_update_log_entry(
self,
target,
current_version,
target_version,
success,
text,
display_name=None,
release_notes="",
save=True,
):
if display_name is None:
display_name = target
with self._update_log_mutex:
self._update_log.append(
{
"datetime": datetime.datetime.now().strftime(DATETIME_FORMAT),
"target": target,
"current_version": current_version,
"target_version": target_version,
"display_name": display_name,
"release_notes": release_notes if release_notes else "",
"success": success,
"text": text,
},
)
self._update_log_dirty = True
if save:
self._save_update_log()
def _is_octoprint_outdated_and_can_update(self):
information, update_available, update_possible = self.get_current_versions()
if not update_available or not update_possible or "octoprint" not in information:
return False
octoprint_information = information["octoprint"]
return (
octoprint_information["updateAvailable"]
and octoprint_information["updatePossible"]
)
# ~~ SettingsPlugin API
def get_settings_defaults(self):
@@ -534,13 +679,14 @@ class SoftwareUpdatePlugin(
},
},
"pip_command": None,
"cache_ttl": 24 * 60,
"cache_ttl": 24 * 60, # 1 day
"notify_users": True,
"ignore_throttled": False,
"minimum_free_storage": 150,
"check_overlay_url": "https://plugins.octoprint.org/update_check_overlay.json",
"check_overlay_py2_url": "https://plugins.octoprint.org/update_check_overlay_py2.json",
"check_overlay_ttl": 6 * 60,
"check_overlay_ttl": 6 * 60, # 6 hours
"updatelog_cutoff": 30 * 24 * 60, # 30 days
"credentials": {
"github": None,
"bitbucket_user": None,
@@ -596,6 +742,7 @@ class SoftwareUpdatePlugin(
else:
data["octoprint_checkout_folder"] = None
data["octoprint_type"] = None
data["octoprint_release_channel"] = None
# ~~ pip check settings
@@ -912,10 +1059,41 @@ class SoftwareUpdatePlugin(
# ~~ BluePrint API
@octoprint.plugin.BlueprintPlugin.route("/check", methods=["GET"])
@octoprint.plugin.BlueprintPlugin.route("/updatelog", methods=["GET"])
@no_firstrun_access
@Permissions.PLUGIN_SOFTWAREUPDATE_CHECK.require(403)
@Permissions.ADMIN.require(403)
def get_update_log(self):
def view():
return flask.jsonify(updatelog=list(reversed(self._update_log)))
def etag(lm=None):
hash = hashlib.sha1()
def hash_update(value):
value = value.encode("utf-8")
hash.update(value)
hash_update(repr(self._update_log))
return hash.hexdigest()
def lastmodified():
if os.path.exists(self._update_log_path):
return os.stat(self._update_log_path).st_mtime
else:
return 0
return with_revalidation_checking(
etag_factory=etag, lastmodified_factory=lastmodified
)(view)()
@octoprint.plugin.BlueprintPlugin.route("/check", methods=["GET"])
def check_for_update(self):
if (
not Permissions.PLUGIN_SOFTWAREUPDATE_CHECK.can()
and not self._settings.global_get(["server", "firstRun"])
):
flask.abort(403)
request_data = flask.request.values
if "targets" in request_data or "check" in request_data:
@@ -1065,9 +1243,13 @@ class SoftwareUpdatePlugin(
)(view)()
@octoprint.plugin.BlueprintPlugin.route("/update", methods=["POST"])
@no_firstrun_access
@Permissions.PLUGIN_SOFTWAREUPDATE_UPDATE.require(403)
def perform_update(self):
if (
not Permissions.PLUGIN_SOFTWAREUPDATE_UPDATE.can()
and not self._settings.global_get(["server", "firstRun"])
):
flask.abort(403)
throttled = self._get_throttled()
if (
throttled
@@ -1216,20 +1398,49 @@ class SoftwareUpdatePlugin(
def get_template_configs(self):
from flask_babel import gettext
return [{"type": "settings", "name": gettext("Software Update")}]
templates = [
{"type": "settings", "name": gettext("Software Update")},
]
if self._is_wizard_update_required():
templates.append(
{
"type": "wizard",
"name": gettext("Update?"),
"template": "softwareupdate_wizard_update.jinja2",
"suffix": "_update",
}
)
if self._is_settings_wizard_required():
templates.append(
{
"type": "wizard",
"name": gettext("Software Update"),
"template": "softwareupdate_wizard_settings.jinja2",
"suffix": "_settings",
}
)
return templates
##~~ WizardPlugin API
def is_wizard_required(self):
def _is_wizard_update_required(self):
firstrun = self._settings.global_get(["server", "firstRun"])
return firstrun and self._is_octoprint_outdated_and_can_update()
def _is_settings_wizard_required(self):
checks = self._get_configured_checks()
check = checks.get("octoprint", None)
checkout_folder = self._get_octoprint_checkout_folder(checks=checks)
return (
check
and "method" in check
and check["method"] == "update_script"
and not checkout_folder
)
return check and check.get("method") == "update_script" and not checkout_folder
def is_wizard_required(self):
return self._is_wizard_update_required() or self._is_settings_wizard_required()
def get_wizard_version(self):
return 1
##~~ EventHandlerPlugin API
@@ -1264,6 +1475,8 @@ class SoftwareUpdatePlugin(
if check_targets is None:
check_targets = list(checks.keys())
# TODO: caching doesn't take check_targets into account!
update_available = False
update_possible = False
information = {}
@@ -1360,28 +1573,9 @@ class SoftwareUpdatePlugin(
local_name = target_information["local"]["name"]
local_value = target_information["local"]["value"]
release_notes = None
if (
target_information
and target_information["remote"]
and target_information["remote"]["value"]
):
if (
"release_notes" in populated_check
and populated_check["release_notes"]
):
release_notes = populated_check["release_notes"]
elif "release_notes" in target_information["remote"]:
release_notes = target_information["remote"][
"release_notes"
]
if release_notes:
release_notes = release_notes.format(
octoprint_version=VERSION,
target_name=target_information["remote"]["name"],
target_version=target_information["remote"]["value"],
)
release_notes = self._get_release_notes(
target_information, populated_check
)
information[target] = {
"updateAvailable": target_update_available,
@@ -1450,6 +1644,24 @@ class SoftwareUpdatePlugin(
return information, update_available, update_possible
def _get_release_notes(self, information, populated_check):
release_notes = None
if information and information["remote"] and information["remote"]["value"]:
if populated_check.get("release_notes"):
release_notes = populated_check["release_notes"]
elif "release_notes" in information["remote"]:
release_notes = information["remote"]["release_notes"]
if release_notes:
release_notes = release_notes.format(
octoprint_version=VERSION,
target_name=information["remote"]["name"],
target_version=information["remote"]["value"],
)
return release_notes
def _get_check_hash(self, check):
def dict_to_sorted_repr(d):
lines = []
@@ -1690,6 +1902,9 @@ class SoftwareUpdatePlugin(
# we might have needed to update the config, so we'll save that now
self._settings.save()
# we also need to save our update log changes
self._save_update_log()
# also, we are now longer updating
self._update_in_progress = False
@@ -1743,8 +1958,22 @@ class SoftwareUpdatePlugin(
information, update_available, update_possible, _, _ = self._get_current_version(
target, check, online=online, credentials=credentials
)
populated_check = self._populated_check(target, check)
def add_update_log(success, text):
self._add_update_log_entry(
target,
information["local"]["value"],
information["remote"]["value"],
success,
text,
display_name=populated_check["displayName"],
release_notes=self._get_release_notes(information, populated_check),
save=False,
)
if not update_available and not force:
add_update_log(False, "Target is already up to date")
return False, None
if not update_possible:
@@ -1753,6 +1982,7 @@ class SoftwareUpdatePlugin(
target
)
)
add_update_log(False, "Update not possible, missing information")
return False, None
if not information.get("compatible", True):
@@ -1761,6 +1991,7 @@ class SoftwareUpdatePlugin(
target
)
)
add_update_log(False, "Update is incompatible")
return False, None
# determine the target version to update to
@@ -1791,7 +2022,6 @@ class SoftwareUpdatePlugin(
### The actual update procedure starts here...
populated_check = self._populated_check(target, check)
try:
self._logger.info(f"Starting update of {target} to {target_version}...")
self._send_client_message(
@@ -1826,6 +2056,7 @@ class SoftwareUpdatePlugin(
"reason": "Unknown update type",
},
)
add_update_log(False, "Update failed, unknown update type")
return False, None
except exceptions.CannotUpdateOffline:
@@ -1842,6 +2073,8 @@ class SoftwareUpdatePlugin(
"reason": "No internet connection",
},
)
add_update_log(False, "No internet connection")
return False, None
except Exception as e:
self._logger.exception(
@@ -1875,6 +2108,7 @@ class SoftwareUpdatePlugin(
"reason": "unknown",
},
)
add_update_log(False, "Update failed")
else:
# make sure that any external changes to config.yaml are loaded into the system
@@ -1886,6 +2120,8 @@ class SoftwareUpdatePlugin(
del self._version_cache[target]
self._version_cache_dirty = True
add_update_log(True, "Update successful")
return target_error, target_result
def _persist_check_current(self, target, check, current):
@@ -2189,4 +2425,5 @@ def __plugin_load__():
"octoprint.cli.commands": cli.commands,
"octoprint.events.register_custom_events": _register_custom_events,
"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions,
"octoprint.systeminfo.additional_bundle_files": __plugin_implementation__.get_additional_bundle_files,
}
@@ -12,6 +12,7 @@
this.checkUrl = url + "check";
this.updateUrl = url + "update";
this.configureUrl = url + "configure";
this.updatelogUrl = url + "updatelog";
};
OctoPrintSoftwareUpdateClient.prototype.checkEntries = function (
@@ -88,6 +89,10 @@
return this.base.postJson(this.configureUrl, data, opts);
};
OctoPrintSoftwareUpdateClient.prototype.getUpdatelog = function (opts) {
return this.base.get(this.updatelogUrl, opts);
};
OctoPrintClient.registerPluginComponent(
"softwareupdate",
OctoPrintSoftwareUpdateClient
@@ -1 +1 @@
#settings_plugin_softwareupdate_updatelist{display:block;width:auto;overflow-x:hidden;padding-right:2px;margin-bottom:1em}div.swupdate-advanced{margin-bottom:5px}td.settings_plugin_softwareupdate_column_update{width:16px}td.settings_plugin_softwareupdate_column_update a{text-decoration:none;color:#000}td.settings_plugin_softwareupdate_column_information .line{display:block}td.settings_plugin_softwareupdate_column_information .settings_plugin_softwareupdate_release_channel{line-height:20px;height:20px;font-size:9px;margin-bottom:0;vertical-align:baseline}#settings_plugin_softwareupdate_workingdialog_output{font-size:.8em}#settings_plugin_softwareupdate_workingdialog_output .message{font-weight:700}#settings_plugin_softwareupdate_workingdialog_output .separator{font-weight:700;color:#666}#settings_plugin_softwareupdate_workingdialog_output .stdout{color:#333}#settings_plugin_softwareupdate_workingdialog_output .stderr{color:#900}#settings_plugin_softwareupdate_workingdialog_output .call{color:#009}#settings_plugin_softwareupdate_workingdialog_output .message_error{font-weight:700;color:#900}.softwareupdate_notification ul{margin:10px 0 10px 25px}.softwareupdate_notification ul .name{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;display:block}
#settings_plugin_softwareupdate_updatelist{display:block;width:auto;overflow-x:hidden;padding-right:2px;margin-bottom:1em}div.swupdate-advanced{margin-bottom:5px}td.settings_plugin_softwareupdate_column_update{width:16px}td.settings_plugin_softwareupdate_column_update a{text-decoration:none;color:#000}td.settings_plugin_softwareupdate_column_information .line{display:block}td.settings_plugin_softwareupdate_column_information .settings_plugin_softwareupdate_release_channel{line-height:20px;height:20px;font-size:9px;margin-bottom:0;vertical-align:baseline}#settings_plugin_softwareupdate_updatelog_list .line{display:block}#settings_plugin_softwareupdate_updatelog_list td.settings_plugin_softwareupdate_column_datetime{width:150px}#settings_plugin_softwareupdate_workingdialog_output{font-size:.8em}#settings_plugin_softwareupdate_workingdialog_output .message{font-weight:700}#settings_plugin_softwareupdate_workingdialog_output .separator{font-weight:700;color:#666}#settings_plugin_softwareupdate_workingdialog_output .stdout{color:#333}#settings_plugin_softwareupdate_workingdialog_output .stderr{color:#900}#settings_plugin_softwareupdate_workingdialog_output .call{color:#009}#settings_plugin_softwareupdate_workingdialog_output .message_error{font-weight:700;color:#900}.softwareupdate_notification ul{margin:10px 0 10px 25px}.softwareupdate_notification ul .name{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;display:block}
@@ -131,6 +131,14 @@ $(function () {
0
);
self.octoprintData = {
item: undefined,
current: ko.observable("unknown"),
available: ko.observable("unknown")
};
self.updatelog = ko.observableArray([]);
self.availableAndPossible = ko.pureComputed(function () {
return _.filter(self.versions.items(), function (info) {
return info.updateAvailable && info.updatePossible;
@@ -161,6 +169,10 @@ $(function () {
} else {
self._closePopup();
}
if (self.loginState.hasPermission(self.access.permissions.ADMIN)) {
self.requestUpdatelog();
}
};
self._showPopup = function (options, eventListeners, singleButtonNotify) {
@@ -356,6 +368,12 @@ $(function () {
});
};
if (key === "octoprint") {
self.octoprintData.item = value;
self.octoprintData.current(value.information.local.name);
self.octoprintData.available(value.information.remote.name);
}
versions.push(value);
});
self.versions.updateItems(versions);
@@ -556,6 +574,16 @@ $(function () {
});
};
self.fromUpdatelogResponse = function (response) {
self.updatelog(response.updatelog);
};
self.requestUpdatelog = function () {
OctoPrint.plugins.softwareupdate
.getUpdatelog()
.done(self.fromUpdatelogResponse);
};
self.iconTitleForEntry = function (data) {
if (data.updatePossible) {
return "";
@@ -656,8 +684,10 @@ $(function () {
self.performUpdate = function (force, items) {
if (
!self.loginState.hasPermission(
self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE
!(
self.loginState.hasPermission(
self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE
) || CONFIG_FIRST_RUN
)
)
return;
@@ -720,8 +750,10 @@ $(function () {
self.update = function (force, items) {
if (
self.updateInProgress ||
!self.loginState.hasPermission(
self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE
!(
self.loginState.hasPermission(
self.access.permissions.PLUGIN_SOFTWAREUPDATE_UPDATE
) || CONFIG_FIRST_RUN
)
) {
self._updateClicked = false;
@@ -1139,7 +1171,8 @@ $(function () {
elements: [
"#settings_plugin_softwareupdate",
"#softwareupdate_confirmation_dialog",
"#wizard_plugin_softwareupdate"
"#wizard_plugin_softwareupdate_update",
"#wizard_plugin_softwareupdate_settings"
]
});
});
@@ -33,6 +33,16 @@ td.settings_plugin_softwareupdate_column_information {
}
}
#settings_plugin_softwareupdate_updatelog_list {
.line {
display: block;
}
td.settings_plugin_softwareupdate_column_datetime {
width: 150px;
}
}
#settings_plugin_softwareupdate_workingdialog_output {
font-size: 0.8em;
@@ -73,52 +73,83 @@
</p>
{% endtrans %}</div>
<div class="pull-right">
<button class="btn btn-primary" data-bind="click: function() { $root.updateAll(); }, enable: enableUpdateAll, css: {disabled: !enableUpdateAll}"><i class="fas fa-spinner fa-spin" data-bind="visible: updateInProgress"></i> {{ _('Update all') }}</button>
<button class="btn" data-bind="click: function() { $root.performCheck(true, false, true); }, enable: !checking(), css: {disabled: checking()}"><i class="fas fa-spinner fa-spin" data-bind="visible: checking"></i> {{ _('Check for updates') }}</button>
<button class="btn" data-bind="click: function() { $root.showPluginSettings(); }" title="{{ _('Plugin Configuration')|edq }}"><i class="fas fa-wrench"></i></button>
</div>
<ul class="nav nav-pills">
<li class="active">
<a href="#settings_plugin_softwareupdate_updates" data-toggle="tab">{{ _('Current versions') }}</a>
</li>
<li>
<a href="#settings_plugin_softwareupdate_updatelog" data-toggle="tab">{{ _('Update log') }}</a>
</li>
</ul>
<h3>{{ _('Current versions') }}</h3>
<div class="tab-content">
<div class="tab-pane active" id="settings_plugin_softwareupdate_updates">
<div class="pull-right">
<button class="btn btn-primary" data-bind="click: function() { $root.updateAll(); }, enable: enableUpdateAll, css: {disabled: !enableUpdateAll}"><i class="fas fa-spinner fa-spin" data-bind="visible: updateInProgress"></i> {{ _('Update all') }}</button>
<button class="btn" data-bind="click: function() { $root.performCheck(true, false, true); }, enable: !checking(), css: {disabled: checking()}"><i class="fas fa-spinner fa-spin" data-bind="visible: checking"></i> {{ _('Check for updates') }}</button>
<button class="btn" data-bind="click: function() { $root.showPluginSettings(); }" title="{{ _('Plugin Configuration')|edq }}"><i class="fas fa-wrench"></i></button>
</div>
<div class="swupdate-advanced">
<div><small><a href="javascript:void(0)" class="muted" onclick="$(this).children().toggleClass('fa-caret-right fa-caret-down').parent().parent().parent().next().slideToggle('fast')"><i class="fas fa-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
<div class="hide">
<small class="muted" style="display: block">{{ _('Last cache refresh:') }} <span data-bind="text: cacheTimestampText"></span></small>
<button class="btn btn-block" data-bind="click: function() { $root.performCheck(true, true, true); }, enable: !checking(), css: {disabled: checking()}"><i class="fas fa-spinner fa-spin" data-bind="visible: checking"></i> {{ _('Force check for update (overrides cache used for update checks)') }}</button>
<button class="btn btn-block btn-danger" data-bind="visible: CONFIG_DEBUG, click: function() { $root.updateAll(true); }, enable: enableUpdate() && !checking(), css: {disabled: !enableUpdate() || checking()}"><i class="fas fa-spinner fa-spin" data-bind="visible: checking"></i> {{ _('Force update all (even if no new versions are available)') }}</button>
<h3>{{ _('Current versions') }}</h3>
<div class="swupdate-advanced">
<div><small><a href="javascript:void(0)" class="muted" onclick="$(this).children().toggleClass('fa-caret-right fa-caret-down').parent().parent().parent().next().slideToggle('fast')"><i class="fas fa-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
<div class="hide">
<small class="muted" style="display: block">{{ _('Last cache refresh:') }} <span data-bind="text: cacheTimestampText"></span></small>
<button class="btn btn-block" data-bind="click: function() { $root.performCheck(true, true, true); }, enable: !checking(), css: {disabled: checking()}"><i class="fas fa-spinner fa-spin" data-bind="visible: checking"></i> {{ _('Force check for update (overrides cache used for update checks)') }}</button>
<button class="btn btn-block btn-danger" data-bind="visible: CONFIG_DEBUG, click: function() { $root.updateAll(true); }, enable: enableUpdate() && !checking(), css: {disabled: !enableUpdate() || checking()}"><i class="fas fa-spinner fa-spin" data-bind="visible: checking"></i> {{ _('Force update all (even if no new versions are available)') }}</button>
</div>
</div>
<div id="settings_plugin_softwareupdate_updatelist">
<table class="table table-striped table-hover table-condensed table-hover">
<tbody data-bind="foreach: versions.paginatedItems">
<tr data-bind="attr: {title: displayName}">
<td class="settings_plugin_softwareupdate_column_update">
<a href="javascript:void(0)" data-bind="visible: compatible, click: toggleDisabled"><i class="far" data-bind="css: { muted: !updateAvailable, 'fa-bell': !disabled, 'fa-bell-slash': disabled }" title="{{ _('Update available')|edq }}"></i></a>
<span data-bind="visible: !compatible" class="muted"><i class="fas fa-power-off" title="{{ _('Not compatible') }}|edq"></i></span>
</td>
<td class="settings_plugin_softwareupdate_column_information">
<a href="javascript:void(0)" data-bind="click: function() { $root.update(false, [$data]) }, visible: $root.enableUpdate() && updateAvailable && updatePossible" class="btn btn-primary pull-right">{{ _('Update') }}</a>
<strong data-bind="text: displayName"></strong>: <span data-bind="text: displayVersion"></span> <span data-bind="invisible: updatePossible"><i class="fas fa-exclamation-triangle" data-bind="css: {'fa-unlink': !online && information && information.needs_online, 'fa-exclamation-triangle': !(!online && information && information.needs_online)}, attr: {title: $root.iconTitleForEntry($data)}"></i></span><br>
<small data-bind="visible: compatible" class="muted">
<span data-bind="visible: releaseChannels && releaseChannels.available" class="line">{{ _('Release Channel:') }} <select class="settings_plugin_softwareupdate_release_channel" data-bind="visible: releaseChannels && releaseChannels.available, value: releaseChannels.current, options: releaseChannels.available, optionsText: 'name', optionsValue: 'channel'"></select> <a href="https://faq.octoprint.org/using-release-channels" target="_blank"><i class="fas fa-question-circle"></i></a></span>
<span class="line">{{ _('Installed:') }} <span data-bind="text: information.local.name"></span></span>
<span class="line">{{ _('Available:') }} <span data-bind="text: information.remote.name"></span></span>
<span class="line" data-bind="visible: releaseNotes">{{ _('Release Notes:') }} <a data-bind="attr: {href: releaseNotes}, text: releaseNotes" target="_blank" rel="noreferrer noopener"></a></span>
<span class="line text-error" data-bind="visible: error, text: $root.errorTextForEntry($data)"></span>
</small>
<small data-bind="visible: !compatible">
<span class="line text-error">{{ _('Newer versions of this plugin are not compatible to this setup.') }}</span>
</small>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="tab-pane active" id="settings_plugin_softwareupdate_updatelog">
<h3>{{ _('Update log') }}</h3>
<div id="settings_plugin_softwareupdate_updatelog_list">
<table class="table table-striped table-hover table-condensed table-hover">
<tbody data-bind="foreach: updatelog">
<tr>
<td class="settings_plugin_softwareupdate_column_datetime" data-bind="text: datetime"></td>
<td>
<span class="line" data-bind="css: { 'text-error': !success, 'text-success': success }"><strong data-bind="text: display_name"></strong> <span data-bind="text: current_version"></span> ➡ <span data-bind="text: target_version"></span></span>
<span class="line" data-bind="text: text"></span>
<span class="line" data-bind="visible: release_notes"><a data-bind="attr: {href: release_notes}" target="_blank" rel="noreferrer noopener">{{ _('Release Notes') }}</a></span>
</td>
</tr>
</tbody>
</table>
</div>
<small>{{ _('Please note that the update log will only contain entries for updates performed through OctoPrint\'s Software Update plugin.') }}</small>
</div>
</div>
<div id="settings_plugin_softwareupdate_updatelist">
<table class="table table-striped table-hover table-condensed table-hover">
<tbody data-bind="foreach: versions.paginatedItems">
<tr data-bind="attr: {title: displayName}">
<td class="settings_plugin_softwareupdate_column_update">
<a href="javascript:void(0)" data-bind="visible: compatible, click: toggleDisabled"><i class="far" data-bind="css: { muted: !updateAvailable, 'fa-bell': !disabled, 'fa-bell-slash': disabled }" title="{{ _('Update available')|edq }}"></i></a>
<span data-bind="visible: !compatible" class="muted"><i class="fas fa-power-off" title="{{ _('Not compatible') }}|edq"></i></span>
</td>
<td class="settings_plugin_softwareupdate_column_information">
<a href="javascript:void(0)" data-bind="click: function() { $root.update(false, [$data]) }, visible: $root.enableUpdate() && updateAvailable && updatePossible" class="btn btn-primary pull-right">{{ _('Update') }}</a>
<strong data-bind="text: displayName"></strong>: <span data-bind="text: displayVersion"></span> <span data-bind="invisible: updatePossible"><i class="fas fa-exclamation-triangle" data-bind="css: {'fa-unlink': !online && information && information.needs_online, 'fa-exclamation-triangle': !(!online && information && information.needs_online)}, attr: {title: $root.iconTitleForEntry($data)}"></i></span><br>
<small data-bind="visible: compatible" class="muted">
<span data-bind="visible: releaseChannels && releaseChannels.available" class="line">{{ _('Release Channel:') }} <select class="settings_plugin_softwareupdate_release_channel" data-bind="visible: releaseChannels && releaseChannels.available, value: releaseChannels.current, options: releaseChannels.available, optionsText: 'name', optionsValue: 'channel'"></select> <a href="https://faq.octoprint.org/using-release-channels" target="_blank"><i class="fas fa-question-circle"></i></a></span>
<span class="line">{{ _('Installed:') }} <span data-bind="text: information.local.name"></span></span>
<span class="line">{{ _('Available:') }} <span data-bind="text: information.remote.name"></span></span>
<span class="line" data-bind="visible: releaseNotes">{{ _('Release Notes:') }} <a data-bind="attr: {href: releaseNotes}, text: releaseNotes" target="_blank" rel="noreferrer noopener"></a></span>
<span class="line text-error" data-bind="visible: error, text: $root.errorTextForEntry($data)"></span>
</small>
<small data-bind="visible: !compatible">
<span class="line text-error">{{ _('Newer versions of this plugin are not compatible to this setup.') }}</span>
</small>
</td>
</tr>
</tbody>
</table>
</div>
<div id="settings_plugin_softwareupdate_configurationdialog" class="modal hide fade-in">
<div class="modal-header">
@@ -0,0 +1,9 @@
<h3>{{ _('Update?') }}</h3>
{% trans %}<p>
You are about to set up OctoPrint <span data-bind="text: octoprintData.current"></span>
but <span data-bind="text: octoprintData.available"></span> is available. It is strongly
recommended to update to the latest version before you continue.
</p>{% endtrans %}
<a href="javascript:void(0)" data-bind="click: function() { $root.update(false, [$root.octoprintData.item]) }" class="btn btn-primary btn-block">{{ _('Update') }}</a>
+5 -1
View File
@@ -1554,6 +1554,7 @@ class SystemInfoBundleHandler(CorsSupportMixin, tornado.web.RequestHandler):
from octoprint.server import (
connectivityChecker,
environmentDetector,
pluginManager,
printer,
safe_mode,
)
@@ -1570,7 +1571,10 @@ class SystemInfoBundleHandler(CorsSupportMixin, tornado.web.RequestHandler):
)
z = get_systeminfo_bundle(
systeminfo, settings().getBaseFolder("logs"), printer=printer
systeminfo,
settings().getBaseFolder("logs"),
printer=printer,
plugin_manager=pluginManager,
)
self.set_header("Content-Type", "application/zip")
+1
View File
@@ -357,6 +357,7 @@ default_settings = {
],
"usersettings": ["access", "interface"],
"wizard": [
"plugin_softwareupdate_update",
"plugin_backup",
"plugin_corewizard_acl",
"plugin_corewizard_onlinecheck",
@@ -1,8 +1,14 @@
ko.bindingHandlers.invisible = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
if (!valueAccessor()) return;
var val = ko.utils.unwrapObservable(valueAccessor());
ko.bindingHandlers.style.update(element, function () {
return {visibility: "hidden"};
return {visibility: val ? "hidden" : "visible"};
});
},
update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var val = ko.utils.unwrapObservable(valueAccessor());
ko.bindingHandlers.style.update(element, function () {
return {visibility: val ? "hidden" : "visible"};
});
}
};
@@ -967,8 +967,8 @@ $(function () {
if (data["gcodeAnalysis"]) {
if (
data["gcodeAnalysis"]["_empty"] ||
(data["gcodeAnalysis"]["dimensions"] &&
data["gcodeAnalysis"]["dimensions"]["width"] === 0 &&
!data["gcodeAnalysis"]["dimensions"] ||
(data["gcodeAnalysis"]["dimensions"]["width"] === 0 &&
data["gcodeAnalysis"]["dimensions"]["depth"] === 0 &&
data["gcodeAnalysis"]["dimensions"]["height"] === 0)
) {