Skip to content

Commit

Permalink
last fixes on shell command
Browse files Browse the repository at this point in the history
  • Loading branch information
vitormhenrique committed Jun 18, 2018
1 parent 97f7408 commit 20a5ca4
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions octoprint_enclosure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,14 @@ def set_io(self):
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"])
Expand Down Expand Up @@ -290,19 +293,6 @@ def set_neopixel(self):

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
Expand Down Expand Up @@ -1057,6 +1047,16 @@ def handle_initial_gpio_control(self):
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:
Expand Down

0 comments on commit 20a5ca4

Please sign in to comment.