Fixed Compile route, refactoring, removed routing hacks, renamed GetInfo
GetInfo is now Subscribe, subclasses changed to unified Route and Web client added to Subscribe route.
This commit is contained in:
parent
6212ebed5b
commit
07031d719c
1 changed files with 25 additions and 36 deletions
|
@ -2,7 +2,6 @@ import Logging
|
||||||
import Routing
|
import Routing
|
||||||
import Config
|
import Config
|
||||||
|
|
||||||
#from .AsyncServer import Server
|
|
||||||
from .Broadcast import Broadcast
|
from .Broadcast import Broadcast
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
@ -19,20 +18,13 @@ from ws4py.server.wsgiutils import WebSocketWSGIApplication
|
||||||
|
|
||||||
from Highway import Server
|
from Highway import Server
|
||||||
|
|
||||||
"""
|
|
||||||
WALLABY_SYNC_ROUTE = "w_sync"
|
|
||||||
SUBLIME_SYNC_ROUTE = "s_sync"
|
|
||||||
"""
|
|
||||||
|
|
||||||
class Info(Routing.ServerRoute):
|
class Info(Routing.Route):
|
||||||
def run(self, data, handler):
|
def run(self, data, handler):
|
||||||
handler.send({"editor" : len(handler.broadcast.channels[Handler.Channels.EDITOR]),
|
handler.send({"routes" : list(handler.routes.keys())}, "info")
|
||||||
"wallaby" : len(handler.broadcast.channels[Handler.Channels.WALLABY]),
|
|
||||||
"routes" : list(handler.routes.keys())}, "info")
|
|
||||||
|
|
||||||
|
|
||||||
class Compile:
|
class Compile:
|
||||||
REQUIRED = [Routing.ROUTE]
|
|
||||||
HAS_MAIN = re.compile(r"\w*\s*main\(\)\s*(\{|.*)$")
|
HAS_MAIN = re.compile(r"\w*\s*main\(\)\s*(\{|.*)$")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -69,11 +61,11 @@ class Compile:
|
||||||
for line in p.communicate():
|
for line in p.communicate():
|
||||||
result += line.decode()
|
result += line.decode()
|
||||||
if handler != None:
|
if handler != None:
|
||||||
handler.send({"failed" : error, "returned" : result, "relpath" : relpath}, self.route)
|
handler.send({"failed" : error, "returned" : result, "relpath" : relpath}, self.handler.reverse_routes[self])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class StdStream(Routing.ServerRoute):
|
class StdStream(Routing.Route):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.stream_to = {}
|
self.stream_to = {}
|
||||||
|
|
||||||
|
@ -88,34 +80,32 @@ class StdStream(Routing.ServerRoute):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GetInfo(Routing.ServerRoute):
|
class Subscribe(Routing.Route):
|
||||||
EDITOR = "e"
|
EDITOR = 1
|
||||||
WALLABY = "w"
|
WALLABY = 2
|
||||||
|
WEB = 3
|
||||||
|
CHANNELS = [EDITOR, WALLABY, WEB]
|
||||||
|
|
||||||
def run(self, data, handler):
|
def run(self, data, handler):
|
||||||
if "type" in data:
|
if "type" in data:
|
||||||
if data["type"] == GetInfo.EDITOR:
|
if data["type"] == Subscribe.EDITOR:
|
||||||
handler.channel = Handler.Channels.EDITOR
|
handler.channel = Subscribe.EDITOR
|
||||||
handler.broadcast.add(handler, handler.channel)
|
handler.broadcast.add(handler, handler.channel)
|
||||||
elif data["type"] == GetInfo.WALLABY:
|
elif data["type"] == Subscribe.WALLABY:
|
||||||
handler.channel = Handler.Channels.WALLABY
|
handler.channel = Subscribe.Channels.WALLABY
|
||||||
handler.broadcast.add(handler, handler.channel)
|
handler.broadcast.add(handler, handler.channel)
|
||||||
if "name" in data:
|
elif data["type"] == Subscribe.WEB:
|
||||||
handler.name = data["name"]
|
handler.channel = Subscribe.Channels.WEB
|
||||||
|
handler.broadcast.add(handler, handler.channel)
|
||||||
|
if handler.debug:
|
||||||
Logging.info("'%s:%d' has identified as a %s client." % (handler.info[0], handler.info[1],
|
Logging.info("'%s:%d' has identified as a %s client." % (handler.info[0], handler.info[1],
|
||||||
"Editor" if handler.channel == Handler.Channels.EDITOR else
|
"Editor" if handler.channel == Subscribe.EDITOR else
|
||||||
"Wallaby" if handler.channel == Handler.Channels.WALLABY else
|
"Wallaby" if handler.channel == Subscribe.WALLABY else
|
||||||
|
"Web" if handler.channel == Subscribe.WEB else
|
||||||
"Unknown (will not subscribe to broadcast)"))
|
"Unknown (will not subscribe to broadcast)"))
|
||||||
|
|
||||||
def start(self, handler):
|
|
||||||
handler.send(None, handler.reverse_routes[self])
|
|
||||||
|
|
||||||
|
|
||||||
class Handler(Server):
|
class Handler(Server):
|
||||||
class Channels:
|
|
||||||
EDITOR = 1
|
|
||||||
WALLABY = 2
|
|
||||||
|
|
||||||
def setup(self, routes, broadcast, compression_level, debug=False):
|
def setup(self, routes, broadcast, compression_level, debug=False):
|
||||||
super().setup(routes, compression_level, debug=debug)
|
super().setup(routes, compression_level, debug=debug)
|
||||||
self.broadcast = broadcast
|
self.broadcast = broadcast
|
||||||
|
@ -161,9 +151,8 @@ except FileNotFoundError:
|
||||||
|
|
||||||
broadcast = Broadcast()
|
broadcast = Broadcast()
|
||||||
# Populating broadcast channels with all channels defined in Handler.Channels
|
# Populating broadcast channels with all channels defined in Handler.Channels
|
||||||
for channel in Handler.Channels.__dict__:
|
for channel in Subscribe.CHANNELS:
|
||||||
if not channel.startswith("_"):
|
broadcast.add_channel(channel)
|
||||||
broadcast.add_channel(Handler.Channels.__dict__[channel])
|
|
||||||
|
|
||||||
compile = Compile(config.source_path, config.binary_path)
|
compile = Compile(config.source_path, config.binary_path)
|
||||||
|
|
||||||
|
@ -174,7 +163,7 @@ server = make_server(config.server_address[0], config.server_address[1],
|
||||||
handler_args={"debug" : config.debug, "broadcast" : broadcast,
|
handler_args={"debug" : config.debug, "broadcast" : broadcast,
|
||||||
"compression_level" : config.compression_level,
|
"compression_level" : config.compression_level,
|
||||||
"routes" : {"info" : Info(),
|
"routes" : {"info" : Info(),
|
||||||
"get_info" : GetInfo(),
|
"subscribe" : Subscribe(),
|
||||||
"std_stream" : StdStream()}}))
|
"std_stream" : StdStream()}}))
|
||||||
server.initialize_websockets_manager()
|
server.initialize_websockets_manager()
|
||||||
|
|
||||||
|
|
Reference in a new issue