Renamed and moved Wallaby files
This commit is contained in:
parent
7959148e0f
commit
ff2955da0e
3 changed files with 2 additions and 0 deletions
56
Wallaby/Wallaby.py
Normal file
56
Wallaby/Wallaby.py
Normal 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()
|
Reference in a new issue