diff --git a/docs/bundledplugins/softwareupdate.rst b/docs/bundledplugins/softwareupdate.rst index dfc837f36..b8909ee23 100644 --- a/docs/bundledplugins/softwareupdate.rst +++ b/docs/bundledplugins/softwareupdate.rst @@ -243,6 +243,9 @@ Update methods * ``python_updater``: Can only be specified by plugins through the :ref:`hook `. A python callable which performs the update, see below for details. + * ``sleep_a_bit``: Does nothing but block for a configurable ``duration`` and log + a countdown in the meantime. Useful for debugging software update mechanisms + during development. .. note:: diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index ffb2f583d..5e1b2649e 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -1113,7 +1113,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, mapping = dict(update_script=updaters.update_script, pip=updaters.pip, - python_updater=updaters.python_updater) + python_updater=updaters.python_updater, + sleep_a_bit=updaters.sleep_a_bit) method = self._get_update_method(target, check, valid_methods=mapping.keys()) return mapping[method] diff --git a/src/octoprint/plugins/softwareupdate/updaters/__init__.py b/src/octoprint/plugins/softwareupdate/updaters/__init__.py index 4d2189097..e492dda64 100644 --- a/src/octoprint/plugins/softwareupdate/updaters/__init__.py +++ b/src/octoprint/plugins/softwareupdate/updaters/__init__.py @@ -5,4 +5,4 @@ __author__ = "Gina Häußge " __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License" -from . import pip, python_updater, update_script \ No newline at end of file +from . import pip, python_updater, update_script, sleep_a_bit diff --git a/src/octoprint/plugins/softwareupdate/updaters/sleep_a_bit.py b/src/octoprint/plugins/softwareupdate/updaters/sleep_a_bit.py new file mode 100644 index 000000000..f39ecc7b0 --- /dev/null +++ b/src/octoprint/plugins/softwareupdate/updaters/sleep_a_bit.py @@ -0,0 +1,23 @@ +# coding=utf-8 +from __future__ import absolute_import, division, print_function + +__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 monotonic +import time + +def can_perform_update(target, check, online=True): + return True + + +def perform_update(target, check, target_version, log_cb=None, online=True): + duration = check.get("duration", 30) + + now = monotonic.monotonic() + end = now + duration + while now < end: + log_cb(["{}s left...".format(end - now)], prefix=">", stream="output") + time.sleep(5) + now = monotonic.monotonic()