From 2bd8aa00f3d8c3eb40edda3f184abffa41b48c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 20 Jun 2018 20:03:19 +0200 Subject: [PATCH 01/20] Add build status and IRC badge --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index b44dfe19e..f957471b2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # OctoPrint [![GitHub version](https://badge.fury.io/gh/foosel%2FOctoPrint.svg)](https://badge.fury.io/gh/foosel%2FOctoPrint) +[![Travis build status](https://img.shields.io/travis/foosel/OctoPrint.svg)](https://travis-ci.org/foosel/OctoPrint) +[![IRC](https://img.shields.io/badge/freenode-%23octoprint-blue.svg)](https://chat.octoprint.org) OctoPrint provides a snappy web interface for controlling consumer 3D printers. It is Free Software and released under the [GNU Affero General Public License V3](http://www.gnu.org/licenses/agpl.html). @@ -9,6 +11,8 @@ Its website can be found at [octoprint.org](https://octoprint.org/?utm_source=gi The community forum is available at [discourse.octoprint.org](https://discourse.octoprint.org/?utm_source=github&utm_medium=readme). +The official IRC channel is [#octoprint on freenode](https://chat.octoprint.org). Its logs can be found [here](https://freenode.logbot.info/octoprint). + The FAQ can be accessed by following [faq.octoprint.org](https://faq.octoprint.org/?utm_source=github&utm_medium=readme). The documentation is located at [docs.octoprint.org](http://docs.octoprint.org). From 887304fe18e45fbab4b0f93fd6546c39b8a73112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 20 Jun 2018 23:01:23 +0200 Subject: [PATCH 02/20] Some more badges --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f957471b2..fc9f7e0f1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ # OctoPrint -[![GitHub version](https://badge.fury.io/gh/foosel%2FOctoPrint.svg)](https://badge.fury.io/gh/foosel%2FOctoPrint) + +![GitHub release](https://img.shields.io/github/release/foosel/OctoPrint.svg?colorB=brightgreen) [![Travis build status](https://img.shields.io/travis/foosel/OctoPrint.svg)](https://travis-ci.org/foosel/OctoPrint) -[![IRC](https://img.shields.io/badge/freenode-%23octoprint-blue.svg)](https://chat.octoprint.org) +[![Discourse topics](https://img.shields.io/discourse/https/discourse.octoprint.org/users.svg)](https://discourse.octoprint.org) +[![IRC](https://img.shields.io/badge/chat-on%20irc-brightgreen.svg)](https://chat.octoprint.org) +[![Twitter Follow](https://img.shields.io/twitter/follow/OctoPrint3d.svg?style=social&label=Follow)](https://twitter.com/OctoPrint3d) + OctoPrint provides a snappy web interface for controlling consumer 3D printers. It is Free Software and released under the [GNU Affero General Public License V3](http://www.gnu.org/licenses/agpl.html). From 5a60af9d137fb1c0750ca9408da7fa1366204793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 19 Jun 2018 11:51:17 +0200 Subject: [PATCH 03/20] Improve SD print detection --- src/octoprint/printer/standard.py | 27 +++++++------ src/octoprint/util/comm.py | 66 +++++++++++-------------------- 2 files changed, 37 insertions(+), 56 deletions(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index c1355bbad..2315969a6 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -134,7 +134,17 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): eventManager().subscribe(Events.METADATA_ANALYSIS_FINISHED, self._on_event_MetadataAnalysisFinished) eventManager().subscribe(Events.METADATA_STATISTICS_UPDATED, self._on_event_MetadataStatisticsUpdated) - def _create_estimator(self, job_type): + def _create_estimator(self, job_type=None): + if job_type is None: + with self._selectedFileMutex: + if self._selectedFile is None: + return + + if self._selectedFile["sd"]: + job_type = "sdcard" + else: + job_type = "local" + self._estimator = self._estimator_factory(job_type) #~~ handling of PrinterCallbacks @@ -490,16 +500,6 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): if self._comm is None or not self._comm.isOperational() or self._comm.isPrinting(): return - with self._selectedFileMutex: - if self._selectedFile is None: - return - - if self._selectedFile["sd"]: - job_type = "sdcard" - else: - job_type = "local" - - self._create_estimator(job_type) self._fileManager.delete_recovery_data() self._lastProgressReport = None @@ -749,7 +749,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): cleanedPrintTime = self._comm.getCleanedPrintTime() printTimeLeft = printTimeLeftOrigin = None - if progress is not None: + if progress is not None and self._estimator is not None: progress_int = int(progress * 100) if self._lastProgressReport != progress_int: self._lastProgressReport = progress_int @@ -1034,11 +1034,14 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._setJobData(full_path, size, sd, user=user) self._stateMonitor.set_state(self._dict(text=self.get_state_string(), flags=self._getStateFlags())) + self._create_estimator() + if self._printAfterSelect: self._printAfterSelect = False self.start_print(pos=self._posAfterSelect, user=user) def on_comm_print_job_started(self, suppress_script=False): + self._stateMonitor.trigger_progress_update() payload = self._payload_for_print_job_event() if payload: eventManager().fire(Events.PRINT_STARTED, payload) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index e595d5746..7d1a90784 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -1011,11 +1011,6 @@ class MachineCom(object): self._callback.on_comm_print_job_started() if self.isSdFileSelected(): - interval = self._timeout_intervals.get("sdStatus", 1.0) - if interval <= 0: - interval = 1.0 - self._sd_status_timer = RepeatedTimer(interval, self._poll_sd_status, run_first=True) - if not external_sd: # make sure to ignore the "file selected" later on, otherwise we'll reset our progress data self._ignore_select = True @@ -1031,15 +1026,9 @@ class MachineCom(object): else: self._currentFile.pos = 0 - def start_polling(): - self._sd_status_timer.start() - self.sendCommand("M24", - on_sent=start_polling, part_of_job=True, tags=tags | {"trigger:comm.start_print",}) - else: - self._sd_status_timer.start() else: if pos is not None and isinstance(pos, int) and pos > 0: self._currentFile.seek(pos) @@ -1154,6 +1143,7 @@ class MachineCom(object): elif check_timer: return + self._currentFile.done = True self._recordFilePosition() self._callback.on_comm_print_job_cancelled() @@ -1204,11 +1194,6 @@ class MachineCom(object): self.sendCommand("M25", part_of_job=True, tags=tags | {"trigger:comm.cancel",}) # pause print self.sendCommand("M27", part_of_job=True, tags=tags | {"trigger:comm.cancel",}) # get current byte position in file self.sendCommand("M26 S0", part_of_job=True, tags=tags | {"trigger:comm.cancel",}) # reset position in file to byte 0 - if self._sd_status_timer is not None: - try: - self._sd_status_timer.cancel() - except: - pass if self._log_position_on_cancel and not disable_log_position: self.sendCommand("M400", @@ -1884,17 +1869,19 @@ class MachineCom(object): total = int(match.group("total")) if self.isSdPrinting() and current == total == 0: - # apparently not SD printing - newer Marlin reports it like that for some reason + # apparently not SD printing - some Marlin versions report it like that for some reason self.cancelPrint(external_sd=True) elif self.isSdFileSelected(): - if not self.isSdPrinting() and current != total: + if not self.isSdPrinting() and current != total and current > 0: self.startPrint(external_sd=True) self._currentFile.pos = current if self._currentFile.size == 0: self._currentFile.size = total - self._callback.on_comm_progress() + + if not self._currentFile.done: + self._callback.on_comm_progress() elif 'Not SD printing' in line and self.isSdFileSelected() and self.isPrinting() and not self.isFinishing(): # something went wrong, printer is reporting that we actually are not printing right now... @@ -1910,9 +1897,7 @@ class MachineCom(object): size = 0 user = None - expected = False if self._sdFileToSelect: - expected = True name = self._sdFileToSelect user = self._sdFileToSelectUser @@ -1920,12 +1905,6 @@ class MachineCom(object): self._sdFileToSelectUser = None self._currentFile = PrintingSdFileInformation(name, size, user=user) - - if not expected: - # It doesn't look like we expected this, so it might be that someone just started a print - # job from SD via the printer's controller. Let's query the printing status and see if that's - # indeed the case and if so switch states accordingly - self.sendCommand("M27", tags={"trigger:unexpected_file_open"}) elif 'File selected' in line: if self._ignore_select: self._ignore_select = False @@ -1944,12 +1923,6 @@ class MachineCom(object): self._currentFile.done = True self._currentFile.pos = 0 - if self._sd_status_timer is not None: - try: - self._sd_status_timer.cancel() - except: - pass - self.sendCommand("M400", part_of_job=True) self._callback.on_comm_print_job_done() def finalize(): @@ -2266,7 +2239,7 @@ class MachineCom(object): command or heating, no poll will be done. """ - if self.isOperational() and not self._sdstatus_autoreporting and not self._connection_closing and self.isSdPrinting() and not self._long_running_command and not self._dwelling_until and not self._heating: + if self.isOperational() and not self._sdstatus_autoreporting and not self._connection_closing and self.isSdFileSelected() and not self._long_running_command and not self._dwelling_until and not self._heating: self.sendCommand("M27", cmd_type="sd_status_poll", tags={"trigger:comm.poll_sd_status"}) def _set_autoreport_temperature_interval(self, interval=None): @@ -2295,9 +2268,12 @@ class MachineCom(object): def _onConnected(self): self._serial.timeout = settings().getFloat(["serial", "timeout", "communication"]) - self._temperature_timer = RepeatedTimer(self._getTemperatureTimerInterval, self._poll_temperature, run_first=True) + self._temperature_timer = RepeatedTimer(self._get_temperature_timer_interval, self._poll_temperature, run_first=True) self._temperature_timer.start() + self._sd_status_timer = RepeatedTimer(self._get_sd_status_timer_interval, self._poll_sd_status, run_first=True) + self._sd_status_timer.start() + self._changeState(self.STATE_OPERATIONAL) self.resetLineNumbers(tags={"trigger:comm.on_connected",}) @@ -2334,7 +2310,7 @@ class MachineCom(object): if self._busy_protocol_detected: self._set_busy_protocol_interval() - def _getTemperatureTimerInterval(self): + def _get_temperature_timer_interval(self): busy_default = 4.0 target_default = 2.0 @@ -2358,6 +2334,12 @@ class MachineCom(object): return get("temperature", busy_default) + def _get_sd_status_timer_interval(self): + interval = self._timeout_intervals.get("sdStatus", 1.0) + if interval <= 0: + interval = 1.0 + return interval + def _send_from_command_queue(self): # We loop here to make sure that if we do NOT send the first command # from the queue, we'll send the second (if there is one). We do not @@ -3635,6 +3617,10 @@ class PrintingFileInformation(object): def done(self): return self._done + @done.setter + def done(self, value): + self._done = value + class PrintingSdFileInformation(PrintingFileInformation): """ Encapsulates information regarding an ongoing print from SD. @@ -3649,14 +3635,6 @@ class PrintingSdFileInformation(PrintingFileInformation): def getFileLocation(self): return FileDestinations.SDCARD - @property - def done(self): - return self._done - - @done.setter - def done(self, value): - self._done = value - @property def size(self): return self._size From c4dc7d0f55fc119fc285138371008bb1a061569d Mon Sep 17 00:00:00 2001 From: Eyal Date: Sun, 24 Jun 2018 15:04:38 +0300 Subject: [PATCH 04/20] Fix comment in types.py to match the code The comment says that the key should be `_analysis` but in the code it is `analysis`: https://github.com/foosel/OctoPrint/blob/master/src/octoprint/slicing/__init__.py#L312 This fixes the comment but leaves the code unchanged. --- src/octoprint/plugin/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index 9b3fc46f2..1fe0f8046 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -1984,7 +1984,7 @@ class SlicerPlugin(OctoPrintPlugin): For jobs that finished successfully, ``result`` should be a :class:`dict` containing additional information about the slicing job under the following keys: - _analysis + analysis Analysis result of the generated machine code as returned by the slicer itself. This should match the data structure described for the analysis queue of the matching machine code format, e.g. :class:`~octoprint.filemanager.analysis.GcodeAnalysisQueue` for GCODE files. From 1a9b6c01a6f3a288f142194c3664f8b7bf907820 Mon Sep 17 00:00:00 2001 From: Eyal Date: Sun, 24 Jun 2018 15:45:29 +0300 Subject: [PATCH 05/20] estimatedPrintTime is in seconds, not minutes The documentation says that the estimated print time should be given in minute. But in practice, when I give it in minutes, the GUI shows an error factor of 60. By supplying it in seconds, the correct value is shown. So it should probably actually be "in seconds" --- src/octoprint/filemanager/analysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/filemanager/analysis.py b/src/octoprint/filemanager/analysis.py index 11c5aac29..e8bc55218 100644 --- a/src/octoprint/filemanager/analysis.py +++ b/src/octoprint/filemanager/analysis.py @@ -299,7 +299,7 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue): - * **Key** * **Description** - * ``estimatedPrintTime`` - * Estimated time the file take to print, in minutes + * Estimated time the file take to print, in seconds - * ``filament`` * Substructure describing estimated filament usage. Keys are ``tool0`` for the first extruder, ``tool1`` for the second and so on. For each tool extruded length and volume (based on diameter) are provided. From a97b8c2fd993caea2711e0a8842e354bd078a1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 25 Jun 2018 11:20:31 +0200 Subject: [PATCH 06/20] Sanity check disabled plugin list just in case See https://github.com/foosel/OctoPrint/issues/2687#issuecomment-399797596 --- .../plugins/pluginmanager/__init__.py | 8 ++++-- src/octoprint/settings.py | 25 +++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 54ae3cb92..06d4cfe80 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -672,7 +672,9 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, self._console_logger.debug(u"{prefix} {line}".format(**locals())) def _mark_plugin_enabled(self, plugin, needs_restart=False): - disabled_list = list(self._settings.global_get(["plugins", "_disabled"])) + disabled_list = list(self._settings.global_get(["plugins", "_disabled"], + validator=lambda x: isinstance(x, list), + fallback=[])) if plugin.key in disabled_list: disabled_list.remove(plugin.key) self._settings.global_set(["plugins", "_disabled"], disabled_list) @@ -687,7 +689,9 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, self._pending_enable.add(plugin.key) def _mark_plugin_disabled(self, plugin, needs_restart=False): - disabled_list = list(self._settings.global_get(["plugins", "_disabled"])) + disabled_list = list(self._settings.global_get(["plugins", "_disabled"], + validator=lambda x: isinstance(x, list), + fallback=[])) if not plugin.key in disabled_list: disabled_list.append(plugin.key) self._settings.global_set(["plugins", "_disabled"], disabled_list) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 17ed611a3..d1f80d370 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -1424,17 +1424,22 @@ class Settings(object): #~~ getter def get(self, path, **kwargs): - error_on_path = kwargs.get("error_on_path", False) - new_kwargs = dict(kwargs) - if "error_on_path" in new_kwargs: - del new_kwargs["error_on_path"] + error_on_path = kwargs.pop("error_on_path", False) + validator = kwargs.pop("validator", None) + fallback = kwargs.pop("fallback", None) - try: - return self._get_value(path, **new_kwargs) - except NoSuchSettingsPath: - if error_on_path: - raise - return None + def process(): + try: + return self._get_value(path, **kwargs) + except NoSuchSettingsPath: + if error_on_path: + raise + return None + + result = process() + if callable(validator) and not validator(result): + result = fallback + return result def getInt(self, path, **kwargs): minimum = kwargs.pop("min", None) From f69718b060237970e2bedfc51aa33131673018e7 Mon Sep 17 00:00:00 2001 From: tedder Date: Sun, 24 Jun 2018 19:45:56 +0200 Subject: [PATCH 07/20] make favicon color match custom theme color With multiple octopis, the theme/header color is really nice for quickly distinguishing them. But it doesn't help with an ocean of open tabs. This does- simply carry the theme color onto the favicon. I could do this as a plugin and/or make it a configurable setting, but it's very small change that doesn't need that much overhead, and generally I have opinions about having a plethora of setting flags for nonfunctional things. Thanks to @jneilliii for [helping me through the viewmodels](https://discourse.octoprint.org/t/where-can-i-get-the-theme-color/2354/5). (cherry picked from commit e1089de) --- .../static/js/app/viewmodels/appearance.js | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/octoprint/static/js/app/viewmodels/appearance.js b/src/octoprint/static/js/app/viewmodels/appearance.js index 75c1c527a..0b5b3f18a 100644 --- a/src/octoprint/static/js/app/viewmodels/appearance.js +++ b/src/octoprint/static/js/app/viewmodels/appearance.js @@ -1,4 +1,49 @@ $(function() { + var save = []; + + // Using the theme color (for the top bar), also recolor the favicon tentacle. + function ThemeFavicon(colorname) { + save.colorName = colorname; + + // the following is from an Apache licensed snippet: + // http://blog.roomanna.com/09-24-2011/dynamically-coloring-a-favicon + var link = document.querySelector("link[rel~='icon']"); + if (!link) { + link = document.createElement("link"); + link.setAttribute("rel", "shortcut icon"); + document.head.appendChild(link); + } + + // try to get the best quality ico possible; prefer svg, the apple-touch pngs are more difficult, + // but all three of the others give a high-quality ico. + var faviconUrl = + // document.querySelector("link[rel~='apple-touch-icon'][sizes~='144x144']").href || + document.querySelector("link[rel~='mask-icon']").href || + link.href || + window.location.origin + "/favicon.ico"; + function onImageLoaded() { + var icosize = 256; // example was 16 + // svgs don't really have width + //var icosize = img.width; + var canvas = document.createElement("canvas"); + canvas.width = icosize; + canvas.height = icosize; + var context = canvas.getContext("2d"); + context.drawImage(img, 0, 0, icosize, icosize); + // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation + context.globalCompositeOperation = "source-in"; + //context.fillStyle = "#d00"; + context.fillStyle = save.colorName; + context.fillRect(0, 0, icosize, icosize/1); + context.fill(); + link.type = "image/x-icon"; + link.href = canvas.toDataURL(); + }; + var img = document.createElement("img"); + img.addEventListener("load", onImageLoaded); + img.src = faviconUrl; + } + function AppearanceViewModel(parameters) { var self = this; @@ -6,6 +51,8 @@ $(function() { self.color = parameters[0].appearance_color; self.colorTransparent = parameters[0].appearance_colorTransparent; + ThemeFavicon(self.name); + self.brand = ko.pureComputed(function() { if (self.name()) return self.name(); From 2a67772f4600afd89ccd86ae7828ec3e24e1e0b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 25 Jun 2018 12:39:31 +0200 Subject: [PATCH 08/20] Different base icon & setting (cherry picked from commit dc61b61) --- src/octoprint/server/api/settings.py | 2 + src/octoprint/settings.py | 1 + src/octoprint/static/img/mask-theme.svg | 30 ++++++ .../static/img/{favicon.svg => mask.svg} | 0 .../static/js/app/viewmodels/appearance.js | 97 +++++++++++++------ .../static/js/app/viewmodels/settings.js | 1 + .../dialogs/settings/appearance.jinja2 | 9 +- src/octoprint/templates/index.jinja2 | 3 +- 8 files changed, 112 insertions(+), 31 deletions(-) create mode 100644 src/octoprint/static/img/mask-theme.svg rename src/octoprint/static/img/{favicon.svg => mask.svg} (100%) diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 6cdcfe0be..96968ea1c 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -90,6 +90,7 @@ def getSettings(): "name": s.get(["appearance", "name"]), "color": s.get(["appearance", "color"]), "colorTransparent": s.getBoolean(["appearance", "colorTransparent"]), + "colorIcon": s.getBoolean(["appearance", "colorIcon"]), "defaultLanguage": s.get(["appearance", "defaultLanguage"]), "showFahrenheitAlso": s.getBoolean(["appearance", "showFahrenheitAlso"]) }, @@ -371,6 +372,7 @@ def _saveSettings(data): if "name" in data["appearance"]: s.set(["appearance", "name"], data["appearance"]["name"]) if "color" in data["appearance"]: s.set(["appearance", "color"], data["appearance"]["color"]) if "colorTransparent" in data["appearance"]: s.setBoolean(["appearance", "colorTransparent"], data["appearance"]["colorTransparent"]) + if "colorIcon" in data["appearance"]: s.setBoolean(["appearance", "colorIcon"], data["appearance"]["colorIcon"]) if "defaultLanguage" in data["appearance"]: s.set(["appearance", "defaultLanguage"], data["appearance"]["defaultLanguage"]) if "showFahrenheitAlso" in data["appearance"]: s.setBoolean(["appearance", "showFahrenheitAlso"], data["appearance"]["showFahrenheitAlso"]) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 17ed611a3..b017670d1 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -278,6 +278,7 @@ default_settings = { "name": "", "color": "default", "colorTransparent": False, + "colorIcon": True, "defaultLanguage": "_default", "showFahrenheitAlso": False, "components": { diff --git a/src/octoprint/static/img/mask-theme.svg b/src/octoprint/static/img/mask-theme.svg new file mode 100644 index 000000000..1d09f4d45 --- /dev/null +++ b/src/octoprint/static/img/mask-theme.svg @@ -0,0 +1,30 @@ + + + + +mask-theme + + + + + + + + + diff --git a/src/octoprint/static/img/favicon.svg b/src/octoprint/static/img/mask.svg similarity index 100% rename from src/octoprint/static/img/favicon.svg rename to src/octoprint/static/img/mask.svg diff --git a/src/octoprint/static/js/app/viewmodels/appearance.js b/src/octoprint/static/js/app/viewmodels/appearance.js index 0b5b3f18a..81282ba78 100644 --- a/src/octoprint/static/js/app/viewmodels/appearance.js +++ b/src/octoprint/static/js/app/viewmodels/appearance.js @@ -1,44 +1,73 @@ $(function() { - var save = []; + var save = {}; // Using the theme color (for the top bar), also recolor the favicon tentacle. - function ThemeFavicon(colorname) { + function themeFavicon(colorname) { save.colorName = colorname; // the following is from an Apache licensed snippet: // http://blog.roomanna.com/09-24-2011/dynamically-coloring-a-favicon - var link = document.querySelector("link[rel~='icon']"); + var link = document.querySelector("link[rel='shortcut icon']"); if (!link) { - link = document.createElement("link"); - link.setAttribute("rel", "shortcut icon"); - document.head.appendChild(link); + link = document.createElement("link"); + link.setAttribute("rel", "shortcut icon"); + document.head.appendChild(link); } // try to get the best quality ico possible; prefer svg, the apple-touch pngs are more difficult, // but all three of the others give a high-quality ico. - var faviconUrl = - // document.querySelector("link[rel~='apple-touch-icon'][sizes~='144x144']").href || - document.querySelector("link[rel~='mask-icon']").href || - link.href || - window.location.origin + "/favicon.ico"; + var faviconUrl = document.querySelector("link[rel~='mask-icon-theme']").href + || link.href + || window.location.origin + "/favicon.ico"; + function onImageLoaded() { - var icosize = 256; // example was 16 - // svgs don't really have width - //var icosize = img.width; - var canvas = document.createElement("canvas"); - canvas.width = icosize; - canvas.height = icosize; - var context = canvas.getContext("2d"); - context.drawImage(img, 0, 0, icosize, icosize); - // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation - context.globalCompositeOperation = "source-in"; - //context.fillStyle = "#d00"; - context.fillStyle = save.colorName; - context.fillRect(0, 0, icosize, icosize/1); - context.fill(); - link.type = "image/x-icon"; - link.href = canvas.toDataURL(); - }; + var icosize = 256; + + var canvas = document.createElement("canvas"); + canvas.width = icosize; + canvas.height = icosize; + + var context = canvas.getContext("2d"); + + function grayscale() { + var imageData = context.getImageData(0, 0, canvas.width, canvas.height), + pixels = imageData.data, + i, l, r, g, b, a, luma; + + for (i = 0, l = pixels.length; i < l; i += 4) { + a = pixels[i + 3]; + if (a === 0) { continue; } + + r = pixels[i]; + g = pixels[i + 1]; + b = pixels[i + 2]; + + luma = r * 0.2126 + g * 0.7152 + b * 0.0722; + + pixels[i] = pixels[i + 1] = pixels[i + 2] = luma; + } + + context.putImageData(imageData, 0, 0); + } + + function colorize(color, alpha) { + context.globalCompositeOperation = "source-atop"; + context.globalAlpha = alpha; + context.fillStyle = color; + context.fillRect(0, 0, canvas.width, canvas.height); + context.globalCompositeOperation = "source-over"; + context.globalAlpha = 1.0; + } + + context.drawImage(img, 0, 0, canvas.width, canvas.height); + if (save.colorName !== "default") { + grayscale(); + colorize(save.colorName, .3); + } + link.type = "image/x-icon"; + link.href = canvas.toDataURL(); + } + var img = document.createElement("img"); img.addEventListener("load", onImageLoaded); img.src = faviconUrl; @@ -50,8 +79,18 @@ $(function() { self.name = parameters[0].appearance_name; self.color = parameters[0].appearance_color; self.colorTransparent = parameters[0].appearance_colorTransparent; + self.colorIcon = parameters[0].appearance_colorIcon; - ThemeFavicon(self.name); + function updateIcon() { + if (self.colorIcon()) { + themeFavicon(self.color()); + } else { + themeFavicon("default"); + } + } + self.color.subscribe(updateIcon); + self.colorIcon.subscribe(updateIcon); + updateIcon(); self.brand = ko.pureComputed(function() { if (self.name()) diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 9f45e6174..7118bbabd 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -111,6 +111,7 @@ $(function() { self.appearance_name = ko.observable(undefined); self.appearance_color = ko.observable(undefined); self.appearance_colorTransparent = ko.observable(); + self.appearance_colorIcon = ko.observable(); self.appearance_defaultLanguage = ko.observable(); self.appearance_showFahrenheitAlso = ko.observable(undefined); diff --git a/src/octoprint/templates/dialogs/settings/appearance.jinja2 b/src/octoprint/templates/dialogs/settings/appearance.jinja2 index b50a93735..b20a91573 100644 --- a/src/octoprint/templates/dialogs/settings/appearance.jinja2 +++ b/src/octoprint/templates/dialogs/settings/appearance.jinja2 @@ -15,7 +15,14 @@
+
+
+
+
+
diff --git a/src/octoprint/templates/index.jinja2 b/src/octoprint/templates/index.jinja2 index d25076b5e..d18a41fca 100644 --- a/src/octoprint/templates/index.jinja2 +++ b/src/octoprint/templates/index.jinja2 @@ -4,7 +4,8 @@ OctoPrint - + + From 13ab34a5c8d3ee3ea54a8a232b9c0f2ef80566cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 25 Jun 2018 18:53:42 +0200 Subject: [PATCH 09/20] Better API key check --- src/octoprint/server/util/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/server/util/__init__.py b/src/octoprint/server/util/__init__.py index 5770bc0c9..c2df7ea30 100644 --- a/src/octoprint/server/util/__init__.py +++ b/src/octoprint/server/util/__init__.py @@ -43,7 +43,7 @@ def enforceApiKeyRequestHandler(): apikey = get_api_key(_flask.request) - if apikey is None: + if not apikey: return _flask.make_response("No API key provided", 403) if apikey != octoprint.server.UI_API_KEY and not settings().getBoolean(["api", "enabled"]): From abf4f90f0e5a1bf8b17856a291b8c9f09db1411e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 26 Jun 2018 17:32:58 +0200 Subject: [PATCH 10/20] Fix an issue with collision free sd name detection --- src/octoprint/util/__init__.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index 29f6a1bbb..07a44eb81 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -339,15 +339,15 @@ def find_collision_free_name(filename, extension, existing_filenames, max_power= u'test_123.gco' >>> find_collision_free_name("test1234", "g o", []) u'test1234.g_o' - >>> find_collision_free_name("test12345", "gco", ["test12~1.gco"]) + >>> find_collision_free_name("test12345", "gco", ["/test12~1.gco"]) u'test12~2.gco' - >>> many_files = ["test12~{}.gco".format(x) for x in range(10)[1:]] + >>> many_files = ["/test12~{}.gco".format(x) for x in range(10)[1:]] >>> find_collision_free_name("test12345", "gco", many_files) u'test1~10.gco' - >>> many_more_files = many_files + ["test1~{}.gco".format(x) for x in range(10, 99)] + >>> many_more_files = many_files + ["/test1~{}.gco".format(x) for x in range(10, 99)] >>> find_collision_free_name("test12345", "gco", many_more_files) u'test1~99.gco' - >>> many_more_files_plus_one = many_more_files + ["test1~99.gco"] + >>> many_more_files_plus_one = many_more_files + ["/test1~99.gco"] >>> find_collision_free_name("test12345", "gco", many_more_files_plus_one) Traceback (most recent call last): ... @@ -357,13 +357,15 @@ def find_collision_free_name(filename, extension, existing_filenames, max_power= """ - if not isinstance(filename, unicode): - filename = unicode(filename) - if not isinstance(extension, unicode): - extension = unicode(extension) + filename = to_unicode(filename) + extension = to_unicode(extension) + + if filename.startswith(u"/"): + filename = filename[1:] + existing_filenames = [to_unicode(x[1:] if x.startswith("/") else x) for x in existing_filenames] def make_valid(text): - return re.sub(r"\s+", "_", text.translate({ord(i):None for i in ".\"/\\[]:;=,"})).lower() + return re.sub(u"\s+", u"_", text.translate({ord(i):None for i in ".\"/\\[]:;=,"})).lower() filename = make_valid(filename) extension = make_valid(extension) From d9c6cca370b88927fb85e21452bc0bf3e0231e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 13 Nov 2017 18:25:47 +0100 Subject: [PATCH 11/20] Anonymous usage tracking --- src/octoprint/cli/server.py | 1 - .../plugins/pluginmanager/__init__.py | 17 +- src/octoprint/plugins/tracking/__init__.py | 186 ++++++++++++++++++ .../plugins/tracking/static/js/tracking.js | 85 ++++++++ .../templates/tracking_settings.jinja2 | 7 + .../tracking/templates/tracking_wizard.jinja2 | 19 ++ 6 files changed, 313 insertions(+), 2 deletions(-) create mode 100644 src/octoprint/plugins/tracking/__init__.py create mode 100644 src/octoprint/plugins/tracking/static/js/tracking.js create mode 100644 src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 create mode 100644 src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 diff --git a/src/octoprint/cli/server.py b/src/octoprint/cli/server.py index 5fed71e5a..dc9ff6cbf 100644 --- a/src/octoprint/cli/server.py +++ b/src/octoprint/cli/server.py @@ -82,7 +82,6 @@ def run_server(basedir, configfile, host, port, debug, allow_root, logging_confi ignore_blacklist=ignore_blacklist, after_safe_mode=log_startup, after_environment_detector=log_register_rollover) - settings, _, safe_mode, event_manager, connectivity_checker, plugin_manager, environment_detector = components except FatalStartupError as e: diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 54ae3cb92..835dcba5a 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -459,6 +459,11 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, self._plugin_manager.log_all_plugins() self._logger.info("The plugin was installed successfully: {}, version {}".format(new_plugin.name, new_plugin.version)) + self._event_bus.fire("plugin_pluginmanager_installplugin", dict(id=new_plugin.key, + version=new_plugin.version, + source=source, + source_type=source_type)) + result = dict(result=True, source=source, source_type=source_type, @@ -549,6 +554,9 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, self._plugin_manager.reload_plugins() + self._event_bus.fire("plugin_pluginmanager_uninstallplugin", dict(id=plugin.key, + version=plugin.version)) + result = dict(result=True, needs_restart=needs_restart, needs_refresh=needs_refresh, @@ -667,7 +675,8 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, if strip: lines = map(lambda x: x.strip(), lines) - self._plugin_manager.send_plugin_message(self._identifier, dict(type="loglines", loglines=[dict(line=line, stream=stream) for line in lines])) + self._plugin_manager.send_plugin_message(self._identifier, dict(type="loglines", + loglines=[dict(line=line, stream=stream) for line in lines])) for line in lines: self._console_logger.debug(u"{prefix} {line}".format(**locals())) @@ -686,6 +695,9 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, elif not plugin.enabled and plugin.key not in self._pending_enable: self._pending_enable.add(plugin.key) + self._event_bus.fire("plugin_pluginmanager_enableplugin", dict(id=plugin.key, + version=plugin.version)) + def _mark_plugin_disabled(self, plugin, needs_restart=False): disabled_list = list(self._settings.global_get(["plugins", "_disabled"])) if not plugin.key in disabled_list: @@ -701,6 +713,9 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, elif (plugin.enabled or plugin.forced_disabled or getattr(plugin, "safe_mode_victim", False)) and plugin.key not in self._pending_disable: self._pending_disable.add(plugin.key) + self._event_bus.fire("plugin_pluginmanager_disableplugin", dict(id=plugin.key, + version=plugin.version)) + def _fetch_all_data(self, async=False): def run(): self._repository_available = self._fetch_repository_from_disk() diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py new file mode 100644 index 000000000..a6cf37c2b --- /dev/null +++ b/src/octoprint/plugins/tracking/__init__.py @@ -0,0 +1,186 @@ +# coding=utf-8 +from __future__ import absolute_import, division, print_function, unicode_literals + +__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' +__copyright__ = "Copyright (C) 2018 The OctoPrint Project - Released under terms of the AGPLv3 License" + +import octoprint.plugin + +from flask.ext.babel import gettext + +import requests +import hashlib +import logging + +# noinspection PyCompatibility +import concurrent.futures + +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}" + +# noinspection PyMissingConstructor +class TrackingPlugin(octoprint.plugin.SettingsPlugin, + octoprint.plugin.EnvironmentDetectionPlugin, + octoprint.plugin.StartupPlugin, + octoprint.plugin.TemplatePlugin, + octoprint.plugin.AssetPlugin, + octoprint.plugin.WizardPlugin, + octoprint.plugin.EventHandlerPlugin): + + def __init__(self): + self._environment = None + self._url = None + self._ping_worker = None + self._executor = concurrent.futures.ThreadPoolExecutor(max_workers=1) + + def initialize(self): + self._init_tracking() + + ##~~ SettingsPlugin + + def get_settings_defaults(self): + return dict(enabled=None, + unique_id=None, + server=TRACKING_URL, + ping=15*60) + + def on_settings_save(self, data): + enabled = self._settings.get([b"enabled"]) + + octoprint.plugin.SettingsPlugin.on_settings_save(self, data) + + if enabled is None and self._settings.get([b"enabled"]): + # tracking was just enabled, let's init it and send a startup event + self._init_tracking() + self._track_startup() + + ##~~ EnvironmentDetectionPlugin + + def on_environment_detected(self, environment, *args, **kwargs): + self._environment = environment + + ##~~ StartupPlugin + + def on_after_startup(self): + self._track_startup() + + ping = self._settings.get_int(["ping"]) + if ping: + self._ping_worker = RepeatedTimer(ping, self._track_ping) + self._ping_worker.start() + + ##~~ EventHandlerPlugin + + def on_event(self, event, payload): + if event.startswith("plugin_pluginmanager_"): + self._track_plugin_event(event, payload) + elif event in (Events.PRINT_STARTED, Events.PRINT_DONE, Events.PRINT_FAILED, Events.PRINT_CANCELLED): + self._track_printjob_event(event, payload) + + ##~~ TemplatePlugin + + def get_template_configs(self): + return [ + dict(type="settings", name=gettext("Usage Tracking"), template="tracking_settings.jinja2", custom_bindings=False), + dict(type="wizard", name=gettext("Anonymous Usage Tracking"), template="tracking_wizard.jinja2", custom_bindings=True, mandatory=True) + ] + + ##~~ AssetPlugin + + def get_assets(self): + return dict(js=["js/tracking.js"]) + + ##~~ WizardPlugin + + def is_wizard_required(self): + return self._settings.get([b"enabled"]) is None + + ##~~ helpers + + def _init_tracking(self): + if not self._settings.get_boolean([b"enabled"]): + return + self._init_id() + self._logger.info("Initialized anonymous tracking") + + def _init_id(self): + if self._settings.get_boolean([b"enabled"]) and not self._settings.get([b"unique_id"]): + import uuid + self._settings.set([b"unique_id"], str(uuid.uuid4())) + self._settings.save() + + def _track_startup(self): + self._track("startup", + version=get_octoprint_version_string(), + os=self._environment[b"os"][b"id"]) + + def _track_ping(self): + self._track("ping") + + def _track_plugin_event(self, event, payload): + if event.endswith("_installplugin"): + self._track("install_plugin", plugin=payload.get(b"id"), plugin_version=payload.get(b"version")) + elif event.endswith("_uninstallplugin"): + self._track("uninstall_plugin", plugin=payload.get(b"id"), plugin_version=payload.get(b"version")) + elif event.endswith("_enableplugin"): + self._track("enable_plugin", plugin=payload.get(b"id"), plugin_version=payload.get(b"version")) + elif event.endswith("_disableplugin"): + self._track("disable_plugin", plugin=payload.get(b"id"), plugin_version=payload.get(b"version")) + + def _track_printjob_event(self, event, payload): + sha = hashlib.sha1() + sha.update(payload.get("name")) + + event = None + args = dict(origin=payload.get(b"origin"), file=sha.hexdigest()) + + if event == Events.PRINT_STARTED: + 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" + elif event == Events.PRINT_FAILED: + event = "print_failed" + elif event == Events.PRINT_CANCELLED: + event = "print_cancelled" + + if event is not None: + self._track(event, **args) + + def _track(self, event, **kwargs): + if not self._settings.get_boolean([b"enabled"]): + return + + self._executor.submit(self._do_track, event, **kwargs) + + 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()))) + + headers = {"User-Agent": "OctoPrint/{}".format(get_octoprint_version_string())} + try: + requests.get(url, + timeout=3.1, + headers=headers) + self._logger.debug("Sent tracking event to {}".format(url)) + except: + if self._logger.isEnabledFor(logging.DEBUG): + self._logger.exception("Error while sending event to anonymous usage tracking".format(url)) + else: + pass + +__plugin_name__ = "Usage Tracking" +__plugin_description__ = "Anonymous version and usage tracking, see homepage for details on what gets tracked" +__plugin_homepage__ = "TODO" +__plugin_author__ = "Gina Häußge" + +__plugin_implementation__ = TrackingPlugin() diff --git a/src/octoprint/plugins/tracking/static/js/tracking.js b/src/octoprint/plugins/tracking/static/js/tracking.js new file mode 100644 index 000000000..6855450b6 --- /dev/null +++ b/src/octoprint/plugins/tracking/static/js/tracking.js @@ -0,0 +1,85 @@ +$(function() { + function TrackingViewModel(parameters) { + var self = this; + + self.settingsViewModel = parameters[0]; + + self.setup = ko.observable(false); + + self.decision = ko.observable(); + self.required = false; + self.active = false; + + self.enableTracking = function() { + self.settingsViewModel.settings.plugins.tracking.enabled(true); + self.decision(true); + self._sendData(); + }; + + self.disableTracking = function() { + self.settingsViewModel.settings.plugins.tracking.enabled(false); + self.decision(false); + self._sendData(); + }; + + self.onBeforeWizardTabChange = function(next, current) { + if (!self.required) return true; + + if (!current || !_.startsWith(current, "wizard_plugin_tracking") || self.setup()) { + return true; + } + + self._showDecisionNeededDialog(); + return false; + }; + + self.onBeforeWizardFinish = function() { + if (!self.required) return true; + + if (self.setup()) { + return true; + } + + self._showDecisionNeededDialog(); + return false; + }; + + self.onWizardPreventSettingsRefreshDialog = function() { + return self.active; + }; + + self.onWizardDetails = function(response) { + self.required = response && response.tracking && response.tracking.required; + }; + + self._showDecisionNeededDialog = function() { + showMessageDialog({ + title: gettext("Please set up anonymous usage tracking"), + message: gettext("You haven't yet decided on whether to enable or disable anonymous usage tracking. You need to either enable or disable it before continuing.") + }); + }; + + self._sendData = function() { + var data = { + plugins: { + tracking: { + enabled: self.settingsViewModel.settings.plugins.tracking.enabled() + } + } + }; + + self.active = true; + self.settingsViewModel.saveData(data) + .done(function() { + self.setup(true); + self.active = false; + }); + }; + } + + OCTOPRINT_VIEWMODELS.push([ + TrackingViewModel, + ["settingsViewModel"], + "#wizard_plugin_tracking" + ]); +}); diff --git a/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 b/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 new file mode 100644 index 000000000..578e5a8ae --- /dev/null +++ b/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 @@ -0,0 +1,7 @@ +
+
+ +
+
diff --git a/src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 b/src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 new file mode 100644 index 000000000..4a1843f09 --- /dev/null +++ b/src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 @@ -0,0 +1,19 @@ +

{{ _('Configure anonymous usage tracking') }}

+ +

{% trans %} + TODO: Add explanation what this does and tracks +{% endtrans %}

+ + + + From 382f10557ed6db73bf2d05580bfd2ed435661252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 4 Jul 2018 11:17:17 +0200 Subject: [PATCH 12/20] Tracking: Add explanation text & links --- src/octoprint/plugins/tracking/__init__.py | 4 ++-- .../tracking/trackingDescription.jinja2 | 10 ++++++++++ .../plugins/tracking/trackingDetails.jinja2 | 4 ++++ .../templates/tracking_settings.jinja2 | 20 +++++++++++++------ .../tracking/templates/tracking_wizard.jinja2 | 16 +++++++-------- 5 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 src/octoprint/plugins/tracking/templates/snippets/plugins/tracking/trackingDescription.jinja2 create mode 100644 src/octoprint/plugins/tracking/templates/snippets/plugins/tracking/trackingDetails.jinja2 diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index a6cf37c2b..7944e6050 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -178,9 +178,9 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, else: pass -__plugin_name__ = "Usage Tracking" +__plugin_name__ = "Anonymous Usage Tracking" __plugin_description__ = "Anonymous version and usage tracking, see homepage for details on what gets tracked" -__plugin_homepage__ = "TODO" +__plugin_homepage__ = "https://tracking.octoprint.org" __plugin_author__ = "Gina Häußge" __plugin_implementation__ = TrackingPlugin() diff --git a/src/octoprint/plugins/tracking/templates/snippets/plugins/tracking/trackingDescription.jinja2 b/src/octoprint/plugins/tracking/templates/snippets/plugins/tracking/trackingDescription.jinja2 new file mode 100644 index 000000000..524a6f4f2 --- /dev/null +++ b/src/octoprint/plugins/tracking/templates/snippets/plugins/tracking/trackingDescription.jinja2 @@ -0,0 +1,10 @@ +{% trans %} +

+ Anonymous usage tracking provides valuable insights into how many instances running what versions of OctoPrint are out there, + whether they are successfully completing print jobs and various other metrics. +

+

+ By enabling it you help to identify problems with new releases and release candidates early on, and to better + tailor OctoPrint's future development to actual use. +

+{% endtrans %} diff --git a/src/octoprint/plugins/tracking/templates/snippets/plugins/tracking/trackingDetails.jinja2 b/src/octoprint/plugins/tracking/templates/snippets/plugins/tracking/trackingDetails.jinja2 new file mode 100644 index 000000000..d1fc0d990 --- /dev/null +++ b/src/octoprint/plugins/tracking/templates/snippets/plugins/tracking/trackingDetails.jinja2 @@ -0,0 +1,4 @@ +

{% trans %} + For details on what gets tracked, please refer to tracking.octoprint.org + and also the Privacy Policy at tracking.octoprint.org. +{% endtrans %}

diff --git a/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 b/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 index 578e5a8ae..4682a6929 100644 --- a/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 +++ b/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 @@ -1,7 +1,15 @@ -
-
- +

{{ _('Anonymous Usage Tracking') }}

+ +{% include "snippets/plugins/tracking/trackingDescription.jinja2" %} + +
+
+
+ +
-
+ + +{% include "snippets/plugins/tracking/trackingDetails.jinja2" %} diff --git a/src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 b/src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 index 4a1843f09..cbc6c12d7 100644 --- a/src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 +++ b/src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 @@ -1,19 +1,19 @@ -

{{ _('Configure anonymous usage tracking') }}

+

{{ _('Configure Anonymous Usage Tracking') }}

-

{% trans %} - TODO: Add explanation what this does and tracks -{% endtrans %}

+{% include "snippets/plugins/tracking/trackingDescription.jinja2" %} + +{% include "snippets/plugins/tracking/trackingDetails.jinja2" %} From 3da4877d509e3114b659ed2b95a6704932b28b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 4 Jul 2018 15:08:09 +0200 Subject: [PATCH 13/20] Tracking: Display instance ID in settings --- .../plugins/tracking/templates/tracking_settings.jinja2 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 b/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 index 4682a6929..4c43e27cc 100644 --- a/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 +++ b/src/octoprint/plugins/tracking/templates/tracking_settings.jinja2 @@ -10,6 +10,12 @@
+
+ +
+ +
+
{% include "snippets/plugins/tracking/trackingDetails.jinja2" %} From 8ca188e50945a82a6ceb1b1d3c756fdd111568d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 4 Jul 2018 15:10:48 +0200 Subject: [PATCH 14/20] Tracking: rename tab in settings --- src/octoprint/plugins/tracking/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index 7944e6050..08ed7855d 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -84,7 +84,7 @@ class TrackingPlugin(octoprint.plugin.SettingsPlugin, def get_template_configs(self): return [ - dict(type="settings", name=gettext("Usage Tracking"), template="tracking_settings.jinja2", custom_bindings=False), + dict(type="settings", name=gettext("Anonymous Usage Tracking"), template="tracking_settings.jinja2", custom_bindings=False), dict(type="wizard", name=gettext("Anonymous Usage Tracking"), template="tracking_wizard.jinja2", custom_bindings=True, mandatory=True) ] From faff20943fa1a983f2d50b7f7646fd04de703c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 5 Jul 2018 10:58:45 +0200 Subject: [PATCH 15/20] Capture & log any errors in the state update worker See #2715 --- src/octoprint/printer/standard.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index c1355bbad..ba2d44d4d 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -1305,20 +1305,23 @@ class StateMonitor(object): self._change_event.set() def _work(self): - while True: - self._change_event.wait() + try: + while True: + self._change_event.wait() - now = time.time() - delta = now - self._last_update - additional_wait_time = self._interval - delta - if additional_wait_time > 0: - time.sleep(additional_wait_time) + now = time.time() + delta = now - self._last_update + additional_wait_time = self._interval - delta + if additional_wait_time > 0: + time.sleep(additional_wait_time) - with self._state_lock: - data = self.get_current_data() - self._update_callback(data) - self._last_update = time.time() - self._change_event.clear() + with self._state_lock: + data = self.get_current_data() + self._update_callback(data) + self._last_update = time.time() + self._change_event.clear() + except: + logging.getLogger(__name__).exception("Looks like something crashed inside the state update worker. Please report this on the OctoPrint issue tracker (make sure to include logs!)") def get_current_data(self): with self._progress_lock: From 0834288cfc6ebb2b9d1c9e3bd2c8deb0150124a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 5 Jul 2018 09:29:43 +0200 Subject: [PATCH 16/20] Fix estimator initialization on SD print start Closes #2715 --- src/octoprint/printer/standard.py | 35 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index ba2d44d4d..6ae36dc50 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -82,6 +82,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._selectedFile = None self._estimator_factory = PrintTimeEstimator + self._estimator = None analysis_queue_hooks = plugin_manager().get_hooks("octoprint.printer.estimation.factory") for name, hook in analysis_queue_hooks.items(): try: @@ -134,7 +135,17 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): eventManager().subscribe(Events.METADATA_ANALYSIS_FINISHED, self._on_event_MetadataAnalysisFinished) eventManager().subscribe(Events.METADATA_STATISTICS_UPDATED, self._on_event_MetadataStatisticsUpdated) - def _create_estimator(self, job_type): + def _create_estimator(self, job_type=None): + if job_type is None: + with self._selectedFileMutex: + if self._selectedFile is None: + return + + if self._selectedFile["sd"]: + job_type = "sdcard" + else: + job_type = "local" + self._estimator = self._estimator_factory(job_type) #~~ handling of PrinterCallbacks @@ -494,12 +505,6 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): if self._selectedFile is None: return - if self._selectedFile["sd"]: - job_type = "sdcard" - else: - job_type = "local" - - self._create_estimator(job_type) self._fileManager.delete_recovery_data() self._lastProgressReport = None @@ -749,6 +754,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): cleanedPrintTime = self._comm.getCleanedPrintTime() printTimeLeft = printTimeLeftOrigin = None + estimator = self._estimator if progress is not None: progress_int = int(progress * 100) if self._lastProgressReport != progress_int: @@ -761,7 +767,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): elif progress == 1.0: printTimeLeft = 0 printTimeLeftOrigin = None - else: + elif estimator is not None: statisticalTotalPrintTime = None statisticalTotalPrintTimeType = None with self._selectedFileMutex: @@ -770,11 +776,11 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): statisticalTotalPrintTime = self._selectedFile["estimatedPrintTime"] statisticalTotalPrintTimeType = self._selectedFile.get("estimatedPrintTimeType", None) - printTimeLeft, printTimeLeftOrigin = self._estimator.estimate(progress, - printTime, - cleanedPrintTime, - statisticalTotalPrintTime, - statisticalTotalPrintTimeType) + printTimeLeft, printTimeLeftOrigin = estimator.estimate(progress, + printTime, + cleanedPrintTime, + statisticalTotalPrintTime, + statisticalTotalPrintTimeType) return self._dict(completion=progress * 100 if progress is not None else None, filepos=filepos, @@ -1031,6 +1037,8 @@ 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())) @@ -1039,6 +1047,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self.start_print(pos=self._posAfterSelect, user=user) def on_comm_print_job_started(self, suppress_script=False): + self._stateMonitor.trigger_progress_update() payload = self._payload_for_print_job_event() if payload: eventManager().fire(Events.PRINT_STARTED, payload) From f7a3e6a6ee7a51d7faece1431cca321ecbc237e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 6 Jul 2018 12:03:09 +0200 Subject: [PATCH 17/20] Add --no-cache-dir flag to update pip operations Otherwise we might run into some weird infinite loop issues within pip's cache handling under certain circumstances, and we really don't want to risk that in the field. See also #2543 for another issue worked around by this, and pypa/pip#3532 for the core issue --- src/octoprint/plugins/softwareupdate/updaters/pip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/plugins/softwareupdate/updaters/pip.py b/src/octoprint/plugins/softwareupdate/updaters/pip.py index 6372da151..08dfed097 100644 --- a/src/octoprint/plugins/softwareupdate/updaters/pip.py +++ b/src/octoprint/plugins/softwareupdate/updaters/pip.py @@ -80,7 +80,7 @@ def perform_update(target, check, target_version, log_cb=None, online=True, forc install_arg = check["pip"].format(target_version=target_version, target=target_version) logger.debug(u"Target: %s, executing pip install %s" % (target, install_arg)) - pip_args = ["install", install_arg] + pip_args = ["install", install_arg, "--no-cache-dir"] pip_kwargs = dict() if pip_working_directory is not None: pip_kwargs.update(cwd=pip_working_directory) From 6728302bb3b3ee01ffcfe0279448c667da5435c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 6 Jul 2018 12:55:25 +0200 Subject: [PATCH 18/20] Preparing release of 1.3.9rc2 --- CHANGELOG.md | 15 +++++++++++++++ SUPPORTERS.md | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c780ca0c3..12c01b817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # OctoPrint Changelog +## 1.3.9rc2 (2018-07-06) + +### Improvements + + * Add sanity check for disabled plugin list (see also [#2687 (comment)](https://github.com/foosel/OctoPrint/issues/2687#issuecomment-399797596)). + * Improve logging of exceptions triggered inside the state update worker (see also [#2715](https://github.com/foosel/OctoPrint/issues/2715)). + +### Bug fixes + + * [#2715](https://github.com/foosel/OctoPrint/issues/2715) (regression) - Fix broken estimator initialization on SD print start and resulting crash of the state update worker. + +### More information + + * [Commits](https://github.com/foosel/OctoPrint/compare/1.3.9rc1...1.3.9rc2) + ## 1.3.9rc1 (2018-06-20) ### Note for upgraders running NGINX as reverse proxy: Be sure to configure HTTP protocol version 1.1 diff --git a/SUPPORTERS.md b/SUPPORTERS.md index 3448ce8d2..c6729c741 100644 --- a/SUPPORTERS.md +++ b/SUPPORTERS.md @@ -30,10 +30,12 @@ thanks to everyone who contributed! * Jeremiah Avery * Josh Daniels * Joshua Wills + * Justin Kaufman * Kaile Riser * Kale Stedman * Kazuhiro Ogura * Kodama Inc. + * Lewis Newby * LulzBot® * Makespace Madrid * Mark Walker @@ -51,11 +53,10 @@ thanks to everyone who contributed! * Samer Najia * Simon Hallam * Stefan Krister - * Stephane Schittly * Sven Mueller * Symbiotic Devices * Thomas Hatley * Timothy D Hoogland * Trent Shumay -and 1334 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel)! \ No newline at end of file +and 1332 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel)! \ No newline at end of file From 798bc2b2252109c617eb7f5e4901428c0c4a8f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 6 Jul 2018 12:55:25 +0200 Subject: [PATCH 19/20] Preparing release of 1.3.9rc2 --- CHANGELOG.md | 15 +++++++++++++++ SUPPORTERS.md | 7 ++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c780ca0c3..12c01b817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # OctoPrint Changelog +## 1.3.9rc2 (2018-07-06) + +### Improvements + + * Add sanity check for disabled plugin list (see also [#2687 (comment)](https://github.com/foosel/OctoPrint/issues/2687#issuecomment-399797596)). + * Improve logging of exceptions triggered inside the state update worker (see also [#2715](https://github.com/foosel/OctoPrint/issues/2715)). + +### Bug fixes + + * [#2715](https://github.com/foosel/OctoPrint/issues/2715) (regression) - Fix broken estimator initialization on SD print start and resulting crash of the state update worker. + +### More information + + * [Commits](https://github.com/foosel/OctoPrint/compare/1.3.9rc1...1.3.9rc2) + ## 1.3.9rc1 (2018-06-20) ### Note for upgraders running NGINX as reverse proxy: Be sure to configure HTTP protocol version 1.1 diff --git a/SUPPORTERS.md b/SUPPORTERS.md index 3448ce8d2..320f12706 100644 --- a/SUPPORTERS.md +++ b/SUPPORTERS.md @@ -1,7 +1,7 @@ # Supporters Development of this version of OctoPrint wouldn't have been possible without -[financial support by the community](http://octoprint.org/support-octoprint/) - +[the financial support by the community](https://octoprint.org/support-octoprint/) - thanks to everyone who contributed! ## Patreon Patrons @@ -30,10 +30,12 @@ thanks to everyone who contributed! * Jeremiah Avery * Josh Daniels * Joshua Wills + * Justin Kaufman * Kaile Riser * Kale Stedman * Kazuhiro Ogura * Kodama Inc. + * Lewis Newby * LulzBot® * Makespace Madrid * Mark Walker @@ -51,11 +53,10 @@ thanks to everyone who contributed! * Samer Najia * Simon Hallam * Stefan Krister - * Stephane Schittly * Sven Mueller * Symbiotic Devices * Thomas Hatley * Timothy D Hoogland * Trent Shumay -and 1334 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel)! \ No newline at end of file +and 1332 more wonderful people pledging on the [Patreon campaign](https://patreon.com/foosel)! \ No newline at end of file From e15946ff79d63c431b4088fb93920d86c880375a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 6 Jul 2018 14:34:19 +0200 Subject: [PATCH 20/20] staging/maintenance is now 1.3.9rc3.dev --- .versioneer-lookup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.versioneer-lookup b/.versioneer-lookup index 5cdf3804e..03672fbbd 100644 --- a/.versioneer-lookup +++ b/.versioneer-lookup @@ -24,10 +24,10 @@ maintenance 1.3.9 da2c9632ea54fd1b3c8ae34f8f26bab29dbaf3c6 pep440-dev fix/.* 1.3.9 da2c9632ea54fd1b3c8ae34f8f26bab29dbaf3c6 pep440-dev improve/.* 1.3.9 da2c9632ea54fd1b3c8ae34f8f26bab29dbaf3c6 pep440-dev -# staging/maintenance is currently the branch for preparation of 1.3.7rc5 +# staging/maintenance is currently the branch for preparation of 1.3.9rc2 # so is regressionfix/... -staging/maintenance 1.3.9rc2 fdf0f75ffa5731fee406c6e761e84a9d2b47aa43 pep440-dev -regressionfix/.* 1.3.9rc2 fdf0f75ffa5731fee406c6e761e84a9d2b47aa43 pep440-dev +staging/maintenance 1.3.9rc3 fd94fc94a09dd91deeb2f59a6b3b00b37eb1f145 pep440-dev +regressionfix/.* 1.3.9rc3 fd94fc94a09dd91deeb2f59a6b3b00b37eb1f145 pep440-dev # every other branch is a development branch and thus gets resolved to 1.4.0-dev for now .* 1.4.0 7f5d03d0549bcbd26f40e7e4a3297ea5204fb1cc pep440-dev