Removed Compile route and behem0th, updated dashb0ard path
This commit is contained in:
parent
90e15a8c14
commit
ae93513fb8
1 changed files with 5 additions and 53 deletions
|
@ -14,63 +14,22 @@ from wsgiref.simple_server import make_server
|
||||||
from ws4py.server.wsgirefserver import WSGIServer, WebSocketWSGIRequestHandler
|
from ws4py.server.wsgirefserver import WSGIServer, WebSocketWSGIRequestHandler
|
||||||
from ws4py.server.wsgiutils import WebSocketWSGIApplication
|
from ws4py.server.wsgiutils import WebSocketWSGIApplication
|
||||||
|
|
||||||
import behem0th
|
|
||||||
from bottle.bottle import route, run, static_file
|
from bottle.bottle import route, run, static_file
|
||||||
|
|
||||||
|
|
||||||
@route("/")
|
@route("/")
|
||||||
def index():
|
def index():
|
||||||
return static_file("index.html", root="Shared/dashb1ard")
|
return static_file("index.html", root="Shared/dashb0ard")
|
||||||
|
|
||||||
@route("/static/<filepath:path>")
|
@route("/static/<filepath:path>")
|
||||||
def static(filepath):
|
def static(filepath):
|
||||||
return static_file(filepath, root="Shared/dashb1ard/static")
|
return static_file(filepath, root="Shared/dashb0ard/static")
|
||||||
|
|
||||||
class Info(Route):
|
class Info(Route):
|
||||||
def run(self, data, handler):
|
def run(self, data, handler):
|
||||||
handler.send({"routes" : list(handler.routes.keys())}, "info")
|
handler.send({"routes" : list(handler.routes.keys())}, "info")
|
||||||
|
|
||||||
|
|
||||||
class Compile:
|
|
||||||
HAS_MAIN = re.compile(r"\w*\s*main\(\)\s*(\{|.*)$")
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def is_valid_c_program(path):
|
|
||||||
for line in open(path, "r").read().split("\n"):
|
|
||||||
if Compile.HAS_MAIN.match(line):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, source_path, binary_path):
|
|
||||||
self.source_path = os.path.abspath(source_path) + "/"
|
|
||||||
self.binary_path = os.path.abspath(binary_path) + "/"
|
|
||||||
self.wallaby_library_avaliable = os.path.isfile("/usr/local/lib/libaurora.so") and os.path.isfile("/usr/local/lib/libdaylite.so")
|
|
||||||
if not self.wallaby_library_avaliable:
|
|
||||||
Logging.warning("Wallaby library not found. All Wallaby functions are unavaliable.")
|
|
||||||
if platform.machine() != "armv7l":
|
|
||||||
Logging.warning("Wrong processor architecture! Generated binaries will not run on Wallaby Controllers.")
|
|
||||||
|
|
||||||
|
|
||||||
def compile(self, path, relpath, handler=None):
|
|
||||||
if relpath.endswith(".c") and Compile.is_valid_c_program(path + relpath):
|
|
||||||
name = "-".join(relpath.split("/")).rstrip(".c")
|
|
||||||
full_path = self.binary_path + name
|
|
||||||
if not os.path.exists(full_path):
|
|
||||||
os.mkdir(full_path)
|
|
||||||
error = True
|
|
||||||
command = ["gcc", "-pipe", "-O0", "-lwallaby", "-I%s" % self.source_path, "-o", "%s" % full_path + "/botball_user_program", path + relpath]
|
|
||||||
if not self.wallaby_library_avaliable:
|
|
||||||
del command[command.index("-lwallaby")]
|
|
||||||
p = Popen(command, stdout=PIPE, stderr=PIPE)
|
|
||||||
error = False if p.wait() == 0 else True
|
|
||||||
result = ""
|
|
||||||
for line in p.communicate():
|
|
||||||
result += line.decode()
|
|
||||||
if handler != None:
|
|
||||||
handler.send({"failed" : error, "returned" : result, "relpath" : relpath}, self.handler.reverse_routes[self])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Subscribe(Route):
|
class Subscribe(Route):
|
||||||
EDITOR = 1
|
EDITOR = 1
|
||||||
|
@ -237,8 +196,6 @@ server.set_app(WebSocketWSGIApplication(handler_cls=Handler,
|
||||||
"peers" : Peers(),
|
"peers" : Peers(),
|
||||||
"sensor" : DummyPipe(),
|
"sensor" : DummyPipe(),
|
||||||
"identify" : DummyPipe(),
|
"identify" : DummyPipe(),
|
||||||
"list_programs" : DummyPipe(),
|
|
||||||
"run_program" : DummyPipe(),
|
|
||||||
"std_stream" : DummyPipe(),
|
"std_stream" : DummyPipe(),
|
||||||
"stop_programs" : DummyPipe(),
|
"stop_programs" : DummyPipe(),
|
||||||
"shutdown" : DummyPipe(),
|
"shutdown" : DummyPipe(),
|
||||||
|
@ -246,12 +203,8 @@ server.set_app(WebSocketWSGIApplication(handler_cls=Handler,
|
||||||
"output" : DummyPipe()}}))
|
"output" : DummyPipe()}}))
|
||||||
|
|
||||||
|
|
||||||
sync_client = behem0th.Client(path=config.path, verbose_log=config.debug)
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Logging.header("Server loop starting.")
|
Logging.header("Server loop starting.")
|
||||||
sync_client.listen()
|
|
||||||
start_new_thread(run, (), {"host" : config.dashb0ard_address[0],
|
start_new_thread(run, (), {"host" : config.dashb0ard_address[0],
|
||||||
"port" : config.dashb0ard_address[1], "quiet" : True})
|
"port" : config.dashb0ard_address[1], "quiet" : True})
|
||||||
Logging.info("Starting dashb0ard on 'http://%s:%d'" % (config.dashb0ard_address[0],
|
Logging.info("Starting dashb0ard on 'http://%s:%d'" % (config.dashb0ard_address[0],
|
||||||
|
@ -262,5 +215,4 @@ try:
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
Logging.header("Gracefully shutting down server.")
|
Logging.header("Gracefully shutting down server.")
|
||||||
server.server_close()
|
server.server_close()
|
||||||
sync_client.close()
|
|
||||||
Logging.success("Server shutdown successful.")
|
Logging.success("Server shutdown successful.")
|
||||||
|
|
Reference in a new issue