Create fl0w user by default
This commit is contained in:
parent
5dfeee5977
commit
2d58f095bd
1 changed files with 44 additions and 25 deletions
|
@ -1,6 +1,6 @@
|
|||
from Highway import Route, Pipe, Client
|
||||
from Meh import Config, Option, ExceptionInConfigError
|
||||
import Logging
|
||||
import Config
|
||||
import Utils
|
||||
|
||||
import socket
|
||||
|
@ -10,29 +10,28 @@ import sys
|
|||
import subprocess
|
||||
from random import randint
|
||||
from _thread import start_new_thread
|
||||
from ctypes import cdll
|
||||
import threading
|
||||
import json
|
||||
|
||||
CHANNEL = 2
|
||||
IS_WALLABY = Utils.is_wallaby()
|
||||
PATH = "/home/root/Documents/KISS/bin/" if IS_WALLABY else (sys.argv[1] if len(sys.argv) > 1 else None)
|
||||
|
||||
PATH = os.path.abspath(PATH)
|
||||
|
||||
if PATH[-1] != "/":
|
||||
PATH = PATH + "/"
|
||||
|
||||
USERS_LOCATION = "/home/root/Documents/KISS/users.json"
|
||||
|
||||
LIB_WALLABY = "/usr/lib/libwallaby.so"
|
||||
WALLABY_PROGRAMS = "/root/Documents/KISS/bin/"
|
||||
|
||||
if not PATH:
|
||||
Logging.error("No path specified. (Necessary on simulated Wallaby controllers.)")
|
||||
exit(1)
|
||||
|
||||
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"]
|
||||
|
||||
|
||||
class SensorReadout:
|
||||
ANALOG = 1
|
||||
DIGITAL = 2
|
||||
|
@ -40,7 +39,7 @@ class SensorReadout:
|
|||
MODES = tuple(NAMED_MODES.keys())
|
||||
|
||||
|
||||
def __init__(self, handler, poll_rate=0.5):
|
||||
def __init__(self, handler, poll_rate=0.2):
|
||||
self.poll_rate = poll_rate
|
||||
self.handler = handler
|
||||
self.peer_lock = threading.Lock()
|
||||
|
@ -159,6 +158,7 @@ class Identify(Pipe):
|
|||
Logging.success("I was identified!")
|
||||
|
||||
|
||||
|
||||
class ListPrograms(Pipe):
|
||||
def run(self, data, peer, handler):
|
||||
programs = []
|
||||
|
@ -313,21 +313,40 @@ class Handler(Client):
|
|||
Logging.info("Unsubscribing '%s' from all sensor updates." % peer)
|
||||
self.routes["sensor"].sensor_readout.unsubscribe_all(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 has to be provided in dev-env.")
|
||||
exit(1)
|
||||
|
||||
if PATH[-1] != "/":
|
||||
PATH = PATH + "/"
|
||||
|
||||
CONFIG_PATH = "wallaby.cfg"
|
||||
|
||||
config = Config.Config()
|
||||
config.add(Config.Option("server_address", "ws://127.0.0.1:3077"))
|
||||
config.add(Config.Option("debug", False, validator=lambda x: True if True or False else False))
|
||||
config.add(Config.Option("output_unbuffer", "stdbuf"))
|
||||
config.add(Config.Option("identify_sound", "Wallaby/identify.wav",
|
||||
validator=lambda x: os.path.isfile(x)))
|
||||
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.read_from_file(CONFIG_PATH)
|
||||
except FileNotFoundError:
|
||||
config.write_to_file(CONFIG_PATH)
|
||||
config = config.read_from_file(CONFIG_PATH)
|
||||
config = config.load(CONFIG_PATH)
|
||||
except (IOError, ExceptionInConfigError):
|
||||
config.dump(CONFIG_PATH)
|
||||
config = config.load(CONFIG_PATH)
|
||||
|
||||
|
||||
try:
|
||||
|
|
Reference in a new issue