Removed unused imports, moved to Meh, removed Broadcast, ...

Fixed behem0th path, disabled compile for now
This commit is contained in:
Philip Trauner 2017-03-02 20:13:48 +01:00
parent f8112743b7
commit dfdbf0634d

View file

@ -1,23 +1,18 @@
from Meh import Config, Option, ExceptionInConfigError
from Highway import Server, Route, DummyPipe
import Logging import Logging
import Config
from .Broadcast import Broadcast
import json
import os import os
import subprocess import subprocess
import re import re
import pwd import pwd
import platform import platform
import struct
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from wsgiref.simple_server import make_server 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
from Highway import Server, Route, DummyPipe
import behem0th import behem0th
@ -78,13 +73,12 @@ class Subscribe(Route):
if "channel" in data: if "channel" in data:
if data["channel"] in Subscribe.CHANNELS: if data["channel"] in Subscribe.CHANNELS:
handler.channel = data["channel"] handler.channel = data["channel"]
handler.broadcast.add(handler, handler.channel)
if handler.debug: if handler.debug:
Logging.info("'%s:%i' has identified as a %s client." % (handler.address, handler.port, Logging.info("'%s:%i' has identified as a %s client." % (handler.address, handler.port,
"Editor" if handler.channel == Subscribe.EDITOR else "Editor" if handler.channel == Subscribe.EDITOR else
"Controller" if handler.channel == Subscribe.WALLABY else "Controller" if handler.channel == Subscribe.WALLABY else
"Web" if handler.channel == Subscribe.WEB else "Web" if handler.channel == Subscribe.WEB else
"Unknown (will not subscribe to broadcast)")) "Unknown"))
if "name" in data: if "name" in data:
handler.name = data["name"] handler.name = data["name"]
handler.routes["peers"].push_changes(handler) handler.routes["peers"].push_changes(handler)
@ -171,9 +165,8 @@ class Peers(Route):
class Handler(Server): class Handler(Server):
def setup(self, routes, broadcast, websockets, debug=False): def setup(self, routes, websockets, debug=False):
super().setup(routes, websockets, debug=debug) super().setup(routes, websockets, debug=debug)
self.broadcast = broadcast
self.channel = None self.channel = None
self.name = "Unknown" self.name = "Unknown"
@ -184,8 +177,6 @@ class Handler(Server):
def closed(self, code, reason): def closed(self, code, reason):
if self.channel != None:
self.broadcast.remove(self, self.channel)
if self.debug: if self.debug:
Logging.info("'%s:%d' disconnected." % (self.address, self.port)) Logging.info("'%s:%d' disconnected." % (self.address, self.port))
self.routes["peers"].push_changes(self) self.routes["peers"].push_changes(self)
@ -202,25 +193,20 @@ def folder_validator(folder):
CONFIG_PATH = "server.cfg" CONFIG_PATH = "server.cfg"
config = Config.Config()
config.add(Config.Option("server_address", ("127.0.0.1", 3077))) config = Config()
config.add(Config.Option("debug", True, validator=lambda x: True if True or False else False)) config.add(Option("server_address", ("127.0.0.1", 3077)))
config.add(Config.Option("binary_path", "Binaries", validator=folder_validator)) config.add(Option("debug", True, validator=lambda x: True if True or False else False))
config.add(Config.Option("source_path", "Source", validator=folder_validator)) config.add(Option("path", "Content", validator=folder_validator))
try: try:
config = config.read_from_file(CONFIG_PATH) config = config.load(CONFIG_PATH)
except FileNotFoundError: except (IOError, ExceptionInConfigError):
config.write_to_file(CONFIG_PATH) config.dump(CONFIG_PATH)
config = config.read_from_file(CONFIG_PATH) config = config.load(CONFIG_PATH)
broadcast = Broadcast() #compile = Compile(config.source_path, config.binary_path)
# 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)
server = make_server(config.server_address[0], config.server_address[1], 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.initialize_websockets_manager()
server.set_app(WebSocketWSGIApplication(handler_cls=Handler, server.set_app(WebSocketWSGIApplication(handler_cls=Handler,
handler_args={"debug" : config.debug, "broadcast" : broadcast, handler_args={"debug" : config.debug,
"websockets" : server.manager.websockets, "websockets" : server.manager.websockets,
"routes" : {"info" : Info(), "routes" : {"info" : Info(),
"whoami" : WhoAmI(), "whoami" : WhoAmI(),
@ -247,7 +233,7 @@ server.set_app(WebSocketWSGIApplication(handler_cls=Handler,
"reboot" : DummyPipe()}})) "reboot" : DummyPipe()}}))
sync_client = behem0th.Client(verbose_log=True) sync_client = behem0th.Client(path=config.path, verbose_log=config.debug)
try: try: