event tags etc. are not supposed to be binary
This commit is contained in:
1 parent
70a104e32a
commit
ea64c017e8
2 files changed
+70
-70
No files matched your search
@@ -46,7 +46,7 @@ class ActionCommandPromptPlugin(octoprint.plugin.AssetPlugin,
|
||||
self._selection_command = None
|
||||
|
||||
def initialize(self):
|
||||
self._selection_command = self._settings.get([b"selection_command"])
|
||||
self._selection_command = self._settings.get(["selection_command"])
|
||||
|
||||
# Additional permissions hook
|
||||
|
||||
@@ -72,7 +72,7 @@ class ActionCommandPromptPlugin(octoprint.plugin.AssetPlugin,
|
||||
|
||||
def on_settings_save(self, data):
|
||||
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
||||
self._selection_command = self._settings.get([b"selection_command"])
|
||||
self._selection_command = self._settings.get(["selection_command"])
|
||||
|
||||
#~ SimpleApiPlugin
|
||||
|
||||
@@ -109,7 +109,7 @@ class ActionCommandPromptPlugin(octoprint.plugin.AssetPlugin,
|
||||
#~ action command handler
|
||||
|
||||
def action_command_handler(self, comm, line, action, *args, **kwargs):
|
||||
if not action.startswith(b"prompt_"):
|
||||
if not action.startswith("prompt_"):
|
||||
return
|
||||
|
||||
if self._selection_command is None:
|
||||
@@ -119,17 +119,17 @@ class ActionCommandPromptPlugin(octoprint.plugin.AssetPlugin,
|
||||
parts = action.split(None, 1)
|
||||
if len(parts) == 1:
|
||||
action = parts[0]
|
||||
parameter = b""
|
||||
parameter = ""
|
||||
else:
|
||||
action, parameter = parts
|
||||
|
||||
if action == b"prompt_begin":
|
||||
if action == "prompt_begin":
|
||||
if self._prompt is not None and self._prompt.active:
|
||||
self._logger.warning("Prompt is already defined")
|
||||
return
|
||||
self._prompt = Prompt(parameter.strip())
|
||||
|
||||
elif action == b"prompt_choice" or action == b"prompt_button":
|
||||
elif action == "prompt_choice" or action == "prompt_button":
|
||||
if self._prompt is None:
|
||||
return
|
||||
if self._prompt.active:
|
||||
@@ -137,7 +137,7 @@ class ActionCommandPromptPlugin(octoprint.plugin.AssetPlugin,
|
||||
return
|
||||
self._prompt.add_choice(parameter.strip())
|
||||
|
||||
elif action == b"prompt_show":
|
||||
elif action == "prompt_show":
|
||||
if self._prompt is None:
|
||||
return
|
||||
if self._prompt.active:
|
||||
@@ -145,7 +145,7 @@ class ActionCommandPromptPlugin(octoprint.plugin.AssetPlugin,
|
||||
return
|
||||
self._show_prompt()
|
||||
|
||||
elif action == b"prompt_end":
|
||||
elif action == "prompt_end":
|
||||
if self._prompt is None:
|
||||
return
|
||||
self._close_prompt()
|
||||
@@ -176,6 +176,6 @@ __plugin_disabling_discouraged__ = gettext("Without this plugin your printer wil
|
||||
__plugin_license__ = "AGPLv3"
|
||||
__plugin_implementation__ = ActionCommandPromptPlugin()
|
||||
__plugin_hooks__ = {
|
||||
b"octoprint.comm.protocol.action": __plugin_implementation__.action_command_handler,
|
||||
b"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions
|
||||
"octoprint.comm.protocol.action": __plugin_implementation__.action_command_handler,
|
||||
"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions
|
||||
}
|
||||
@@ -74,11 +74,11 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
never=[["server"], ["ping"]])
|
||||
|
||||
def on_settings_save(self, data):
|
||||
enabled = self._settings.get([b"enabled"])
|
||||
enabled = self._settings.get(["enabled"])
|
||||
|
||||
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
||||
|
||||
if enabled is None and self._settings.get([b"enabled"]):
|
||||
if enabled is None and self._settings.get(["enabled"]):
|
||||
# tracking was just enabled, let's start up tracking
|
||||
self._start_tracking()
|
||||
|
||||
@@ -95,7 +95,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
##~~ ShutdownPlugin
|
||||
|
||||
def on_shutdown(self):
|
||||
if not self._settings.get_boolean([b"enabled"]):
|
||||
if not self._settings.get_boolean(["enabled"]):
|
||||
return
|
||||
self._track_shutdown()
|
||||
|
||||
@@ -103,7 +103,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
def on_event(self, event, payload):
|
||||
if not self._settings.get_boolean([b"enabled"]):
|
||||
if not self._settings.get_boolean(["enabled"]):
|
||||
return
|
||||
|
||||
if event in (Events.PRINT_STARTED, Events.PRINT_DONE, Events.PRINT_FAILED, Events.PRINT_CANCELLED):
|
||||
@@ -153,18 +153,18 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
##~~ WizardPlugin
|
||||
|
||||
def is_wizard_required(self):
|
||||
return self._settings.get([b"enabled"]) is None
|
||||
return self._settings.get(["enabled"]) is None
|
||||
|
||||
##~~ helpers
|
||||
|
||||
def _init_id(self):
|
||||
if not self._settings.get([b"unique_id"]):
|
||||
if not self._settings.get(["unique_id"]):
|
||||
import uuid
|
||||
self._settings.set([b"unique_id"], str(uuid.uuid4()))
|
||||
self._settings.set(["unique_id"], str(uuid.uuid4()))
|
||||
self._settings.save()
|
||||
|
||||
def _start_tracking(self):
|
||||
if not self._settings.get_boolean([b"enabled"]):
|
||||
if not self._settings.get_boolean(["enabled"]):
|
||||
return
|
||||
|
||||
if self._ping_worker is None:
|
||||
@@ -183,7 +183,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._track_startup()
|
||||
|
||||
def _track_ping(self):
|
||||
if not self._settings.get_boolean([b"enabled"]):
|
||||
if not self._settings.get_boolean(["enabled"]):
|
||||
return
|
||||
|
||||
uptime = int(monotonic_time() - self._startup_time)
|
||||
@@ -194,23 +194,23 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
return
|
||||
|
||||
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"])
|
||||
os=self._environment["os"]["id"],
|
||||
python=self._environment["python"]["version"],
|
||||
pip=self._environment["python"]["pip"],
|
||||
cores=self._environment["hardware"]["cores"],
|
||||
freq=self._environment["hardware"]["freq"],
|
||||
ram=self._environment["hardware"]["ram"])
|
||||
|
||||
if b"plugins" in self._environment and b"pi_support" in self._environment[b"plugins"]:
|
||||
payload[b"pi_model"] = self._environment[b"plugins"][b"pi_support"][b"model"]
|
||||
if "plugins" in self._environment and "pi_support" in self._environment["plugins"]:
|
||||
payload["pi_model"] = self._environment["plugins"]["pi_support"]["model"]
|
||||
|
||||
if b"octopi_version" in self._environment[b"plugins"][b"pi_support"]:
|
||||
payload[b"octopi_version"] = self._environment[b"plugins"][b"pi_support"][b"octopi_version"]
|
||||
if "octopi_version" in self._environment["plugins"]["pi_support"]:
|
||||
payload["octopi_version"] = self._environment["plugins"]["pi_support"]["octopi_version"]
|
||||
|
||||
self._track("startup", **payload)
|
||||
|
||||
def _track_shutdown(self):
|
||||
if not self._settings.get_boolean([b"enabled"]):
|
||||
if not self._settings.get_boolean(["enabled"]):
|
||||
return
|
||||
|
||||
if not self._settings.get_boolean(["events", "startup"]):
|
||||
@@ -223,13 +223,13 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
return
|
||||
|
||||
if event.endswith("_install_plugin"):
|
||||
self._track("install_plugin", plugin=payload.get(b"id"), plugin_version=payload.get(b"version"))
|
||||
self._track("install_plugin", plugin=payload.get("id"), plugin_version=payload.get("version"))
|
||||
elif event.endswith("_uninstall_plugin"):
|
||||
self._track("uninstall_plugin", plugin=payload.get(b"id"), plugin_version=payload.get(b"version"))
|
||||
self._track("uninstall_plugin", plugin=payload.get("id"), plugin_version=payload.get("version"))
|
||||
elif event.endswith("_enable_plugin"):
|
||||
self._track("enable_plugin", plugin=payload.get(b"id"), plugin_version=payload.get(b"version"))
|
||||
self._track("enable_plugin", plugin=payload.get("id"), plugin_version=payload.get("version"))
|
||||
elif event.endswith("_disable_plugin"):
|
||||
self._track("disable_plugin", plugin=payload.get(b"id"), plugin_version=payload.get(b"version"))
|
||||
self._track("disable_plugin", plugin=payload.get("id"), plugin_version=payload.get("version"))
|
||||
|
||||
def _track_update_event(self, event, payload):
|
||||
if not self._settings.get_boolean(["events", "update"]):
|
||||
@@ -244,15 +244,15 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
if not self._settings.get_boolean(["events", "throttled"]):
|
||||
return
|
||||
|
||||
args = dict(throttled_now=payload[b"current_issue"],
|
||||
throttled_past=payload[b"past_issue"],
|
||||
throttled_mask=payload[b"raw_value"],
|
||||
throttled_voltage_now=payload[b"current_undervoltage"],
|
||||
throttled_voltage_past=payload[b"past_undervoltage"],
|
||||
throttled_overheat_now=payload[b"current_overheat"],
|
||||
throttled_overheat_past=payload[b"past_overheat"])
|
||||
args = dict(throttled_now=payload["current_issue"],
|
||||
throttled_past=payload["past_issue"],
|
||||
throttled_mask=payload["raw_value"],
|
||||
throttled_voltage_now=payload["current_undervoltage"],
|
||||
throttled_voltage_past=payload["past_undervoltage"],
|
||||
throttled_overheat_now=payload["current_overheat"],
|
||||
throttled_overheat_past=payload["past_overheat"])
|
||||
|
||||
if payload[b"current_issue"]:
|
||||
if payload["current_issue"]:
|
||||
track_event = "system_throttled"
|
||||
else:
|
||||
track_event = "system_unthrottled"
|
||||
@@ -264,19 +264,19 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
if not self._settings.get_boolean(["events", "commerror"]):
|
||||
return
|
||||
|
||||
if not b"reason" in payload or not b"error" in payload:
|
||||
if not "reason" in payload or not "error" in payload:
|
||||
return
|
||||
|
||||
track_event = "commerror_{}".format(payload[b"reason"])
|
||||
args = dict(commerror_text=payload[b"error"])
|
||||
track_event = "commerror_{}".format(payload["reason"])
|
||||
args = dict(commerror_text=payload["error"])
|
||||
|
||||
if callable(self._helpers_get_throttle_state):
|
||||
try:
|
||||
throttle_state = self._helpers_get_throttle_state(run_now=True)
|
||||
if throttle_state and (throttle_state.get(b"current_issue", False) or throttle_state.get(b"past_issue", False)):
|
||||
args[b"throttled_now"] = throttle_state[b"current_issue"]
|
||||
args[b"throttled_past"] = throttle_state[b"past_issue"]
|
||||
args[b"throttled_mask"] = throttle_state[b"raw_value"]
|
||||
if throttle_state and (throttle_state.get("current_issue", False) or throttle_state.get("past_issue", False)):
|
||||
args["throttled_now"] = throttle_state["current_issue"]
|
||||
args["throttled_past"] = throttle_state["past_issue"]
|
||||
args["throttled_mask"] = throttle_state["raw_value"]
|
||||
except:
|
||||
# ignored
|
||||
pass
|
||||
@@ -287,7 +287,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
if not self._settings.get_boolean(["events", "printjob"]):
|
||||
return
|
||||
|
||||
unique_id = self._settings.get([b"unique_id"])
|
||||
unique_id = self._settings.get(["unique_id"])
|
||||
if not unique_id:
|
||||
return
|
||||
|
||||
@@ -296,33 +296,33 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
sha.update(unique_id)
|
||||
|
||||
track_event = None
|
||||
args = dict(origin=payload.get(b"origin"), file=sha.hexdigest())
|
||||
args = dict(origin=payload.get("origin"), file=sha.hexdigest())
|
||||
|
||||
if event == Events.PRINT_STARTED:
|
||||
track_event = "print_started"
|
||||
elif event == Events.PRINT_DONE:
|
||||
try:
|
||||
elapsed = int(payload.get(b"time"))
|
||||
args[b"elapsed"] = elapsed
|
||||
elapsed = int(payload.get("time"))
|
||||
args["elapsed"] = elapsed
|
||||
except ValueError:
|
||||
pass
|
||||
track_event = "print_done"
|
||||
elif event == Events.PRINT_FAILED:
|
||||
try:
|
||||
elapsed = int(payload.get(b"time"))
|
||||
args[b"elapsed"] = elapsed
|
||||
elapsed = int(payload.get("time"))
|
||||
args["elapsed"] = elapsed
|
||||
except ValueError:
|
||||
pass
|
||||
args[b"reason"] = payload.get(b"reason", "unknown")
|
||||
args["reason"] = payload.get("reason", "unknown")
|
||||
|
||||
if b"error" in payload and self._settings.get_boolean(["events", "commerror"]):
|
||||
args[b"commerror_text"] = payload[b"error"]
|
||||
if "error" in payload and self._settings.get_boolean(["events", "commerror"]):
|
||||
args["commerror_text"] = payload["error"]
|
||||
|
||||
track_event = "print_failed"
|
||||
elif event == Events.PRINT_CANCELLED:
|
||||
try:
|
||||
elapsed = int(payload.get(b"time"))
|
||||
args[b"elapsed"] = elapsed
|
||||
elapsed = int(payload.get("time"))
|
||||
args["elapsed"] = elapsed
|
||||
except ValueError:
|
||||
pass
|
||||
track_event = "print_cancelled"
|
||||
@@ -330,10 +330,10 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
if callable(self._helpers_get_throttle_state):
|
||||
try:
|
||||
throttle_state = self._helpers_get_throttle_state(run_now=True)
|
||||
if throttle_state and (throttle_state.get(b"current_issue", False) or throttle_state.get(b"past_issue", False)):
|
||||
args[b"throttled_now"] = throttle_state[b"current_issue"]
|
||||
args[b"throttled_past"] = throttle_state[b"past_issue"]
|
||||
args[b"throttled_mask"] = throttle_state[b"raw_value"]
|
||||
if throttle_state and (throttle_state.get("current_issue", False) or throttle_state.get("past_issue", False)):
|
||||
args["throttled_now"] = throttle_state["current_issue"]
|
||||
args["throttled_past"] = throttle_state["past_issue"]
|
||||
args["throttled_mask"] = throttle_state["raw_value"]
|
||||
except:
|
||||
# ignored
|
||||
pass
|
||||
@@ -357,11 +357,11 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
return
|
||||
|
||||
self._track("printer_safety_warning",
|
||||
printer_safety_warning_type=payload.get(b"warning_type", "unknown"),
|
||||
printer_safety_check_name=payload.get(b"check_name", "unknown"))
|
||||
printer_safety_warning_type=payload.get("warning_type", "unknown"),
|
||||
printer_safety_check_name=payload.get("check_name", "unknown"))
|
||||
|
||||
def _track(self, event, **kwargs):
|
||||
if not self._settings.get_boolean([b"enabled"]):
|
||||
if not self._settings.get_boolean(["enabled"]):
|
||||
return
|
||||
|
||||
self._executor.submit(self._do_track, event, **kwargs)
|
||||
@@ -370,14 +370,14 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin,
|
||||
if not self._connectivity_checker.online:
|
||||
return
|
||||
|
||||
if not self._settings.get_boolean([b"enabled"]):
|
||||
if not self._settings.get_boolean(["enabled"]):
|
||||
return
|
||||
|
||||
unique_id = self._settings.get([b"unique_id"])
|
||||
unique_id = self._settings.get(["unique_id"])
|
||||
if not unique_id:
|
||||
return
|
||||
|
||||
server = self._settings.get([b"server"])
|
||||
server = self._settings.get(["server"])
|
||||
url = server.format(id=unique_id, event=event)
|
||||
# Don't print the URL or UUID! That would expose the UUID in forums/tickets
|
||||
# if pasted. It's okay for the user to know their uuid, but it shouldn't be shared.
|
||||
|
||||
Reference in new issue
Block a user