last fixes on shell command

This commit is contained in:
Vitor de Miranda Henrique
2018-06-18 15:07:45 -05:00
parent 97f74087a4
commit 20a5ca4566

View File

@@ -196,11 +196,14 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
return flask.jsonify(success=True)
@octoprint.plugin.BlueprintPlugin.route("/sendShellCommand", methods=["GET"])
def send_send_shell_command(self):
def 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()
self.send_gcode_command(rpi_output['shell_script'])
command = rpi_output['shell_script']
self.shell_command(command)
return flask.jsonify(success=True)
@octoprint.plugin.BlueprintPlugin.route("/setAutoStartUp", methods=["GET"])
@@ -290,19 +293,6 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
return flask.jsonify(success=True)
def send_shell_command(self, command):
try:
stdout = (Popen(command, shell=True, stdout=PIPE).stdout).read()
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(
self._identifier, dict(is_msg=True, msg="Could not execute shell script", msg_type="error"))
def send_neopixel_command(self, led_pin, led_count, led_brightness, red, green, blue, address,
neopixel_dirrect, index_id, queue_id=None):
"""Send neopixel command
@@ -1057,6 +1047,16 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
self.log_error(ex)
pass
def 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"))
except Exception as ex:
self.log_error(ex)
self._plugin_manager.send_plugin_message(
self._identifier, dict(is_msg=True, msg="Could not execute shell script", msg_type="error"))
def handle_gpio_control(self, channel):
try:
if self._settings.get(["debug"]) is True: