Added program output streaming
This commit is contained in:
parent
d2fd0b4479
commit
6d14dacaa7
1 changed files with 30 additions and 12 deletions
|
@ -2,6 +2,7 @@ from ESock import ESock
|
||||||
from Sync import SyncClient
|
from Sync import SyncClient
|
||||||
from Utils import is_socket_related_error
|
from Utils import is_socket_related_error
|
||||||
from Utils import capture_trace
|
from Utils import capture_trace
|
||||||
|
from Utils import is_wallaby
|
||||||
import Routing
|
import Routing
|
||||||
import Logging
|
import Logging
|
||||||
|
|
||||||
|
@ -10,9 +11,10 @@ import time
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import platform
|
import platform
|
||||||
|
import subprocess
|
||||||
|
|
||||||
CHANNEL = "w"
|
CHANNEL = "w"
|
||||||
IS_WALLABY = True if "ARMv7" in platform.uname().version.lower() else False
|
IS_WALLABY = is_wallaby()
|
||||||
PATH = "/home/root/Documents/KISS/" if IS_WALLABY else sys.argv[1]
|
PATH = "/home/root/Documents/KISS/" if IS_WALLABY else sys.argv[1]
|
||||||
|
|
||||||
class WallabyControl(Routing.ClientRoute):
|
class WallabyControl(Routing.ClientRoute):
|
||||||
|
@ -25,9 +27,28 @@ class WallabyControl(Routing.ClientRoute):
|
||||||
if type(data) is str:
|
if type(data) is str:
|
||||||
if data in self.actions_without_params.keys():
|
if data in self.actions_without_params.keys():
|
||||||
self.actions_without_params[data](handler)
|
self.actions_without_params[data](handler)
|
||||||
elif type(data[address_pair]) is dict:
|
elif type(data) is dict:
|
||||||
if action in self.actions_with_params.keys():
|
for action in data:
|
||||||
self.actions_without_params[action](handler, data[action])
|
print(action)
|
||||||
|
if action in self.actions_with_params.keys():
|
||||||
|
self.actions_with_params[action](handler, data[action])
|
||||||
|
|
||||||
|
|
||||||
|
def run_program(self, handler, program):
|
||||||
|
if not IS_WALLABY:
|
||||||
|
command = ["gstdbuf", "-i0", "-o0", "-e0"]
|
||||||
|
else:
|
||||||
|
command = ["stdbuf", "-i0", "-o0", "-e0"]
|
||||||
|
command.append("./%s%s/botball_user_program" % (handler.sync.folder, program))
|
||||||
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
|
# Poll process for new output until finished
|
||||||
|
for line in iter(process.stdout.readline, b""):
|
||||||
|
handler.sock.send(line.decode(), "std_stream")
|
||||||
|
print(line)
|
||||||
|
|
||||||
|
process.wait()
|
||||||
|
handler.sock.send({"return_code" : process.returncode}, "std_stream")
|
||||||
|
|
||||||
|
|
||||||
def stop(self, handler):
|
def stop(self, handler):
|
||||||
|
@ -35,13 +56,6 @@ class WallabyControl(Routing.ClientRoute):
|
||||||
os.system("killall -s 2 botball_user_program")
|
os.system("killall -s 2 botball_user_program")
|
||||||
|
|
||||||
|
|
||||||
def run_program(self, handler, program):
|
|
||||||
# WIP: Subprocess with unbuffered stdout required for output streaming
|
|
||||||
print(handler)
|
|
||||||
print(program)
|
|
||||||
os.system("./%s%s" % (handler.sync.folder, program))
|
|
||||||
|
|
||||||
|
|
||||||
def restart(self, handler):
|
def restart(self, handler):
|
||||||
Logging.warning("Restart not implemented yet.")
|
Logging.warning("Restart not implemented yet.")
|
||||||
|
|
||||||
|
@ -57,10 +71,14 @@ class WallabyControl(Routing.ClientRoute):
|
||||||
handler.sock.close()
|
handler.sock.close()
|
||||||
|
|
||||||
|
|
||||||
|
def get_wallaby_hostname():
|
||||||
|
return open("/etc/hostname", "r").read()
|
||||||
|
|
||||||
class GetInfo(Routing.ClientRoute):
|
class GetInfo(Routing.ClientRoute):
|
||||||
def run(self, data, handler):
|
def run(self, data, handler):
|
||||||
if data == "":
|
if data == "":
|
||||||
handler.sock.send({"type" : CHANNEL, "name" : platform.node()}, "get_info")
|
handler.sock.send({"type" : CHANNEL,
|
||||||
|
"name" : platform.node() if not IS_WALLABY else get_wallaby_hostname()}, "get_info")
|
||||||
elif "name" in data:
|
elif "name" in data:
|
||||||
if IS_WALLABY:
|
if IS_WALLABY:
|
||||||
open("/etc/hostname", "w").write(str(data["name"]))
|
open("/etc/hostname", "w").write(str(data["name"]))
|
||||||
|
|
Reference in a new issue