Renamed to debug_wallaby.py and added stub code for stop, restart and disconnect

This commit is contained in:
PhilipTrauner 2016-01-31 20:34:29 +01:00
parent e65657e83b
commit f3d288c1ca
2 changed files with 56 additions and 1 deletions

View file

@ -1 +0,0 @@
from Shared import ESock

56
debug_wallaby.py Normal file
View file

@ -0,0 +1,56 @@
import fl0w
from ESock import ESock
import Routing
import socket
import time
import os
import sys
class WallabyControl(Routing.ClientRoute):
def run(self, data, handler):
commands = {"stop" : self.stop, "restart" : self.restart, "disconnect" : self.disconnect}
if data in commands:
commands[data](handler)
def stop(self, handler):
print("Stop nyi")
def restart(self, handler):
self.disconnect(handler)
time.sleep(15)
os.execl(sys.executable, *([sys.executable]+sys.argv))
def disconnect(self, handler):
handler.sock.close()
class WallabyClient:
def __init__(self, host_port_pair, debug=False):
self.sock = ESock(socket.create_connection(host_port_pair), debug=debug)
self.connected = True
self.debug = debug
self.routes = {"wallaby_control" : WallabyControl()}
def start(self):
self.sock.send("w", "set_type")
while 1 and self.connected:
try:
data = self.sock.recv()
if data[1] in self.routes:
self.routes[data[1]].run(data[0], self)
except (OSError, socket.error):
self.connected = False
def stop(self):
self.sock.close()
wallaby_client = WallabyClient(("127.0.0.1", 3077))
try:
wallaby_client.start()
except KeyboardInterrupt:
wallaby_client.stop()