Removed unused imports, moved to Meh, removed Broadcast, ...
Fixed behem0th path, disabled compile for now
This commit is contained in:
parent
f8112743b7
commit
dfdbf0634d
1 changed files with 16 additions and 30 deletions
|
@ -1,23 +1,18 @@
|
|||
from Meh import Config, Option, ExceptionInConfigError
|
||||
from Highway import Server, Route, DummyPipe
|
||||
import Logging
|
||||
import Config
|
||||
|
||||
from .Broadcast import Broadcast
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import re
|
||||
import pwd
|
||||
import platform
|
||||
import struct
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
from wsgiref.simple_server import make_server
|
||||
from ws4py.server.wsgirefserver import WSGIServer, WebSocketWSGIRequestHandler
|
||||
from ws4py.server.wsgiutils import WebSocketWSGIApplication
|
||||
|
||||
from Highway import Server, Route, DummyPipe
|
||||
|
||||
import behem0th
|
||||
|
||||
|
||||
|
@ -78,13 +73,12 @@ class Subscribe(Route):
|
|||
if "channel" in data:
|
||||
if data["channel"] in Subscribe.CHANNELS:
|
||||
handler.channel = data["channel"]
|
||||
handler.broadcast.add(handler, handler.channel)
|
||||
if handler.debug:
|
||||
Logging.info("'%s:%i' has identified as a %s client." % (handler.address, handler.port,
|
||||
"Editor" if handler.channel == Subscribe.EDITOR else
|
||||
"Controller" if handler.channel == Subscribe.WALLABY else
|
||||
"Web" if handler.channel == Subscribe.WEB else
|
||||
"Unknown (will not subscribe to broadcast)"))
|
||||
"Unknown"))
|
||||
if "name" in data:
|
||||
handler.name = data["name"]
|
||||
handler.routes["peers"].push_changes(handler)
|
||||
|
@ -171,9 +165,8 @@ class Peers(Route):
|
|||
|
||||
|
||||
class Handler(Server):
|
||||
def setup(self, routes, broadcast, websockets, debug=False):
|
||||
def setup(self, routes, websockets, debug=False):
|
||||
super().setup(routes, websockets, debug=debug)
|
||||
self.broadcast = broadcast
|
||||
self.channel = None
|
||||
self.name = "Unknown"
|
||||
|
||||
|
@ -184,8 +177,6 @@ class Handler(Server):
|
|||
|
||||
|
||||
def closed(self, code, reason):
|
||||
if self.channel != None:
|
||||
self.broadcast.remove(self, self.channel)
|
||||
if self.debug:
|
||||
Logging.info("'%s:%d' disconnected." % (self.address, self.port))
|
||||
self.routes["peers"].push_changes(self)
|
||||
|
@ -202,25 +193,20 @@ def folder_validator(folder):
|
|||
|
||||
CONFIG_PATH = "server.cfg"
|
||||
|
||||
config = Config.Config()
|
||||
config.add(Config.Option("server_address", ("127.0.0.1", 3077)))
|
||||
config.add(Config.Option("debug", True, validator=lambda x: True if True or False else False))
|
||||
config.add(Config.Option("binary_path", "Binaries", validator=folder_validator))
|
||||
config.add(Config.Option("source_path", "Source", validator=folder_validator))
|
||||
|
||||
config = Config()
|
||||
config.add(Option("server_address", ("127.0.0.1", 3077)))
|
||||
config.add(Option("debug", True, validator=lambda x: True if True or False else False))
|
||||
config.add(Option("path", "Content", validator=folder_validator))
|
||||
|
||||
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)
|
||||
|
||||
|
||||
broadcast = Broadcast()
|
||||
# Populating broadcast channels with all channels defined in Subscribe.Channels
|
||||
for channel in Subscribe.CHANNELS:
|
||||
broadcast.add_channel(channel)
|
||||
|
||||
compile = Compile(config.source_path, config.binary_path)
|
||||
#compile = Compile(config.source_path, config.binary_path)
|
||||
|
||||
|
||||
server = make_server(config.server_address[0], config.server_address[1],
|
||||
|
@ -229,7 +215,7 @@ server = make_server(config.server_address[0], config.server_address[1],
|
|||
server.initialize_websockets_manager()
|
||||
|
||||
server.set_app(WebSocketWSGIApplication(handler_cls=Handler,
|
||||
handler_args={"debug" : config.debug, "broadcast" : broadcast,
|
||||
handler_args={"debug" : config.debug,
|
||||
"websockets" : server.manager.websockets,
|
||||
"routes" : {"info" : Info(),
|
||||
"whoami" : WhoAmI(),
|
||||
|
@ -247,7 +233,7 @@ server.set_app(WebSocketWSGIApplication(handler_cls=Handler,
|
|||
"reboot" : DummyPipe()}}))
|
||||
|
||||
|
||||
sync_client = behem0th.Client(verbose_log=True)
|
||||
sync_client = behem0th.Client(path=config.path, verbose_log=config.debug)
|
||||
|
||||
|
||||
try:
|
||||
|
|
Reference in a new issue