This repository has been archived on 2025-06-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fl0w-old/Wallaby/Wallaby.py
2016-02-04 20:34:05 +01:00

56 lines
No EOL
1.2 KiB
Python

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()