Merge branch 'maintenance' into devel
This commit is contained in:
commit
d248df3826
4 files changed
+59
-16
No files matched your search
@@ -48,6 +48,7 @@ _RPI_REVISION_MAP = {
|
||||
"a020a0": "CM3",
|
||||
"a22082": "3B",
|
||||
"a32082": "3B",
|
||||
"a020d3": "3B+"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
|
||||
|
||||
import octoprint.plugin
|
||||
|
||||
import copy
|
||||
import flask
|
||||
import os
|
||||
import threading
|
||||
@@ -916,6 +917,20 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
# determine the target version to update to
|
||||
target_version = information["remote"]["value"]
|
||||
target_error = False
|
||||
target_result = None
|
||||
|
||||
def trigger_event(success, **additional_payload):
|
||||
if success:
|
||||
event = "update_succeeded"
|
||||
else:
|
||||
event = "update_failed"
|
||||
|
||||
payload = copy.copy(additional_payload)
|
||||
payload.update(dict(target=target,
|
||||
from_version=information["local"]["value"],
|
||||
to_version=target_version))
|
||||
|
||||
self._event_bus.fire("plugin_softwareupdate_{}".format(event), payload=payload)
|
||||
|
||||
### The actual update procedure starts here...
|
||||
|
||||
@@ -930,6 +945,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
update_result = updater.perform_update(target, populated_check, target_version, log_cb=self._log, online=online)
|
||||
target_result = ("success", update_result)
|
||||
self._logger.info("Update of %s to %s successful!" % (target, target_version))
|
||||
trigger_event(True)
|
||||
|
||||
except exceptions.UnknownUpdateType:
|
||||
self._logger.warn("Update of %s can not be performed, unknown update type" % target)
|
||||
@@ -942,6 +958,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
|
||||
except Exception as e:
|
||||
self._logger.exception("Update of %s can not be performed, please also check plugin_softwareupdate_console.log for possible causes of this" % target)
|
||||
trigger_event(False)
|
||||
|
||||
if not "ignorable" in populated_check or not populated_check["ignorable"]:
|
||||
target_error = True
|
||||
|
||||
|
||||
@@ -19,12 +19,13 @@ from octoprint.util import RepeatedTimer
|
||||
from octoprint.util.version import get_octoprint_version_string
|
||||
from octoprint.events import Events
|
||||
|
||||
TRACKING_URL = "https://tracking.octoprint.org/track/{id}/{event}/?{args}"
|
||||
TRACKING_URL = "https://tracking.octoprint.org/track/{id}/{event}/"
|
||||
|
||||
# noinspection PyMissingConstructor
|
||||
class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
octoprint.plugin.EnvironmentDetectionPlugin,
|
||||
octoprint.plugin.StartupPlugin,
|
||||
octoprint.plugin.ShutdownPlugin,
|
||||
octoprint.plugin.TemplatePlugin,
|
||||
octoprint.plugin.AssetPlugin,
|
||||
octoprint.plugin.WizardPlugin,
|
||||
@@ -72,11 +73,18 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._ping_worker = RepeatedTimer(ping, self._track_ping)
|
||||
self._ping_worker.start()
|
||||
|
||||
##~~ ShutdownPlugin
|
||||
|
||||
def on_shutdown(self):
|
||||
self._track_shutdown()
|
||||
|
||||
##~~ EventHandlerPlugin
|
||||
|
||||
def on_event(self, event, payload):
|
||||
if event.startswith("plugin_pluginmanager_"):
|
||||
self._track_plugin_event(event, payload)
|
||||
if event.startswith("plugin_softwareupdate_"):
|
||||
self._track_update_event(event, payload)
|
||||
elif event in (Events.PRINT_STARTED, Events.PRINT_DONE, Events.PRINT_FAILED, Events.PRINT_CANCELLED):
|
||||
self._track_printjob_event(event, payload)
|
||||
|
||||
@@ -113,9 +121,22 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._settings.save()
|
||||
|
||||
def _track_startup(self):
|
||||
self._track("startup",
|
||||
version=get_octoprint_version_string(),
|
||||
os=self._environment[b"os"][b"id"])
|
||||
payload = dict(version=get_octoprint_version_string(),
|
||||
os=self._environment[b"os"][b"id"],
|
||||
python=self._environment[b"python"][b"version"],
|
||||
pip=self._environment[b"python"][b"pip"],
|
||||
cores=self._environment[b"hardware"][b"cores"],
|
||||
freq=self._environment[b"hardware"][b"freq"],
|
||||
ram=self._environment[b"hardware"][b"ram"])
|
||||
|
||||
if b"plugins" in self._environment and b"octopi_support" in self._environment[b"plugins"]:
|
||||
payload[b"octopi_version"] = self._environment[b"plugins"][b"octopi_support"][b"version"]
|
||||
payload[b"pi_model"] = self._environment[b"plugins"][b"octopi_support"][b"model"]
|
||||
|
||||
self._track("startup", **payload)
|
||||
|
||||
def _track_shutdown(self):
|
||||
self._track("shutdown")
|
||||
|
||||
def _track_ping(self):
|
||||
self._track("ping")
|
||||
@@ -130,29 +151,35 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
elif event.endswith("_disableplugin"):
|
||||
self._track("disable_plugin", plugin=payload.get(b"id"), plugin_version=payload.get(b"version"))
|
||||
|
||||
def _track_update_event(self, event, payload):
|
||||
if event.endswith("_update_succeeded"):
|
||||
self._track("update_successful", target=payload.get("target"), from_version=payload.get("from_version"), to_version=payload.get("to_version"))
|
||||
elif event.endswith("_update_failed"):
|
||||
self._track("update_failed", target=payload.get("target"), from_version=payload.get("from_version"), to_version=payload.get("to_version"))
|
||||
|
||||
def _track_printjob_event(self, event, payload):
|
||||
sha = hashlib.sha1()
|
||||
sha.update(payload.get("name"))
|
||||
|
||||
event = None
|
||||
track_event = None
|
||||
args = dict(origin=payload.get(b"origin"), file=sha.hexdigest())
|
||||
|
||||
if event == Events.PRINT_STARTED:
|
||||
event = "print_started"
|
||||
track_event = "print_started"
|
||||
elif event == Events.PRINT_DONE:
|
||||
try:
|
||||
elapsed = int(payload.get(b"time"))
|
||||
except ValueError:
|
||||
elapsed = "unknown"
|
||||
args[b"elapsed"] = elapsed
|
||||
event = "print_done"
|
||||
track_event = "print_done"
|
||||
elif event == Events.PRINT_FAILED:
|
||||
event = "print_failed"
|
||||
track_event = "print_failed"
|
||||
elif event == Events.PRINT_CANCELLED:
|
||||
event = "print_cancelled"
|
||||
track_event = "print_cancelled"
|
||||
|
||||
if event is not None:
|
||||
self._track(event, **args)
|
||||
if track_event is not None:
|
||||
self._track(track_event, **args)
|
||||
|
||||
def _track(self, event, **kwargs):
|
||||
if not self._settings.get_boolean([b"enabled"]):
|
||||
@@ -162,13 +189,12 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
|
||||
def _do_track(self, event, **kwargs):
|
||||
server = self._settings.get([b"server"])
|
||||
url = server.format(id=self._settings.get([b"unique_id"]),
|
||||
event=event,
|
||||
args="&".join(map(lambda x: "{}={}".format(x[0], x[1]), kwargs.items())))
|
||||
url = server.format(id=self._settings.get([b"unique_id"]), event=event)
|
||||
|
||||
headers = {"User-Agent": "OctoPrint/{}".format(get_octoprint_version_string())}
|
||||
try:
|
||||
requests.get(url,
|
||||
params=kwargs,
|
||||
timeout=3.1,
|
||||
headers=headers)
|
||||
self._logger.debug("Sent tracking event to {}".format(url))
|
||||
|
||||
@@ -1042,8 +1042,6 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
else:
|
||||
eventManager().fire(Events.FILE_DESELECTED)
|
||||
|
||||
self._create_estimator()
|
||||
|
||||
self._setJobData(full_path, size, sd, user=user)
|
||||
self._stateMonitor.set_state(self._dict(text=self.get_state_string(), flags=self._getStateFlags()))
|
||||
|
||||
|
||||
Reference in new issue
Block a user