Add configuration entries for setting the compression level used by ESock.
On the ST client and on the server, compression_level defaults to 2, on the Wallaby client to 0 because of limited resources and longer battery-life.
This commit is contained in:
parent
a6de0790dd
commit
306d629d0b
5 changed files with 33 additions and 22 deletions
|
@ -11,7 +11,7 @@ import _thread
|
||||||
|
|
||||||
|
|
||||||
class Server:
|
class Server:
|
||||||
def __init__(self, host_port_pair, debug=False):
|
def __init__(self, host_port_pair, debug=False, compression_level=None):
|
||||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
try:
|
try:
|
||||||
self.sock.bind(host_port_pair)
|
self.sock.bind(host_port_pair)
|
||||||
|
@ -21,13 +21,18 @@ class Server:
|
||||||
self.sock.listen(2)
|
self.sock.listen(2)
|
||||||
self.handlers = []
|
self.handlers = []
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
|
self.compression_level = compression_level
|
||||||
|
|
||||||
|
|
||||||
def run(self, handler, handler_args={}):
|
def run(self, handler, handler_args={}):
|
||||||
self.handler = handler
|
self.handler = handler
|
||||||
while 1:
|
while 1:
|
||||||
sock, info = self.sock.accept()
|
sock, info = self.sock.accept()
|
||||||
sock = ESock(sock) if not self.debug else ESock(sock, debug=self.debug)
|
if self.compression_level:
|
||||||
|
sock = ESock(sock, debug=self.debug, compression_level=self.compression_level)
|
||||||
|
else:
|
||||||
|
sock = ESock(sock, debug=self.debug)
|
||||||
|
|
||||||
handler = self.handler(sock, info, **handler_args)
|
handler = self.handler(sock, info, **handler_args)
|
||||||
self.handlers.append(handler)
|
self.handlers.append(handler)
|
||||||
_thread.start_new_thread(self.controller, (handler, ))
|
_thread.start_new_thread(self.controller, (handler, ))
|
||||||
|
@ -60,11 +65,11 @@ class Server:
|
||||||
handler.finish()
|
handler.finish()
|
||||||
except Exception:
|
except Exception:
|
||||||
self.print_trace(sock)
|
self.print_trace(sock)
|
||||||
finally:
|
finally:
|
||||||
if handler in self.handlers:
|
if handler in self.handlers:
|
||||||
del self.handlers[self.handlers.index(handler)]
|
del self.handlers[self.handlers.index(handler)]
|
||||||
handler.sock.close()
|
handler.sock.close()
|
||||||
|
|
||||||
|
|
||||||
class Handler:
|
class Handler:
|
||||||
def __init__(self, sock, info, **kwargs):
|
def __init__(self, sock, info, **kwargs):
|
||||||
|
@ -79,4 +84,4 @@ class Server:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Info(Routing.ServerRoute):
|
||||||
def run(self, data, handler):
|
def run(self, data, handler):
|
||||||
handler.sock.send("Connected ST clients: %d\nConnected Wallabies: %d\nAvaliable routes: %s" % (
|
handler.sock.send("Connected ST clients: %d\nConnected Wallabies: %d\nAvaliable routes: %s" % (
|
||||||
len(handler.broadcast.channels[Handler.Channels.SUBLIME]),
|
len(handler.broadcast.channels[Handler.Channels.SUBLIME]),
|
||||||
len(handler.broadcast.channels[Handler.Channels.WALLABY]),
|
len(handler.broadcast.channels[Handler.Channels.WALLABY]),
|
||||||
", ".join([route for route in list(handler.routes.keys())])), "info")
|
", ".join([route for route in list(handler.routes.keys())])), "info")
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class StdStream(Routing.ServerRoute):
|
||||||
class WallabyControl(Routing.ServerRoute):
|
class WallabyControl(Routing.ServerRoute):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.actions_with_params = {"run" : self.run_program}
|
self.actions_with_params = {"run" : self.run_program}
|
||||||
self.actions_without_params = {"disconnect" : self.disconnect,
|
self.actions_without_params = {"disconnect" : self.disconnect,
|
||||||
"reboot" : self.reboot, "shutdown" : self.shutdown, "stop" : self.stop_programs}
|
"reboot" : self.reboot, "shutdown" : self.shutdown, "stop" : self.stop_programs}
|
||||||
self.programs = []
|
self.programs = []
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class WallabyControl(Routing.ServerRoute):
|
||||||
|
|
||||||
def run_program(self, program, wallaby_handler, handler):
|
def run_program(self, program, wallaby_handler, handler):
|
||||||
handler.routes["std_stream"].stream_to.update({wallaby_handler : handler})
|
handler.routes["std_stream"].stream_to.update({wallaby_handler : handler})
|
||||||
wallaby_handler.sock.send({"run" : program}, "wallaby_control")
|
wallaby_handler.sock.send({"run" : program}, "wallaby_control")
|
||||||
|
|
||||||
|
|
||||||
def stop_programs(self, wallaby_handler, handler):
|
def stop_programs(self, wallaby_handler, handler):
|
||||||
|
@ -158,9 +158,9 @@ class GetInfo(Routing.ServerRoute):
|
||||||
handler.broadcast.add(handler, handler.channel)
|
handler.broadcast.add(handler, handler.channel)
|
||||||
if "name" in data:
|
if "name" in data:
|
||||||
handler.name = data["name"]
|
handler.name = data["name"]
|
||||||
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],
|
||||||
"Sublime Text" if handler.channel == Handler.Channels.SUBLIME else
|
"Sublime Text" if handler.channel == Handler.Channels.SUBLIME else
|
||||||
"Wallaby" if handler.channel == Handler.Channels.WALLABY else
|
"Wallaby" if handler.channel == Handler.Channels.WALLABY else
|
||||||
"Unknown (will not subscribe to broadcast)"))
|
"Unknown (will not subscribe to broadcast)"))
|
||||||
|
|
||||||
def start(self, handler):
|
def start(self, handler):
|
||||||
|
@ -179,7 +179,7 @@ class Handler(Server.Handler):
|
||||||
self.routes = Routing.create_routes(routes, self)
|
self.routes = Routing.create_routes(routes, self)
|
||||||
self.name = "Unknown"
|
self.name = "Unknown"
|
||||||
|
|
||||||
|
|
||||||
def handle(self, data, route):
|
def handle(self, data, route):
|
||||||
if route in self.routes:
|
if route in self.routes:
|
||||||
self.routes[route].run(data, self)
|
self.routes[route].run(data, self)
|
||||||
|
@ -213,6 +213,7 @@ 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("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("binary_path", "Binaries", validator=folder_validator))
|
||||||
config.add(Config.Option("source_path", "Source", validator=folder_validator))
|
config.add(Config.Option("source_path", "Source", validator=folder_validator))
|
||||||
|
config.add(Config.Option("compression_level", 0, validator=lambda x: x >= 0 and x <= 9))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = config.read_from_file(CONFIG_PATH)
|
config = config.read_from_file(CONFIG_PATH)
|
||||||
|
@ -220,7 +221,7 @@ except FileNotFoundError:
|
||||||
config.write_to_file(CONFIG_PATH)
|
config.write_to_file(CONFIG_PATH)
|
||||||
config = config.read_from_file(CONFIG_PATH)
|
config = config.read_from_file(CONFIG_PATH)
|
||||||
|
|
||||||
server = Server(config.server_address, debug=config.debug)
|
server = Server(config.server_address, debug=config.debug, compression_level=config.compression_level)
|
||||||
|
|
||||||
broadcast = Broadcast()
|
broadcast = Broadcast()
|
||||||
# Populating broadcast channels with all channels defined in Handler.Channels
|
# Populating broadcast channels with all channels defined in Handler.Channels
|
||||||
|
@ -234,9 +235,9 @@ s_sync = SyncServer(config.source_path, Handler.Channels.SUBLIME, debug=config.d
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Logging.header("fl0w server started on '%s:%d'" % (config.server_address[0], config.server_address[1]))
|
Logging.header("fl0w server started on '%s:%d'" % (config.server_address[0], config.server_address[1]))
|
||||||
server.run(Handler,
|
server.run(Handler,
|
||||||
{"broadcast" : broadcast,
|
{"broadcast" : broadcast,
|
||||||
"routes" : {"info" : Info(), "wallaby_control" : WallabyControl(),
|
"routes" : {"info" : Info(), "wallaby_control" : WallabyControl(),
|
||||||
"get_info" : GetInfo(), "compile" : compile, "std_stream" : StdStream(),
|
"get_info" : GetInfo(), "compile" : compile, "std_stream" : StdStream(),
|
||||||
WALLABY_SYNC_ROUTE : w_sync,
|
WALLABY_SYNC_ROUTE : w_sync,
|
||||||
SUBLIME_SYNC_ROUTE : s_sync}})
|
SUBLIME_SYNC_ROUTE : s_sync}})
|
||||||
|
|
|
@ -157,10 +157,13 @@ class Fl0w:
|
||||||
def connect(self, connect_details):
|
def connect(self, connect_details):
|
||||||
connect_details_raw = connect_details
|
connect_details_raw = connect_details
|
||||||
connect_details = connect_details.split(":")
|
connect_details = connect_details.split(":")
|
||||||
|
compression_level = int(sublime.load_settings("fl0w.sublime-settings").get("compression_level"))
|
||||||
|
|
||||||
if len(connect_details) == 2:
|
if len(connect_details) == 2:
|
||||||
try:
|
try:
|
||||||
# Establish connection to the server
|
# Establish connection to the server
|
||||||
self.sock = ESock(socket.create_connection((connect_details[0], int(connect_details[1]))), disconnect_callback=self.invoke_disconnect, debug=False)
|
self.sock = ESock(socket.create_connection((connect_details[0], int(connect_details[1]))),
|
||||||
|
disconnect_callback=self.invoke_disconnect, debug=False, compression_level=compression_level)
|
||||||
sublime.status_message("Connected to %s:%s." % (connect_details[0], connect_details[1]))
|
sublime.status_message("Connected to %s:%s." % (connect_details[0], connect_details[1]))
|
||||||
# Initialize all routes
|
# Initialize all routes
|
||||||
error_report = Fl0w.ErrorReport()
|
error_report = Fl0w.ErrorReport()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
{
|
{
|
||||||
"server_address": "" // Last server address
|
"server_address": "", // Last server address
|
||||||
}
|
"compression_level": 2
|
||||||
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ class WallabyControl(Routing.ClientRoute):
|
||||||
def __init__(self, output_unbuffer):
|
def __init__(self, output_unbuffer):
|
||||||
self.output_unbuffer = output_unbuffer
|
self.output_unbuffer = output_unbuffer
|
||||||
self.actions_with_params = {"run" : self.run_program}
|
self.actions_with_params = {"run" : self.run_program}
|
||||||
self.actions_without_params = {"disconnect" : self.disconnect,
|
self.actions_without_params = {"disconnect" : self.disconnect,
|
||||||
"reboot" : self.reboot, "shutdown" : self.shutdown, "stop" : self.stop}
|
"reboot" : self.reboot, "shutdown" : self.shutdown, "stop" : self.stop}
|
||||||
self.currently_running_program = None
|
self.currently_running_program = None
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class WallabyControl(Routing.ClientRoute):
|
||||||
self.currently_running_program.kill()
|
self.currently_running_program.kill()
|
||||||
else:
|
else:
|
||||||
Logging.info("No program started by fl0w.")
|
Logging.info("No program started by fl0w.")
|
||||||
|
|
||||||
|
|
||||||
def reboot(self, handler):
|
def reboot(self, handler):
|
||||||
self.disconnect(handler)
|
self.disconnect(handler)
|
||||||
|
@ -82,7 +82,7 @@ def get_wallaby_hostname():
|
||||||
class GetInfo(Routing.ClientRoute):
|
class GetInfo(Routing.ClientRoute):
|
||||||
def run(self, data, handler):
|
def run(self, data, handler):
|
||||||
if data == "":
|
if data == "":
|
||||||
handler.sock.send({"type" : CHANNEL,
|
handler.sock.send({"type" : CHANNEL,
|
||||||
"name" : platform.node() if not IS_WALLABY else get_wallaby_hostname()}, "get_info")
|
"name" : platform.node() if not IS_WALLABY else get_wallaby_hostname()}, "get_info")
|
||||||
elif "name" in data:
|
elif "name" in data:
|
||||||
if IS_WALLABY:
|
if IS_WALLABY:
|
||||||
|
@ -125,6 +125,7 @@ config = Config.Config()
|
||||||
config.add(Config.Option("server_address", ("127.0.0.1", 3077)))
|
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("debug", True, validator=lambda x: True if True or False else False))
|
||||||
config.add(Config.Option("output_unbuffer", "stdbuf"))
|
config.add(Config.Option("output_unbuffer", "stdbuf"))
|
||||||
|
config.add(Config.Option("compression_level", 0, validator=lambda x: x >= 0 and x <= 9))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = config.read_from_file(CONFIG_PATH)
|
config = config.read_from_file(CONFIG_PATH)
|
||||||
|
@ -134,7 +135,7 @@ except FileNotFoundError:
|
||||||
exit(1)
|
exit(1)
|
||||||
config = config.read_from_file(CONFIG_PATH)
|
config = config.read_from_file(CONFIG_PATH)
|
||||||
|
|
||||||
wallaby_client = WallabyClient(config.server_address,
|
wallaby_client = WallabyClient(config.server_address,
|
||||||
{"wallaby_control" : WallabyControl(config.output_unbuffer), "get_info" : GetInfo()},
|
{"wallaby_control" : WallabyControl(config.output_unbuffer), "get_info" : GetInfo()},
|
||||||
debug=config.debug)
|
debug=config.debug)
|
||||||
try:
|
try:
|
||||||
|
|
Reference in a new issue