From 8a284caaa221195d93a30f165ba94faa1ee6d51b Mon Sep 17 00:00:00 2001 From: Vitor de Miranda Henrique Date: Fri, 15 Jun 2018 14:23:22 -0500 Subject: [PATCH] improved msg when sending shell scripts --- octoprint_enclosure/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index f6b1aca..aa227d7 100644 --- a/octoprint_enclosure/__init__.py +++ b/octoprint_enclosure/__init__.py @@ -194,7 +194,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, return flask.jsonify(success=True) @octoprint.plugin.BlueprintPlugin.route("/sendShellCommand", methods=["GET"]) - def send_shell_command(self): + def send_send_shell_command(self): output_index = self.to_int(flask.request.values["index_id"]) rpi_output = [r_out for r_out in self.rpi_outputs if self.to_int( r_out['index_id']) == output_index].pop() @@ -289,11 +289,13 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, return flask.jsonify(success=True) - def shell_command(self, command): + def send_shell_command(self, command): try: stdout = (Popen(command, shell=True, stdout=PIPE).stdout).read() - self._plugin_manager.send_plugin_message( - self._identifier, dict(is_msg=True, msg=stdout, msg_type="success")) + + response = stdout or "Command executed with no return value." + + self._plugin_manager.send_plugin_message(self._identifier, dict(is_msg=True, msg=response, msg_type="success")) except Exception as ex: self.log_error(ex) self._plugin_manager.send_plugin_message( @@ -1056,7 +1058,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, self.send_notification(msg) if rpi_output['output_type'] == 'shell_output': command = rpi_output['shell_script'] - self.shell_command(command) + self.send_shell_command(command) self.log_error(ex) pass