Removed fl0w-proper bootstrapping code, unneeded routes
This commit is contained in:
parent
7fc4a0697b
commit
90e15a8c14
1 changed files with 14 additions and 102 deletions
|
@ -15,24 +15,19 @@ import threading
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from behem0th import Client as SyncClient
|
|
||||||
from behem0th import EventHandler
|
|
||||||
|
|
||||||
CHANNEL = 2
|
CHANNEL = 2
|
||||||
IS_WALLABY = Utils.is_wallaby()
|
IS_WALLABY = Utils.is_wallaby()
|
||||||
|
|
||||||
USERS_LOCATION = "/home/root/Documents/KISS/users.json"
|
|
||||||
LIB_WALLABY = "/usr/lib/libwallaby.so"
|
LIB_WALLABY = "/usr/lib/libwallaby.so"
|
||||||
|
|
||||||
|
CONFIG_PATH = "wallaby.cfg"
|
||||||
|
|
||||||
if not IS_WALLABY:
|
config = Config()
|
||||||
Logging.warning("Binaries that were created for Wallaby Controllers will not run on a simulated Wallaby.")
|
config.add(Option("server_address", "ws://127.0.0.1:3077"))
|
||||||
|
config.add(Option("output_unbuffer", "stdbuf"))
|
||||||
|
config.add(Option("identify_sound", "Wallaby/identify.wav",
|
||||||
def get_users():
|
validator=lambda sound: os.path.isfile(sound)))
|
||||||
if IS_WALLABY:
|
|
||||||
return list(json.loads(open(USERS_LOCATION, "r").read()).keys())
|
|
||||||
return ["Default User"]
|
|
||||||
|
|
||||||
|
|
||||||
class SensorReadout:
|
class SensorReadout:
|
||||||
|
@ -157,22 +152,7 @@ class SensorReadout:
|
||||||
class Identify(Pipe):
|
class Identify(Pipe):
|
||||||
def run(self, data, peer, handler):
|
def run(self, data, peer, handler):
|
||||||
Utils.play_sound(config.identify_sound)
|
Utils.play_sound(config.identify_sound)
|
||||||
if handler.debug:
|
Logging.success("I was identified!")
|
||||||
Logging.success("I was identified!")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ListPrograms(Pipe):
|
|
||||||
def run(self, data, peer, handler):
|
|
||||||
programs = []
|
|
||||||
if os.path.isdir(PATH):
|
|
||||||
for program in os.listdir(PATH):
|
|
||||||
if "botball_user_program" in os.listdir(PATH + program):
|
|
||||||
programs.append(program)
|
|
||||||
else:
|
|
||||||
Logging.error("Harrogate folder structure does not exist. "
|
|
||||||
"You broke something, mate.")
|
|
||||||
handler.pipe(programs, handler.reverse_routes[self], peer)
|
|
||||||
|
|
||||||
|
|
||||||
class StopPrograms(Pipe):
|
class StopPrograms(Pipe):
|
||||||
|
@ -255,18 +235,6 @@ class Sensor(Pipe):
|
||||||
self.sensor_readout = SensorReadout(handler)
|
self.sensor_readout = SensorReadout(handler)
|
||||||
|
|
||||||
|
|
||||||
class BinaryReceived(Pipe, EventHandler):
|
|
||||||
def on_modified(self, event):
|
|
||||||
print(event)
|
|
||||||
|
|
||||||
|
|
||||||
def on_created(self, event):
|
|
||||||
print(event)
|
|
||||||
|
|
||||||
|
|
||||||
def start(self, handler):
|
|
||||||
self.handler = handler
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Shutdown(Pipe):
|
class Shutdown(Pipe):
|
||||||
|
@ -298,21 +266,6 @@ class WhoAmI(Route):
|
||||||
handler.send(None, "whoami")
|
handler.send(None, "whoami")
|
||||||
|
|
||||||
|
|
||||||
class Hostname(Pipe):
|
|
||||||
def run(self, data, peer, handler):
|
|
||||||
if type(data) is dict:
|
|
||||||
if "set" in data:
|
|
||||||
try:
|
|
||||||
Utils.set_hostname(str(data["set"]))
|
|
||||||
except Utils.HostnameNotChangedError:
|
|
||||||
if IS_WALLABY:
|
|
||||||
Logging.error("Hostname change unsuccessful. "
|
|
||||||
"Something is wrong with your Wallaby.")
|
|
||||||
else:
|
|
||||||
Logging.warning("Hostname change unsuccessful. "
|
|
||||||
"This seems to be a dev-system, so don't worry too "
|
|
||||||
"much about it.")
|
|
||||||
|
|
||||||
|
|
||||||
class Processes(Pipe):
|
class Processes(Pipe):
|
||||||
def run(self, data, peer, handler):
|
def run(self, data, peer, handler):
|
||||||
|
@ -354,7 +307,7 @@ class Output(Pipe):
|
||||||
|
|
||||||
def unsubscribe(self, peer):
|
def unsubscribe(self, peer):
|
||||||
if peer in self.subscribers:
|
if peer in self.subscribers:
|
||||||
del self.subscribers[self.subscribers.index(peer)]
|
del self.subscribers[self.subscribers.index(peer)]
|
||||||
|
|
||||||
class Std:
|
class Std:
|
||||||
def __init__(self, old_std, write_callback):
|
def __init__(self, old_std, write_callback):
|
||||||
|
@ -373,7 +326,7 @@ class Output(Pipe):
|
||||||
|
|
||||||
class Handler(Client):
|
class Handler(Client):
|
||||||
def setup(self, routes, debug=False):
|
def setup(self, routes, debug=False):
|
||||||
super().setup(routes, debug_suppress_routes=["pipe"], debug=debug)
|
super().setup(routes, debug=debug)
|
||||||
|
|
||||||
|
|
||||||
def peer_unavaliable(self, peer):
|
def peer_unavaliable(self, peer):
|
||||||
|
@ -383,40 +336,6 @@ class Handler(Client):
|
||||||
self.routes["output"].unsubscribe(peer)
|
self.routes["output"].unsubscribe(peer)
|
||||||
|
|
||||||
|
|
||||||
if IS_WALLABY:
|
|
||||||
if not "fl0w" in get_users():
|
|
||||||
json.loads(open(USERS_LOCATION, "r").read())["fl0w"] = {"mode" : "Advanced"}
|
|
||||||
try:
|
|
||||||
os.mkdir(FL0W_USER_PATH)
|
|
||||||
except FileExistsError:
|
|
||||||
pass
|
|
||||||
PATH = FL0W_USER_PATH + "bin/"
|
|
||||||
else:
|
|
||||||
if len(sys.argv) == 2:
|
|
||||||
if os.path.exists(sys.argv[1]):
|
|
||||||
PATH = os.path.abspath(sys.argv[1])
|
|
||||||
else:
|
|
||||||
Logging.error("Location does not exist.")
|
|
||||||
exit(1)
|
|
||||||
else:
|
|
||||||
Logging.error("Location has to be provided in dev-env.")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
if PATH[-1] != "/":
|
|
||||||
PATH = PATH + "/"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CONFIG_PATH = "wallaby.cfg"
|
|
||||||
|
|
||||||
config = Config()
|
|
||||||
config.add(Option("server_address", "ws://127.0.0.1:3077"))
|
|
||||||
config.add(Option("debug", True, validator=lambda x: True if True or False else False))
|
|
||||||
config.add(Option("output_unbuffer", "stdbuf"))
|
|
||||||
config.add(Option("identify_sound", "Wallaby/identify.wav",
|
|
||||||
validator=lambda sound: os.path.isfile(sound)))
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = config.load(CONFIG_PATH)
|
config = config.load(CONFIG_PATH)
|
||||||
except (IOError, ExceptionInConfigError):
|
except (IOError, ExceptionInConfigError):
|
||||||
|
@ -427,19 +346,12 @@ except (IOError, ExceptionInConfigError):
|
||||||
try:
|
try:
|
||||||
ws = Handler(config.server_address)
|
ws = Handler(config.server_address)
|
||||||
# setup has to be called before the connection is established
|
# setup has to be called before the connection is established
|
||||||
ws.setup({"subscribe" : Subscribe(), "hostname" : Hostname(),
|
ws.setup({"subscribe" : Subscribe(), "sensor" : Sensor(),
|
||||||
"processes" : Processes(), "sensor" : Sensor(),
|
"identify" : Identify(), "whoami" : WhoAmI(),
|
||||||
"identify" : Identify(), "list_programs" : ListPrograms(),
|
|
||||||
"whoami" : WhoAmI(), "run_program" : RunProgram(config.output_unbuffer),
|
|
||||||
"stop_programs" : StopPrograms(), "shutdown" : Shutdown(),
|
"stop_programs" : StopPrograms(), "shutdown" : Shutdown(),
|
||||||
"reboot" : Reboot(), "binary_received" : BinaryReceived(),
|
"reboot" : Reboot(), "output" : Output()},
|
||||||
"output" : Output()},
|
debug=False)
|
||||||
debug=config.debug)
|
|
||||||
ws.connect()
|
ws.connect()
|
||||||
sync_client = SyncClient(path=PATH, verbose_log=config.debug,
|
|
||||||
event_handler=ws.routes["binary_received"])
|
|
||||||
sync_client.connect(Utils.get_ip_from_url(config.server_address))
|
|
||||||
ws.run_forever()
|
ws.run_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
ws.close()
|
ws.close()
|
||||||
#sync_client.close()
|
|
Reference in a new issue