From 7f067f40e9702ea5e1733b01aefef4d4efe9f850 Mon Sep 17 00:00:00 2001 From: Christoph Heiss Date: Wed, 1 Mar 2017 21:56:29 +0100 Subject: [PATCH] Initial integration of behem0th. --- Server/Server.py | 7 +++++++ Shared/Utils.py | 6 ++++++ Sublime/fl0w/fl0w.py | 12 ++++++++++-- Wallaby/Wallaby.py | 9 ++++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Server/Server.py b/Server/Server.py index e058d29..6356f98 100644 --- a/Server/Server.py +++ b/Server/Server.py @@ -18,6 +18,8 @@ from ws4py.server.wsgiutils import WebSocketWSGIApplication from Highway import Server, Route, DummyPipe +import behem0th + class Info(Route): def run(self, data, handler): @@ -245,10 +247,15 @@ server.set_app(WebSocketWSGIApplication(handler_cls=Handler, "reboot" : DummyPipe()}})) +sync_client = behem0th.Client(verbose_log=True) + + try: Logging.header("Server loop starting.") + sync_client.listen() server.serve_forever() except KeyboardInterrupt: Logging.header("Gracefully shutting down server.") server.server_close() + sync_client.close() Logging.success("Server shutdown successful.") diff --git a/Shared/Utils.py b/Shared/Utils.py index bae4483..e8b5c05 100644 --- a/Shared/Utils.py +++ b/Shared/Utils.py @@ -6,6 +6,8 @@ import struct import socket import fcntl import subprocess +import urllib + class HostnameNotChangedError(PermissionError): def __init__(self): @@ -82,6 +84,10 @@ def get_ip_address(ifname=None): return ip_address +def get_ip_from_url(url): + return urllib.parse.urlsplit(url).netloc.split(':')[0] + + def play_sound(path): if is_linux() or is_darwin(): try: diff --git a/Sublime/fl0w/fl0w.py b/Sublime/fl0w/fl0w.py index fa2ea18..30c8c30 100644 --- a/Sublime/fl0w/fl0w.py +++ b/Sublime/fl0w/fl0w.py @@ -16,7 +16,9 @@ import sublime import sublime_plugin from Highway import Client, Route, Pipe, DummyPipe -from Utils import get_hostname +from Utils import get_hostname, get_ip_from_url + +import behem0th from SublimeMenu import * import Logging @@ -355,6 +357,8 @@ class Fl0w: self.main_menu += Entry("Disconnect", "Disconnect from server", action=self.invoke_disconnect) + self.sync_client = behem0th.Client(path=self.folder, verbose_log=True) + # Patch all sensor phantom that have been created before a fl0w instance # was attached to the window for sensor_phantom in sensor_phantoms: @@ -503,7 +507,9 @@ class Fl0w: set_status("Connection opened '%s'" % self.folder, self.window) self.connected = True self.settings.set("address", address) - except OSError as e: + + self.sync_client.connect(get_ip_from_url(address)) + except (OSError, ConnectionRefusedError) as e: sublime.error_message("Error during connection creation:\n %s" % str(e)) @@ -523,6 +529,8 @@ class Fl0w: set_status("Connection closed '%s'" % self.folder, self.window) self.connected = False + self.sync_client.close() + class Fl0wCommand(sublime_plugin.WindowCommand): def run(self): diff --git a/Wallaby/Wallaby.py b/Wallaby/Wallaby.py index 24b5e99..7c62a36 100644 --- a/Wallaby/Wallaby.py +++ b/Wallaby/Wallaby.py @@ -3,6 +3,8 @@ import Logging import Config import Utils +import behem0th + import socket import time import os @@ -331,6 +333,8 @@ except FileNotFoundError: try: + sync_client = behem0th.Client(path=self.folder, verbose_log=True) + ws = Handler(config.server_address) # setup has to be called before the connection is established ws.setup({"subscribe" : Subscribe(), "hostname" : Hostname(), @@ -341,6 +345,9 @@ try: "reboot" : Reboot()}, debug=config.debug) ws.connect() + sync_client.connect(Utils.get_ip_from_url(config.server_address)) + ws.run_forever() except KeyboardInterrupt: - ws.close() \ No newline at end of file + ws.close() + sync_client.close()