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 re
|
||||
|
||||
from behem0th import Client as SyncClient
|
||||
from behem0th import EventHandler
|
||||
|
||||
CHANNEL = 2
|
||||
IS_WALLABY = Utils.is_wallaby()
|
||||
|
||||
USERS_LOCATION = "/home/root/Documents/KISS/users.json"
|
||||
LIB_WALLABY = "/usr/lib/libwallaby.so"
|
||||
|
||||
CONFIG_PATH = "wallaby.cfg"
|
||||
|
||||
if not IS_WALLABY:
|
||||
Logging.warning("Binaries that were created for Wallaby Controllers will not run on a simulated Wallaby.")
|
||||
|
||||
|
||||
def get_users():
|
||||
if IS_WALLABY:
|
||||
return list(json.loads(open(USERS_LOCATION, "r").read()).keys())
|
||||
return ["Default User"]
|
||||
config = Config()
|
||||
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",
|
||||
validator=lambda sound: os.path.isfile(sound)))
|
||||
|
||||
|
||||
class SensorReadout:
|
||||
|
@ -157,22 +152,7 @@ class SensorReadout:
|
|||
class Identify(Pipe):
|
||||
def run(self, data, peer, handler):
|
||||
Utils.play_sound(config.identify_sound)
|
||||
if handler.debug:
|
||||
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)
|
||||
Logging.success("I was identified!")
|
||||
|
||||
|
||||
class StopPrograms(Pipe):
|
||||
|
@ -255,18 +235,6 @@ class Sensor(Pipe):
|
|||
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):
|
||||
|
@ -298,21 +266,6 @@ class WhoAmI(Route):
|
|||
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):
|
||||
def run(self, data, peer, handler):
|
||||
|
@ -373,7 +326,7 @@ class Output(Pipe):
|
|||
|
||||
class Handler(Client):
|
||||
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):
|
||||
|
@ -383,40 +336,6 @@ class Handler(Client):
|
|||
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:
|
||||
config = config.load(CONFIG_PATH)
|
||||
except (IOError, ExceptionInConfigError):
|
||||
|
@ -427,19 +346,12 @@ except (IOError, ExceptionInConfigError):
|
|||
try:
|
||||
ws = Handler(config.server_address)
|
||||
# setup has to be called before the connection is established
|
||||
ws.setup({"subscribe" : Subscribe(), "hostname" : Hostname(),
|
||||
"processes" : Processes(), "sensor" : Sensor(),
|
||||
"identify" : Identify(), "list_programs" : ListPrograms(),
|
||||
"whoami" : WhoAmI(), "run_program" : RunProgram(config.output_unbuffer),
|
||||
ws.setup({"subscribe" : Subscribe(), "sensor" : Sensor(),
|
||||
"identify" : Identify(), "whoami" : WhoAmI(),
|
||||
"stop_programs" : StopPrograms(), "shutdown" : Shutdown(),
|
||||
"reboot" : Reboot(), "binary_received" : BinaryReceived(),
|
||||
"output" : Output()},
|
||||
debug=config.debug)
|
||||
"reboot" : Reboot(), "output" : Output()},
|
||||
debug=False)
|
||||
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()
|
||||
except KeyboardInterrupt:
|
||||
ws.close()
|
||||
#sync_client.close()
|
Reference in a new issue