From bfd847f0a63658ab27b9f3e287c5361f11a670ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 12 Dec 2018 15:16:17 +0100 Subject: [PATCH 01/12] GCODE viewer: Bring back the layer count --- src/octoprint/static/js/app/viewmodels/gcode.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/octoprint/static/js/app/viewmodels/gcode.js b/src/octoprint/static/js/app/viewmodels/gcode.js index 522659f97..f6254fe43 100644 --- a/src/octoprint/static/js/app/viewmodels/gcode.js +++ b/src/octoprint/static/js/app/viewmodels/gcode.js @@ -530,6 +530,7 @@ $(function() { output.push(gettext("Model size") + ": " + model.width.toFixed(2) + "mm × " + model.depth.toFixed(2) + "mm × " + model.height.toFixed(2) + "mm"); output.push(gettext("Estimated layer height") + ": " + model.layerHeight.toFixed(2) + gettext("mm")); output.push(gettext("Estimated total print time") + ": " + formatFuzzyPrintTime(model.printTime)); + output.push(gettext("Layers with extrusion") + ": " + model.layersPrinted.toFixed(0)); self.ui_modelInfo(output.join("
")); From ae36a3905acf55215c189719532dab78b4d1dc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 12 Dec 2018 15:25:38 +0100 Subject: [PATCH 02/12] printer safety: Mark Malyan M200 fw 4.0+ as safe Implements #2947 --- src/octoprint/plugins/printer_safety_check/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/plugins/printer_safety_check/__init__.py b/src/octoprint/plugins/printer_safety_check/__init__.py index 38a09533d..6970a9b16 100644 --- a/src/octoprint/plugins/printer_safety_check/__init__.py +++ b/src/octoprint/plugins/printer_safety_check/__init__.py @@ -43,8 +43,8 @@ ENDER3_RECEIVED_TEST = lambda line: line and ENDER3_AUTHOR in line.lower() # iMe on Micro3D IME_M115_TEST = lambda name, data: name and name.lower().startswith("ime") -# Malyan M200 aka Monoprice Select Mini -MALYANM200_M115_TEST = lambda name, data: name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" +# Malyan M200 aka Monoprice Select Mini, versions less than 4.0 +MALYANM200_M115_TEST = lambda name, data: name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" and get_comparable_version(data.get("VER", "0")) < get_comparable_version("4.0") # Stock Micro3D MICRO3D_M115_TEST = lambda name, data: name and name.lower().startswith("micro3d") From 8cf5ca95892784fc650960f804eef6a07c1849eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 10 Dec 2018 12:13:11 +0100 Subject: [PATCH 03/12] tracking: Track firmware/communication errors --- src/octoprint/plugins/tracking/__init__.py | 30 +++++++++++++++++++ .../templates/tracking_settings.jinja2 | 3 ++ src/octoprint/printer/standard.py | 12 +------- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index 577999f98..46c6978e4 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -60,6 +60,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, ping=15*60, events=dict(startup=True, printjob=True, + commerror=True, plugin=True, update=True, printer=True, @@ -117,6 +118,8 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, self._track_throttle_event(event, payload) elif event in (Events.PRINT_STARTED, Events.PRINT_DONE, Events.PRINT_FAILED, Events.PRINT_CANCELLED): self._track_printjob_event(event, payload) + elif event in (Events.ERROR,): + self._track_commerror_event(event, payload) elif event in (Events.CONNECTED,): self._printer_connection_parameters = dict(port=payload["port"], baudrate=payload["baudrate"]) @@ -228,6 +231,29 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, if track_event is not None: self._track(track_event, **args) + def _track_commerror_event(self, event, payload): + if not self._settings.get_boolean(["events", "commerror"]): + return + + if not b"reason" in payload or not b"error" in payload: + return + + track_event = "commerror_{}".format(payload[b"reason"]) + args = dict(commerror_text=payload[b"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"] + except: + # ignored + pass + + self._track(track_event, **args) + def _track_printjob_event(self, event, payload): if not self._settings.get_boolean(["events", "printjob"]): return @@ -255,6 +281,10 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, elapsed = "unknown" args[b"elapsed"] = elapsed args[b"reason"] = payload.get(b"reason", "unknown") + + if b"error" in payload and self._settings.get_boolean(["events", "commerror"]): + args[b"commerror_text"] = payload[b"error"] + track_event = "print_failed" elif event == Events.PRINT_CANCELLED: track_event = "print_cancelled" diff --git a/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 b/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 index 217bc26c6..292a898bd 100644 --- a/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 +++ b/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 @@ -31,6 +31,9 @@ + diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index a3c589048..e010b5176 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -974,6 +974,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): if payload: payload["time"] = self._comm.getPrintTime() payload["reason"] = "error" + payload["error"] = self._comm.getErrorString() def finalize(): self._fileManager.log_print(payload["origin"], @@ -1104,17 +1105,6 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._stateMonitor.set_state(self._dict(text=self.get_state_string(), flags=self._getStateFlags())) - def on_comm_print_job_failed(self, reason=None): - payload = self._payload_for_print_job_event() - - if reason: - payload["reason"] = reason - else: - payload["reason"] = "unknown" - - if payload: - eventManager().fire(Events.PRINT_FAILED, payload) - def on_comm_print_job_cancelling(self, firmware_error=None): payload = self._payload_for_print_job_event() if payload: From 49b995b2345c5bc3b07b2f5e5e8e75f2ddd41079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 12 Dec 2018 16:06:15 +0100 Subject: [PATCH 04/12] Set 10min idle timeout on tornado under windows Possible workaround for #2916 --- src/octoprint/server/__init__.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index e59effb5a..d6db68d8a 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -21,6 +21,7 @@ from builtins import bytes, range from past.builtins import basestring import os +import sys import logging import logging.config import atexit @@ -655,11 +656,16 @@ class Server(object): if not isinstance(trusted_downstream, list): self._logger.warn("server.reverseProxy.trustedDownstream is not a list, skipping") trusted_downstreams = [] - self._server = util.tornado.CustomHTTPServer(self._tornado_app, - max_body_sizes=max_body_sizes, - default_max_body_size=self._settings.getInt(["server", "maxSize"]), - xheaders=True, - trusted_downstream=trusted_downstream) + + server_kwargs = dict(max_body_sizes=max_body_sizes, + default_max_body_size=self._settings.getInt(["server", "maxSize"]), + xheaders=True, + trusted_downstream=trusted_downstream) + if sys.platform == "win32": + # set 10min idle timeout under windows to hopefully make #2916 less likely + server_kwargs.update(dict(idle_connection_timeout=600)) + + self._server = util.tornado.CustomHTTPServer(self._tornado_app, **server_kwargs) self._server.listen(self._port, address=self._host if self._host != "::" else None) # special case - tornado # only listens on v4 & v6 # if we use None as address From 5760b4b264637d33c3d036d889425c31e38e40a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 13 Dec 2018 13:13:02 +0100 Subject: [PATCH 05/12] tracking: check enabled state before preparing payload Otherwise if tracking is disabled we still do the work and then throw it away, which is kinda stupid. Also fixes potential issues with using things like the unique_id when it hasn't in fact been set due to disabled tracking. --- src/octoprint/plugins/tracking/__init__.py | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index 46c6978e4..8691bfb30 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -161,9 +161,15 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, self._settings.save() def _track_ping(self): + if not self._settings.get_boolean([b"enabled"]): + return + self._track("ping") def _track_startup(self): + if not self._settings.get_boolean([b"enabled"]): + return + if not self._settings.get_boolean(["events", "startup"]): return @@ -184,12 +190,18 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, self._track("startup", **payload) def _track_shutdown(self): + if not self._settings.get_boolean([b"enabled"]): + return + if not self._settings.get_boolean(["events", "startup"]): return self._track("shutdown") def _track_plugin_event(self, event, payload): + if not self._settings.get_boolean([b"enabled"]): + return + if not self._settings.get_boolean(["events", "plugin"]): return @@ -203,6 +215,9 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, self._track("disable_plugin", plugin=payload.get(b"id"), plugin_version=payload.get(b"version")) def _track_update_event(self, event, payload): + if not self._settings.get_boolean([b"enabled"]): + return + if not self._settings.get_boolean(["events", "update"]): return @@ -212,6 +227,9 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, self._track("update_failed", target=payload.get("target"), from_version=payload.get("from_version"), to_version=payload.get("to_version")) def _track_throttle_event(self, event, payload): + if not self._settings.get_boolean([b"enabled"]): + return + if not self._settings.get_boolean(["events", "throttled"]): return @@ -232,6 +250,9 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, self._track(track_event, **args) def _track_commerror_event(self, event, payload): + if not self._settings.get_boolean([b"enabled"]): + return + if not self._settings.get_boolean(["events", "commerror"]): return @@ -255,6 +276,9 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, self._track(track_event, **args) def _track_printjob_event(self, event, payload): + if not self._settings.get_boolean([b"enabled"]): + return + if not self._settings.get_boolean(["events", "printjob"]): return @@ -304,6 +328,9 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, self._track(track_event, **args) def _track_printer_event(self, event, payload): + if not self._settings.get_boolean([b"enabled"]): + return + if not self._settings.get_boolean(["events", "printer"]): return From f6dd13af7af135d1ff97fe7d576f8754ebcadd80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 13 Dec 2018 15:24:24 +0100 Subject: [PATCH 06/12] tracking: add printer safety warnings to tracking We want to get an idea how many people are running unsafe firmware. --- .../plugins/printer_safety_check/__init__.py | 29 +++++++++++-------- src/octoprint/plugins/tracking/__init__.py | 14 +++++++++ .../templates/tracking_settings.jinja2 | 3 ++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/octoprint/plugins/printer_safety_check/__init__.py b/src/octoprint/plugins/printer_safety_check/__init__.py index 6970a9b16..01b118ced 100644 --- a/src/octoprint/plugins/printer_safety_check/__init__.py +++ b/src/octoprint/plugins/printer_safety_check/__init__.py @@ -25,35 +25,35 @@ Learn more at https://faq.octoprint.org/warning-{warning_type} """ # Anet A8 -ANETA8_M115_TEST = lambda name, data: name and name.lower().startswith("anet_a8_") +ANETA8_M115_TEST = ("aneta8", lambda name, data: name and name.lower().startswith("anet_a8_")) # Anycubic MEGA ANYCUBIC_AUTHOR1 = "| Author: (Jolly, xxxxxxxx.CO.)".lower() ANYCUBIC_AUTHOR2 = "| Author: (**Jolly, xxxxxxxx.CO.**)".lower() -ANYCUBIC_RECEIVED_TEST = lambda line: line and (ANYCUBIC_AUTHOR1 in line.lower() or ANYCUBIC_AUTHOR2 in line.lower()) +ANYCUBIC_RECEIVED_TEST = ("anycubic", lambda line: line and (ANYCUBIC_AUTHOR1 in line.lower() or ANYCUBIC_AUTHOR2 in line.lower())) # Creality CR-10s CR10S_AUTHOR = " | Author: (CR-10Slanguage)".lower() -CR10S_RECEIVED_TEST = lambda line: line and CR10S_AUTHOR in line.lower() +CR10S_RECEIVED_TEST = ("cr10s", lambda line: line and CR10S_AUTHOR in line.lower()) # Creality Ender 3 ENDER3_AUTHOR = " | Author: (Ender3)".lower() -ENDER3_RECEIVED_TEST = lambda line: line and ENDER3_AUTHOR in line.lower() +ENDER3_RECEIVED_TEST = ("ender3", lambda line: line and ENDER3_AUTHOR in line.lower()) # iMe on Micro3D -IME_M115_TEST = lambda name, data: name and name.lower().startswith("ime") +IME_M115_TEST = ("ime", lambda name, data: name and name.lower().startswith("ime")) # Malyan M200 aka Monoprice Select Mini, versions less than 4.0 -MALYANM200_M115_TEST = lambda name, data: name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" and get_comparable_version(data.get("VER", "0")) < get_comparable_version("4.0") +MALYANM200_M115_TEST = ("malyan_m200", lambda name, data: name and name.lower().startswith("malyan") and data.get("MODEL") == "M200" and get_comparable_version(data.get("VER", "0")) < get_comparable_version("4.0")) # Stock Micro3D -MICRO3D_M115_TEST = lambda name, data: name and name.lower().startswith("micro3d") +MICRO3D_M115_TEST = ("micro3d", lambda name, data: name and name.lower().startswith("micro3d")) # Any Repetier versions < 0.92 -REPETIER_BEFORE_092_M115_TEST = lambda name, data: name and name.lower().startswith("repetier") and extract_repetier_version(name) is not None and extract_repetier_version(name) < get_comparable_version("0.92") +REPETIER_BEFORE_092_M115_TEST = ("repetier_before_092", lambda name, data: name and name.lower().startswith("repetier") and extract_repetier_version(name) is not None and extract_repetier_version(name) < get_comparable_version("0.92")) # THERMAL_PROTECTION capability reported as disabled -THERMAL_PROTECTION_CAP_TEST = lambda cap, enabled: cap == "THERMAL_PROTECTION" and not enabled +THERMAL_PROTECTION_CAP_TEST = ("capability", lambda cap, enabled: cap == "THERMAL_PROTECTION" and not enabled) SAFETY_CHECKS = { "firmware-unsafe": dict(m115=(ANETA8_M115_TEST, IME_M115_TEST, MALYANM200_M115_TEST, MICRO3D_M115_TEST, @@ -147,9 +147,14 @@ class PrinterSafetyCheckPlugin(octoprint.plugin.AssetPlugin, if not checks or not message: continue - if any(x(*args, **kwargs) for x in checks): - self._register_warning(warning_type, message) - changes = True + for check_name, check in checks: + if check(*args, **kwargs): + self._register_warning(warning_type, message) + self._event_bus.fire("plugin_printer_safety_check_warning", dict(check_type=check_type, + check_name=check_name, + warning_type=warning_type)) + changes = True + break if changes: self._ping_clients() diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index 8691bfb30..cdae60ce7 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -64,6 +64,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, plugin=True, update=True, printer=True, + printer_safety_check=True, throttled=True)) def get_settings_restricted_paths(self): @@ -116,6 +117,8 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, elif event in ("plugin_pi_support_throttle_state",): self._throttle_state = payload self._track_throttle_event(event, payload) + elif event in ("plugin_printer_safety_check_warning",): + self._track_printer_safety_event(event, payload) elif event in (Events.PRINT_STARTED, Events.PRINT_DONE, Events.PRINT_FAILED, Events.PRINT_CANCELLED): self._track_printjob_event(event, payload) elif event in (Events.ERROR,): @@ -341,6 +344,17 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, args["printer_baudrate"] = self._printer_connection_parameters["baudrate"] self._track("printer_connected", **args) + def _track_printer_safety_event(self, event, payload): + if not self._settings.get_boolean([b"enabled"]): + return + + if not self._settings.get_boolean(["events", "printer_safety_check"]): + 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")) + def _track(self, event, **kwargs): if not self._settings.get_boolean([b"enabled"]): return diff --git a/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 b/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 index 292a898bd..570038309 100644 --- a/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 +++ b/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 @@ -28,6 +28,9 @@ + From bf5bc14c8722a4e712cec0dfa2531a5005ed8650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 13 Dec 2018 16:29:22 +0100 Subject: [PATCH 07/12] backup: fix needed space calculation It wasn't taking excludes into account. Now its calculation mirrors the zip file creation. --- src/octoprint/plugins/backup/__init__.py | 34 +++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/octoprint/plugins/backup/__init__.py b/src/octoprint/plugins/backup/__init__.py index b00f5faf2..1d36918d1 100644 --- a/src/octoprint/plugins/backup/__init__.py +++ b/src/octoprint/plugins/backup/__init__.py @@ -514,11 +514,17 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, thread.start() @classmethod - def _get_disk_size(cls, path): + def _get_disk_size(cls, path, ignored=None): + if ignored is None: + ignored = [] + + if path in ignored: + return 0 + total = 0 for entry in scandir(path): if entry.is_dir(): - total += cls._get_disk_size(entry.path) + total += cls._get_disk_size(entry.path, ignored=ignored) elif entry.is_file(): total += entry.stat().st_size return total @@ -595,6 +601,8 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, on_backup_start=None, on_backup_done=None, on_backup_error=None): + exclude_by_default = ("generated", "logs", "watched",) + try: if exclude is None: exclude = [] @@ -605,14 +613,23 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, temporary_path = os.path.join(datafolder, ".{}".format(name)) final_path = os.path.join(datafolder, name) - size = cls._get_disk_size(basedir) - if not cls._free_space(os.path.dirname(temporary_path), size): - raise InsufficientSpace() - own_folder = datafolder defaults = [os.path.join(basedir, "config.yaml"),] + \ [os.path.join(basedir, folder) for folder in default_settings["folder"].keys()] + # check how much many bytes we are about to backup + size = os.stat(configfile).st_size + for folder in default_settings["folder"].keys(): + if folder in exclude or folder in exclude_by_default: + continue + size += cls._get_disk_size(settings.global_get_basefolder(folder), + ignored=[own_folder,]) + size += cls._get_disk_size(basedir, ignored=defaults + [own_folder,]) + + # since we can't know the compression ratio beforehand, we assume we need the same amount of space + if not cls._free_space(os.path.dirname(temporary_path), size): + raise InsufficientSpace() + compression = zipfile.ZIP_DEFLATED if zlib else zipfile.ZIP_STORED if callable(on_backup_start): @@ -642,10 +659,7 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin, # backup configured folder paths for folder in default_settings["folder"].keys(): - if folder in exclude: - continue - - if folder in ("generated", "logs", "watched",): + if folder in exclude or folder in exclude_by_default: continue add_to_zip(settings.global_get_basefolder(folder), From e30f1b9f82ceaf103bda8eb9ba7067652d092d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 17 Dec 2018 12:29:19 +0100 Subject: [PATCH 08/12] Add "::1/128" to localNetworks for auto login See BillyBlaze/OctoPrint-TouchUI#266 --- src/octoprint/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 19a599e49..79a5d910b 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -324,7 +324,7 @@ default_settings = { "userManager": "octoprint.users.FilebasedUserManager", "userfile": None, "autologinLocal": False, - "localNetworks": ["127.0.0.0/8"], + "localNetworks": ["127.0.0.0/8", "::1/128"], "autologinAs": None, "trustBasicAuthentication": False, "checkBasicAuthenticationPassword": True From 99225244f1cccf8b5472f42eeb4f6b0542f91933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 17 Dec 2018 14:20:42 +0100 Subject: [PATCH 09/12] Add full version string to API --- docs/api/version.rst | 6 ++++-- src/octoprint/server/api/__init__.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/api/version.rst b/docs/api/version.rst index 47b0c56e0..9716139c4 100644 --- a/docs/api/version.rst +++ b/docs/api/version.rst @@ -7,7 +7,8 @@ Version information .. http:get:: /api/version Retrieve information regarding server and API version. Returns a JSON object with two keys, ``api`` containing - the API version, ``server`` containing the server version. + the API version, ``server`` containing the server version, ``text`` containing the server version including + the prefix ``OctoPrint `` (to determine that this is indeed a genuine OctoPrint instance). **Example Request** @@ -26,7 +27,8 @@ Version information { "api": "0.1", - "server": "1.1.0" + "server": "1.3.10", + "text": "OctoPrint 1.3.10" } :statuscode 200: No error diff --git a/src/octoprint/server/api/__init__.py b/src/octoprint/server/api/__init__.py index ed4cc7cee..c084dc18e 100644 --- a/src/octoprint/server/api/__init__.py +++ b/src/octoprint/server/api/__init__.py @@ -177,7 +177,8 @@ def apiPrinterState(): def apiVersion(): return jsonify({ "server": octoprint.server.VERSION, - "api": VERSION + "api": VERSION, + "text": "OctoPrint {}".format(octoprint.server.DISPLAY_VERSION) }) From a23d92158b485de5ef4c4531a041c6ca23ffdee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 17 Dec 2018 17:47:22 +0100 Subject: [PATCH 10/12] tracking: Track uptime of OctoPrint in ping event That will give us an idea if the current hypothesis that quite a number of people are shutting down their instance at night is correct or not, which in turn will inform future startup optimizations. --- src/octoprint/plugins/tracking/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index cdae60ce7..cf1b79ab5 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -21,7 +21,7 @@ except ImportError: # noinspection PyCompatibility import concurrent.futures -from octoprint.util import RepeatedTimer +from octoprint.util import RepeatedTimer, monotonic_time from octoprint.util.version import get_octoprint_version_string from octoprint.events import Events @@ -48,6 +48,8 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, self._record_next_firmware_info = False + self._startup_time = monotonic_time() + def initialize(self): self._init_tracking() @@ -91,7 +93,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, def on_after_startup(self): ping = self._settings.get_int(["ping"]) if ping: - self._ping_worker = RepeatedTimer(ping, self._track_ping) + self._ping_worker = RepeatedTimer(ping, self._track_ping, run_first=True) self._ping_worker.start() # cautiously look for the get_throttled helper from pi_support @@ -167,7 +169,8 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, if not self._settings.get_boolean([b"enabled"]): return - self._track("ping") + uptime = int(monotonic_time() - self._startup_time) + self._track("ping", octoprint_uptime=uptime) def _track_startup(self): if not self._settings.get_boolean([b"enabled"]): From 52c7321c78c8a81b6b557d67fe5af44b8b32df4c Mon Sep 17 00:00:00 2001 From: Connor Wolf Date: Sun, 11 Nov 2018 07:32:48 +0100 Subject: [PATCH 11/12] Handle unsupported version at runtime. If you have an ancient setuptools, 4a36ddb3aa77b8d1b1a64c197607fa652705856c won't successfully prevent installing. These changes will at least give a sane error, rather then just barfing on random syntax errors due to the `unicode` type not being present in py3k. Cherry picked from 2f20f2d --- src/octoprint/__main__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/octoprint/__main__.py b/src/octoprint/__main__.py index 3dd81998d..9b1a759fc 100644 --- a/src/octoprint/__main__.py +++ b/src/octoprint/__main__.py @@ -2,6 +2,10 @@ # coding=utf-8 from __future__ import absolute_import, division, print_function +import sys +if sys.version_info[0] >= 3: + raise Exception("Octoprint does not support Python 3") + if __name__ == "__main__": import octoprint octoprint.main() From 4e9437114b0070bbf5415dda7c532098f336eab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 19 Dec 2018 13:35:18 +0100 Subject: [PATCH 12/12] Change wording & exception type --- src/octoprint/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/__main__.py b/src/octoprint/__main__.py index 9b1a759fc..b794f4798 100644 --- a/src/octoprint/__main__.py +++ b/src/octoprint/__main__.py @@ -4,7 +4,7 @@ from __future__ import absolute_import, division, print_function import sys if sys.version_info[0] >= 3: - raise Exception("Octoprint does not support Python 3") + raise RuntimeError("Sorry, OctoPrint does not yet support Python 3") if __name__ == "__main__": import octoprint