Unfinished; added GetInfo, initial support for new WallabyControl
This commit is contained in:
parent
1ee65798b0
commit
2ef7a5c1c1
1 changed files with 31 additions and 11 deletions
|
@ -1,23 +1,31 @@
|
||||||
import fl0w
|
|
||||||
from ESock import ESock
|
from ESock import ESock
|
||||||
from Sync import SyncClient
|
from Sync import SyncClient
|
||||||
import Routing
|
import Routing
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import platform
|
||||||
|
|
||||||
|
CHANNEL = "w"
|
||||||
|
IS_WALLABY = True if "ARMv7" in platform.uname().version.lower() else False
|
||||||
|
|
||||||
class WallabyControl(Routing.ClientRoute):
|
class WallabyControl(Routing.ClientRoute):
|
||||||
|
def __init__(self):
|
||||||
|
self.actions_with_params = {"stop" : self.stop, "run" : self.run}
|
||||||
|
self.actions_without_params = {"restart" : self.restart, "disconnect" : self.disconnect,
|
||||||
|
"reboot" : self.reboot, "shutdown" : self.shutdown}
|
||||||
|
|
||||||
def run(self, data, handler):
|
def run(self, data, handler):
|
||||||
commands = {"stop" : self.stop, "restart" : self.restart,
|
if data in self.actions_without_params.keys():
|
||||||
"disconnect" : self.disconnect, "reboot" : self.reboot,
|
self.actions_without_params[action](handler)
|
||||||
"shutdown" : self.shutdown}
|
elif type(data[address_pair]) is dict:
|
||||||
if data in commands:
|
if action in self.actions_with_params.keys():
|
||||||
commands[data](handler)
|
self.actions_without_params[action](data[action], handler)
|
||||||
|
|
||||||
def stop(self, handler):
|
def stop(self, handler):
|
||||||
print("Stop nyi")
|
os.system("killall -s 2 botball_user_program")
|
||||||
|
|
||||||
def restart(self, handler):
|
def restart(self, handler):
|
||||||
self.disconnect(handler)
|
self.disconnect(handler)
|
||||||
|
@ -35,6 +43,15 @@ class WallabyControl(Routing.ClientRoute):
|
||||||
handler.sock.close()
|
handler.sock.close()
|
||||||
|
|
||||||
|
|
||||||
|
class GetInfo(Routing.ClientRoute):
|
||||||
|
def run(self, data, handler):
|
||||||
|
if data == "":
|
||||||
|
handler.sock.send({"type" : CHANNEL, "name" : platform.node()}, "get_info")
|
||||||
|
elif "name" in data:
|
||||||
|
if IS_WALLABY:
|
||||||
|
open("/etc/hostname", "w").write(str(data["name"]))
|
||||||
|
else:
|
||||||
|
Logging.info("Hostname change: '%s'" % str(data["name"]))
|
||||||
|
|
||||||
|
|
||||||
class WallabyClient:
|
class WallabyClient:
|
||||||
|
@ -42,17 +59,20 @@ class WallabyClient:
|
||||||
self.sock = ESock(socket.create_connection(host_port_pair), debug=debug)
|
self.sock = ESock(socket.create_connection(host_port_pair), debug=debug)
|
||||||
self.connected = True
|
self.connected = True
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.sync = SyncClient(self.sock, sys.argv[1], "w_sync")
|
self.sync = SyncClient(self.sock, sys.argv[1], "w_sync", debug=True)
|
||||||
self.routes = {"wallaby_control" : WallabyControl(), "w_sync" : self.sync}
|
self.routes = {"wallaby_control" : WallabyControl(), "w_sync" : self.sync,
|
||||||
|
"get_info" : GetInfo()}
|
||||||
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.sock.send("w", "set_type")
|
|
||||||
self.sync.start()
|
self.sync.start()
|
||||||
while 1 and self.connected:
|
while 1 and self.connected:
|
||||||
data = self.sock.recv()
|
data = self.sock.recv()
|
||||||
|
try:
|
||||||
if data[1] in self.routes:
|
if data[1] in self.routes:
|
||||||
self.routes[data[1]].run(data[0], self)
|
self.routes[data[1]].run(data[0], self)
|
||||||
|
except Exception as e:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
|
Reference in a new issue