diff --git a/docs/api/general.rst b/docs/api/general.rst index 3c404724c..47e46aa32 100644 --- a/docs/api/general.rst +++ b/docs/api/general.rst @@ -148,8 +148,14 @@ Login via the ``passive`` flag. Will return a :http:statuscode:`200` with a :ref:`login response ` on successful - login, whether active or passive. The active (username/password) login may also return a :http:statuscode:`401` in - case of a username/password mismatch or unknown user and a :http:statuscode:`403` in case of a deactivated account. + login, whether active or passive. The active (username/password) login may also return a :http:statuscode:`403` in + case of a username/password mismatch, unknown user or a deactivated account. + + .. warning:: + + Previous versions of this API endpoint did return a :http:statuscode:`401` in case of a username/password + mismatch or an unknown user. That was incompatible with basic authentication since it was a wrong use of + the :http:statuscode:`401` code and got therefore changed as part of a bug fix. :json passive: If present, performs a passive login only, returning information about the current user that's active either through an existing session or the used API key @@ -157,8 +163,7 @@ Login :json pass: (active login only) Password :json remember: (active login only) Whether to set a "remember me" cookie on the session :status 200: Successful login - :status 401: Username/password mismatch or unknown user - :status 403: Deactivated account + :status 403: Username/password mismatch, unknown user or deactivated account .. _sec-api-general-logout: diff --git a/docs/bundledplugins/backup.rst b/docs/bundledplugins/backup.rst index 350d40508..8e05c4954 100644 --- a/docs/bundledplugins/backup.rst +++ b/docs/bundledplugins/backup.rst @@ -27,7 +27,7 @@ Command line usage ------------------ The Backup Plugin implements a command line interface that allows creation and restoration of backups. -It adds two new commands, ``backup:backup`` and ``backup_restore``. +It adds two new commands, ``backup:backup`` and ``backup:restore``. .. code-block:: none diff --git a/docs/bundledplugins/discovery.rst b/docs/bundledplugins/discovery.rst index 1fa8acdd7..52314cb5f 100644 --- a/docs/bundledplugins/discovery.rst +++ b/docs/bundledplugins/discovery.rst @@ -14,7 +14,7 @@ network running Microsoft Windows. You will be able to just double click on the OctoPrint instance icon in "Networks > Other Devices" in your Windows Explorer, which will take you directly to the web frontend. -The ZeroConf support allows OctoPrint to announce itself to Safari on MacOS X +The ZeroConf support allows OctoPrint to announce itself to Safari on macOS on the same network. Linux users should install `Avahi `_ and can then use one diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index 271911218..64001bde6 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -5,7 +5,7 @@ config.yaml If not specified via the command line, the main configuration file ``config.yaml`` for OctoPrint is expected in its settings folder, which unless defined differently via the command line is located at ``~/.octoprint`` on Linux, at -``%APPDATA%/OctoPrint`` on Windows and at ``~/Library/Application Support/OctoPrint`` on MacOS. If the file is not there, +``%APPDATA%/OctoPrint`` on Windows and at ``~/Library/Application Support/OctoPrint`` on macOS. If the file is not there, you can just create it - it will only get created by OctoPrint once you save settings that deviate from the default settings. diff --git a/docs/configuration/logging_yaml.rst b/docs/configuration/logging_yaml.rst index 483e79550..bb68c2028 100644 --- a/docs/configuration/logging_yaml.rst +++ b/docs/configuration/logging_yaml.rst @@ -5,7 +5,7 @@ logging.yaml The logging configuration file ``logging.yaml`` for OctoPrint is expected in its settings folder, which unless defined differently on the command line is located at ``~/.octoprint`` on Linux, at ``%APPDATA%/OctoPrint`` on Windows and at -``~/Library/Application Support/OctoPrint`` on MacOS. +``~/Library/Application Support/OctoPrint`` on macOS. You can use it to change the log levels of the individual components within OctoPrint, which might be necessary to help in debugging issues you are experiencing, or to change the configuration of the logging handlers themselves, e.g. in diff --git a/docs/development/environment.rst b/docs/development/environment.rst index 2fa09aac3..ea1110153 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -17,7 +17,7 @@ below. * `Python 3.7 `_ including ``pip``, ``setuptools`` and ``virtualenv`` * `Git `_ - * Checkout the OctoPrint sources from their Git repository: + * Checkout the OctoPrint sources from their Git repository: * ``git clone -b devel https://github.com/foosel/OctoPrint.git`` * Enter the checked out source folder: ``cd OctoPrint`` * Create virtual environments in the checked out source folder for both Python 2.7 and Python 3.7 to use for @@ -26,12 +26,12 @@ below. * PY2: ``virtualenv --python=python2 venv2`` * PY3: ``virtualenv --python=python3 venv3`` * Activate one of the virtual environments: - * PY2: ``source venv2/bin/activate`` (Linux, MacOS) or ``source venv2/Scripts/activate`` (Git Bash under Windows, see below) - * PY3: ``source venv3/bin/activate`` (Linux, MacOS) or ``source venv3/Scripts/activate`` (Git Bash under Windows, see below) + * PY2: ``source venv2/bin/activate`` (Linux, macOS) or ``source venv2/Scripts/activate`` (Git Bash under Windows, see below) + * PY3: ``source venv3/bin/activate`` (Linux, macOS) or ``source venv3/Scripts/activate`` (Git Bash under Windows, see below) * Update ``pip`` in the virtual environment: * ``pip install --upgrade pip`` * Install OctoPrint in `"editable" mode `_, - including its regular *and* development and plugin development dependencies: + including its regular *and* development and plugin development dependencies: * ``pip install -e .[develop,plugins]`` When the virtual environment is activated you can then: @@ -197,8 +197,10 @@ PyCharm ....... - "File" > "Open ...", select OctoPrint checkout folder (e.g. ``~/devel/OctoPrint`` or ``C:\Devel\OctoPrint``) - - "File" > "Settings ..." > "Project: OctoPrint" > "Project Interpreter" > "Add local ...", select OctoPrint venv + - **(Linux, Windows)** "File" > "Settings ..." > "Project: OctoPrint" > "Project Interpreter" > "Add local ...", select OctoPrint venv folder (e.g. ``~/devel/OctoPrint/venv`` or ``C:\Devel\OctoPrint\venv``) + - **(macOS)** "PyCharm" > "Preferences ..." > "Project: OctoPrint" > "Project Interpreter" > "Add ..." > + "Virtualenv Environment > "Existing Environment", select OctoPrint venv folder (e.g. ``~/devel/OctoPrint/venv``) - Right click "src" in project tree, mark as source folder - Add Run/Debug Configuration, select "Python": diff --git a/docs/development/virtual_printer.rst b/docs/development/virtual_printer.rst index 85d35c50e..ebf931113 100644 --- a/docs/development/virtual_printer.rst +++ b/docs/development/virtual_printer.rst @@ -17,7 +17,7 @@ be found in the full :ref:`config.yaml documentation `, OctoPrint expects scripts to be located in the ``scripts/gcode`` folder in OctoPrint configuration directory (per default ``~/.octoprint`` on Linux, ``%APPDATA%\OctoPrint`` -on Windows and ``~/Library/Application Support/OctoPrint`` on MacOS). +on Windows and ``~/Library/Application Support/OctoPrint`` on macOS). These GCODE scripts are backed by the templating engine Jinja2, allowing more than just simple "send-as-is" scripts but making use of a full blown templating language in order to create your scripts. To diff --git a/docs/features/safemode.rst b/docs/features/safemode.rst index 56445e9e4..45ec3651c 100644 --- a/docs/features/safemode.rst +++ b/docs/features/safemode.rst @@ -75,12 +75,12 @@ When OctoPrint is running in safe mode the following changes to its normal opera * OctoPrint will not enable any of the installed third party plugins. OctoPrint considers all plugins third party plugins that do not ship with OctoPrint's sources, so any plugins installed either via `pip` or into OctoPrint's plugin folder at ``~/.octoprint/plugins`` (Linux), ``%APPDATA%/OctoPrint/plugins`` (Windows) and - ``~/Library/Application Support/OctoPrint/plugins`` (MacOS). + ``~/Library/Application Support/OctoPrint/plugins`` (macOS). * OctoPrint will not enable any of the installed third party language packs. OctoPrint considers all language packs third party language packs that do not ship with OctoPrint's sources, so any language plugins installed through the language pack manager within settings and/or stored in the language pack folder at ``~/.octoprint/translations`` (Linux), ``%APPDATA%/OctoPrint/translations`` (Windows) or - ``~/Library/Application Support/OctoPrint/translations`` (MacOS). + ``~/Library/Application Support/OctoPrint/translations`` (macOS). * OctoPrint will still allow to uninstall third party plugins through the built-in Plugin Manager. * OctoPrint will still allow to disable (bundled) plugins that are still enabled. * OctoPrint will not allow to enable third party plugins. diff --git a/docs/jsclientlib/socket.rst b/docs/jsclientlib/socket.rst index 6da88a1ee..925528490 100644 --- a/docs/jsclientlib/socket.rst +++ b/docs/jsclientlib/socket.rst @@ -42,7 +42,7 @@ To register for all message types, provide ``*`` as the type to register for. ``handler`` is expected to be a function accepting one object parameter ``eventObj``, consisting - of the received message as property ``key`` and the received payload (if any) as property ``data``. + of the received message as property ``event`` and the received payload (if any) as property ``data``. .. code-block:: javascript diff --git a/src/octoprint/plugin/core.py b/src/octoprint/plugin/core.py index 05a46ff22..c25d4e2ec 100644 --- a/src/octoprint/plugin/core.py +++ b/src/octoprint/plugin/core.py @@ -447,7 +447,7 @@ class PluginInfo(object): @property def hooks(self): """ - Hooks provided by the plugin. Will be taken from the hooks attribute of the plugin module as defiend in + Hooks provided by the plugin. Will be taken from the hooks attribute of the plugin module as defined in :attr:`attr_hooks` if available, otherwise an empty dictionary is returned. Returns: diff --git a/src/octoprint/plugins/discovery/__init__.py b/src/octoprint/plugins/discovery/__init__.py index e8d153f8e..c9ee8dea9 100644 --- a/src/octoprint/plugins/discovery/__init__.py +++ b/src/octoprint/plugins/discovery/__init__.py @@ -212,7 +212,7 @@ class DiscoveryPlugin(octoprint.plugin.StartupPlugin, def zeroconf_unregister(self, reg_type, port=None): """ - Unregisteres a previously registered Zeroconf/Bonjour/Avahi service identified by service and port. + Unregisters a previously registered Zeroconf/Bonjour/Avahi service identified by service and port. :param reg_type: the type of the service to be unregistered :param port: the port of the service to be unregistered, defaults to OctoPrint's (public) port if not given diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 534464d1e..6817a0cca 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -197,7 +197,6 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, notices_ttl=6*60, pip_args=None, pip_force_user=False, - confirm_uninstall=True, confirm_disable=False, dependency_links=False, hidden=[], @@ -298,6 +297,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, "uninstall": ["plugin"], "enable": ["plugin"], "disable": ["plugin"], + "cleanup": ["plugin"], "refresh_repository": [] } @@ -384,7 +384,15 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, return make_response("Unknown plugin: %s" % plugin_name, 404) plugin = self._plugin_manager.plugins[plugin_name] - return self.command_uninstall(plugin) + return self.command_uninstall(plugin, cleanup=data.get("cleanup", False)) + + elif command == "cleanup": + plugin_name = data["plugin"] + if not plugin_name in self._plugin_manager.plugins: + return make_response("Unknown plugin: %s" % plugin_name, 404) + + plugin = self._plugin_manager.plugins[plugin_name] + return self.command_cleanup(plugin) elif command == "enable" or command == "disable": plugin_name = data["plugin"] @@ -565,7 +573,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, self._send_result_notification("install", result) return jsonify(result) - def command_uninstall(self, plugin): + def command_uninstall(self, plugin, cleanup=False): if plugin.key == "pluginmanager": return make_response("Can't uninstall Plugin Manager", 403) @@ -614,7 +622,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, self._logger.warning("Trying to uninstall plugin {plugin} but origin is unknown ({plugin.origin.type})".format(**locals())) return make_response("Could not uninstall plugin, its origin is unknown") - needs_restart = self._plugin_manager.is_restart_needing_plugin(plugin) + needs_restart = self._plugin_manager.is_restart_needing_plugin(plugin) or cleanup needs_refresh = plugin.implementation and isinstance(plugin.implementation, octoprint.plugin.ReloadNeedingPlugin) needs_reconnect = self._plugin_manager.has_any_of_hooks(plugin, self._reconnect_hooks) and self._printer.is_operational() @@ -654,6 +662,45 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, needs_reconnect=needs_reconnect, plugin=self._to_external_plugin(plugin)) self._send_result_notification("uninstall", result) + self._logger.info("Plugin {} uninstalled".format(plugin.key)) + + if cleanup: + self.command_cleanup(plugin) + + return jsonify(result) + + def command_cleanup(self, plugin): + # delete plugin settings + self._settings.global_set(["plugins", plugin.key], None) + self._settings.save() + message = "Cleaned up settings of plugin {}".format(plugin.key) + self._log_stdout(message) + self._logger.info(message) + + # delete plugin data folder + import os + import shutil + + result_data = True + data_folder = os.path.join(self._settings.getBaseFolder("data"), plugin.key) + if os.path.exists(data_folder): + try: + shutil.rmtree(data_folder) + message = "Cleaned up data folder of plugin {}".format(plugin.key) + self._log_stdout(message) + self._logger.info(message) + except: + message = "Could not delete data folder of plugin {} at {}".format(plugin.key, data_folder) + self._log_stderr(message) + self._logger.exception(message) + result_data = False + + result = dict(result=result_data, + needs_restart=True, + plugin=self._to_external_plugin(plugin)) + self._send_result_notification("cleanup", result) + self._logger.info("Plugin {} cleaned up".format(plugin.key)) + return jsonify(result) def command_toggle(self, plugin, command): diff --git a/src/octoprint/plugins/pluginmanager/static/clientjs/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/clientjs/pluginmanager.js index acaaf3590..5a59a2075 100644 --- a/src/octoprint/plugins/pluginmanager/static/clientjs/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/clientjs/pluginmanager.js @@ -52,11 +52,25 @@ return this.base.simpleApiCommand("pluginmanager", "install", data, opts); }; - OctoPrintPluginManagerClient.prototype.uninstall = function(plugin, opts) { + OctoPrintPluginManagerClient.prototype.uninstall = function(plugin, cleanup, opts) { + // backwards compatibility to former argument list (plugin, opts) + if (arguments.length === 2 && typeof cleanup === "object") { + opts = cleanup; + cleanup = false; + } + + var data = { + plugin: plugin, + cleanup: !!cleanup + }; + return this.base.simpleApiCommand("pluginmanager", "uninstall", data, opts); + }; + + OctoPrintPluginManagerClient.prototype.cleanup = function(plugin, opts) { var data = { plugin: plugin }; - return this.base.simpleApiCommand("pluginmanager", "uninstall", data, opts); + return this.base.simpleApiCommand("pluginmanager", "cleanup", data, opts); }; OctoPrintPluginManagerClient.prototype.enable = function(plugin, opts) { diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js index 26a0bc338..d974885cd 100644 --- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js @@ -186,6 +186,12 @@ $(function() { && !data.pending_uninstall; }; + self.enableCleanup = function(data) { + return self.enableManagement() + && data.key !== 'pluginmanager' + && !data.pending_uninstall; + }; + self.enableRepoInstall = function(data) { return self.enableManagement() && self.pipAvailable() && !self.safeMode() && !self.throttled() && self.online() && self.isCompatible(data); }; @@ -566,14 +572,14 @@ $(function() { } if (data.bundled) return; - if (data.key == "pluginmanager") return; + if (data.key === "pluginmanager") return; // defining actual uninstall logic as functor in order to handle // the confirm/no-confirm logic without duplication of logic - var performUninstall = function() { + var performUninstall = function(cleanup) { self._markWorking(gettext("Uninstalling plugin..."), _.sprintf(gettext("Uninstalling plugin \"%(name)s\""), {name: _.escape(data.name)})); - OctoPrint.plugins.pluginmanager.uninstall(data.key) + OctoPrint.plugins.pluginmanager.uninstall(data.key, cleanup) .done(function() { self.requestData(); }) @@ -590,19 +596,56 @@ $(function() { }); }; - if (self.settingsViewModel.settings.plugins.pluginmanager.confirm_uninstall()) { - // confirmation needed. Show confirmation dialog and call performUninstall if user clicks Yes - showConfirmationDialog({ - message: _.sprintf(gettext("You are about to uninstall the plugin \"%(name)s\""), {name: _.escape(data.name)}), - cancel: gettext("Keep installed"), - proceed: gettext("Uninstall"), - onproceed: performUninstall, - nofade: true - }); - } else { - // no confirmation needed, just go ahead and uninstall - performUninstall(); + showConfirmationDialog({ + message: _.sprintf(gettext("You are about to uninstall the plugin \"%(name)s\""), {name: _.escape(data.name)}), + cancel: gettext("Keep installed"), + proceed: [ + gettext("Uninstall"), + gettext("Uninstall & clean up data") + ], + onproceed: function(button) { + // buttons: 0=uninstall, 1=uninstall&cleanup + performUninstall(button === 1) + }, + nofade: true + }); + }; + + self.cleanupPlugin = function(data) { + if (!self.loginState.isAdmin()) { + return; } + + if (!self.enableUninstall(data)) { + return; + } + + if (data.key === "pluginmanager") return; + + var performCleanup = function() { + self._markWorking(gettext("Cleaning up plugin data..."), _.sprintf(gettext("Cleaning up data of plugin \"%(name)s\""), {name: _.escape(data.name)})); + + OctoPrint.plugins.pluginmanager.cleanup(data.key) + .fail(function() { + new PNotify({ + title: gettext("Something went wrong"), + text: gettext("Please consult octoprint.log for details"), + type: "error", + hide: false + }); + }) + .always(function() { + self._markDone(); + }) + }; + + showConfirmationDialog({ + message: _.sprintf(gettext("You are about to cleanup the plugin data of \"%(name)s\". This operation cannot be reversed."), {name: _.escape(data.name)}), + cancel: gettext("Keep data"), + proceed: gettext("Cleanup data"), + onproceed: performCleanup, + nofade: true + }); }; self.refreshRepository = function() { @@ -749,6 +792,10 @@ $(function() { line = gettext("Disable %(plugin)s: %(result)s"); break; } + case "cleanup": { + line = gettext("Cleanup %(plugin)s: %(result)s"); + break; + } default: { return; } diff --git a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 index e18a8dc51..22f73fbc5 100644 --- a/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 +++ b/src/octoprint/plugins/pluginmanager/templates/pluginmanager_settings.jinja2 @@ -81,7 +81,7 @@ -  |  +  |  |  @@ -267,13 +267,6 @@
{{ _('Confirmations') }} -
-
- -
-
+
+ +
+ + {{ _('Only modify if told to do so') }} +
+
diff --git a/src/octoprint/templates/tabs/timelapse.jinja2 b/src/octoprint/templates/tabs/timelapse.jinja2 index 2a8243c42..62afd9684 100644 --- a/src/octoprint/templates/tabs/timelapse.jinja2 +++ b/src/octoprint/templates/tabs/timelapse.jinja2 @@ -26,7 +26,7 @@ {{ _('sec') }} - {{ _('OctoPrint will rate limit snapshots to this minimum interval. This is to prevent against performance issues with vase mode/continous z prints.') }} + {{ _('OctoPrint will rate limit snapshots to this minimum interval. This it to prevent against performance issues with vase mode/continuous z prints.') }} @@ -75,7 +75,7 @@
diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 2deed35d6..d3351de22 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -40,7 +40,7 @@ from octoprint.filemanager.destinations import FileDestinations from octoprint.util import get_exception_string, sanitize_ascii, filter_non_ascii, CountedEvent, RepeatedTimer, \ to_unicode, bom_aware_open, TypedQueue, PrependableQueue, TypeAlreadyInQueue, chunks, ResettableTimer, \ monotonic_time -from octoprint.util.platform import get_os +from octoprint.util.platform import get_os, set_close_exec try: import winreg @@ -383,7 +383,7 @@ class MachineCom(object): CAPABILITY_SUPPORT_DETECTED = "detected" CAPABILITY_SUPPORT_DISABLED = "disabled" - def __init__(self, port = None, baudrate=None, callbackObject=None, printerProfileManager=None): + def __init__(self, port=None, baudrate=None, callbackObject=None, printerProfileManager=None): self._logger = logging.getLogger(__name__) self._serialLogger = logging.getLogger("SERIAL") self._phaseLogger = logging.getLogger(__name__ + ".command_phases") @@ -517,7 +517,8 @@ class MachineCom(object): self._pausing_commands = settings().get(["serial", "pausingCommands"]) self._emergency_commands = settings().get(["serial", "emergencyCommands"]) - self._clear_to_send = CountedEvent(name="comm.clear_to_send", minimum=None) + self._ack_max = settings().getInt(["serial", "ackMax"]) + self._clear_to_send = CountedEvent(name="comm.clear_to_send", minimum=None, maximum=self._ack_max) self._send_queue = SendQueue() self._temperature_timer = None self._sd_status_timer = None @@ -2674,6 +2675,15 @@ class MachineCom(object): serial_obj.open() + # Set close_exec flag on serial handle, see #3212 + if hasattr(serial_obj, "fd"): + # posix + set_close_exec(serial_obj.fd) + elif hasattr(serial_obj, "_port_handle"): + # win32 + # noinspection PyProtectedMember + set_close_exec(serial_obj._port_handle) + return BufferedReadlineWrapper(serial_obj) serial_factories = list(self._serial_factory_hooks.items()) + [("default", default)] @@ -3154,6 +3164,19 @@ class MachineCom(object): self._logger.debug("Type already in send queue: " + e.type) return False + def _use_up_clear(self, gcode): + # we only need to use up a clear if the command we just sent was either a gcode command or if we also + # require ack's for unknown commands + eats_clear = self._unknownCommandsNeedAck + if gcode is not None: + eats_clear = True + + if eats_clear: + # if we need to use up a clear, do that now + self._clear_to_send.clear() + + return eats_clear + def _send_loop(self): """ The send loop is responsible of sending commands in ``self._send_queue`` over the line, if it is cleared for @@ -3200,6 +3223,7 @@ class MachineCom(object): if linenumber is not None: # line number predetermined - this only happens for resends, so we'll use the number and # send directly without any processing (since that already took place on the first sending!) + self._use_up_clear(gcode) self._do_send_with_checksum(command.encode("ascii"), linenumber) else: @@ -3250,7 +3274,13 @@ class MachineCom(object): continue # now comes the part where we increase line numbers and send stuff - no turning back now + used_up_clear = self._use_up_clear(gcode) self._do_send(command, gcode=gcode) + if not used_up_clear: + # If we didn't use up a clear we need to tickle the read queue - there might + # not be a reply to this command, so our _monitor loop will stay waiting until + # timeout. We definitely do not want that, so we tickle the queue manually here + self._continue_sending() # trigger "sent" phase and use up one "ok" if on_sent is not None and callable(on_sent): @@ -3258,21 +3288,6 @@ class MachineCom(object): on_sent() self._process_command_phase("sent", command, command_type, gcode=gcode, subcode=subcode, tags=tags) - # we only need to use up a clear if the command we just sent was either a gcode command or if we also - # require ack's for unknown commands - use_up_clear = self._unknownCommandsNeedAck - if gcode is not None: - use_up_clear = True - - if use_up_clear: - # if we need to use up a clear, do that now - self._clear_to_send.clear() - else: - # Otherwise we need to tickle the read queue - there might not be a reply - # to this command, so our _monitor loop will stay waiting until timeout. We - # definitely do not want that, so we tickle the queue manually here - self._continue_sending() - finally: # no matter _how_ we exit this block, we signal that we # are done processing the last fetched queue entry @@ -3790,10 +3805,12 @@ class MachineCom(object): return self._logger.info(message) - self._do_send(cmd, gcode=gcode) # use up an ok since we will get one back for this command and don't want to get out of sync - self._clear_to_send.clear() + used_up_clear = self._use_up_clear(gcode) + self._do_send(cmd, gcode=gcode) + if not used_up_clear: + self._continue_sending() return None, diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index f8403d936..b16794ee0 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -64,36 +64,55 @@ class Vector3D(object): return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z) def __add__(self, other): - if isinstance(other, Vector3D): + try: + if len(other) == 3: + return Vector3D(self.x + other[0], + self.y + other[1], + self.z + other[2]) + except TypeError: + # doesn't look like a 3-tuple + pass + + try: return Vector3D(self.x + other.x, self.y + other.y, self.z + other.z) - elif isinstance(other, (tuple, list)) and len(other) == 3: - return Vector3D(self.x + other[0], - self.y + other[1], - self.z + other[2]) - else: - raise ValueError("other must be a Vector3D instance or a list or tuple of length 3") + except AttributeError: + # also doesn't look like a Vector3D + pass + + raise TypeError("other must be a Vector3D instance or a list or tuple of length 3") def __sub__(self, other): - if isinstance(other, Vector3D): + try: + if len(other) == 3: + return Vector3D(self.x - other[0], + self.y - other[1], + self.z - other[2]) + except TypeError: + # doesn't look like a 3-tuple + pass + + try: return Vector3D(self.x - other.x, self.y - other.y, self.z - other.z) - elif isinstance(other, (tuple, list)) and len(other) == 3: - return Vector3D(self.x - other[0], - self.y - other[1], - self.z - other[2]) - else: - raise ValueError("other must be a Vector3D instance or a list or tuple") + except AttributeError: + # also doesn't look like a Vector3D + pass + + raise TypeError("other must be a Vector3D instance or a list or tuple of length 3") def __mul__(self, other): - if isinstance(other, (int, float)): + try: return Vector3D(self.x * other, self.y * other, self.z * other) - else: - raise ValueError("other must be a float or int value") + except TypeError: + # doesn't look like a scalar + pass + + raise ValueError("other must be a float or int value") def __rmul__(self, other): return self.__mul__(other) @@ -344,11 +363,11 @@ class gcode(object): totalExtrusion[currentExtruder]) if currentExtruder == 0 and len(currentE) > 1 and duplicationMode: - # Copy first extruder length to other extruders + # Copy first extruder length to other extruders for i in range(1, len(currentE)): - totalExtrusion[i] += e - currentE[i] += e - maxExtrusion[i] = max(maxExtrusion[i], + totalExtrusion[i] += e + currentE[i] += e + maxExtrusion[i] = max(maxExtrusion[i], totalExtrusion[i]) else: e = 0.0 @@ -438,13 +457,13 @@ class gcode(object): else: fwrecoverTime = (fwretractDist + s) / f elif M == 605: #Duplication/Mirroring mode - s = getCodeInt(line, 'S') - if s in [2, 4, 5, 6]: - # Duplication / Mirroring mode selected. Printer firmware copies extrusion commands + s = getCodeInt(line, 'S') + if s in [2, 4, 5, 6]: + # Duplication / Mirroring mode selected. Printer firmware copies extrusion commands # from first extruder to all other extruders duplicationMode = True - else: - duplicationMode = False + else: + duplicationMode = False elif T is not None: if T > max_extruders: