Initial integration of behem0th.
This commit is contained in:
parent
5188457be5
commit
7f067f40e9
4 changed files with 31 additions and 3 deletions
|
@ -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.")
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
ws.close()
|
||||
sync_client.close()
|
||||
|
|
Reference in a new issue