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
|
from Highway import Server, Route, DummyPipe
|
||||||
|
|
||||||
|
import behem0th
|
||||||
|
|
||||||
|
|
||||||
class Info(Route):
|
class Info(Route):
|
||||||
def run(self, data, handler):
|
def run(self, data, handler):
|
||||||
|
@ -245,10 +247,15 @@ server.set_app(WebSocketWSGIApplication(handler_cls=Handler,
|
||||||
"reboot" : DummyPipe()}}))
|
"reboot" : DummyPipe()}}))
|
||||||
|
|
||||||
|
|
||||||
|
sync_client = behem0th.Client(verbose_log=True)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Logging.header("Server loop starting.")
|
Logging.header("Server loop starting.")
|
||||||
|
sync_client.listen()
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
Logging.header("Gracefully shutting down server.")
|
Logging.header("Gracefully shutting down server.")
|
||||||
server.server_close()
|
server.server_close()
|
||||||
|
sync_client.close()
|
||||||
Logging.success("Server shutdown successful.")
|
Logging.success("Server shutdown successful.")
|
||||||
|
|
|
@ -6,6 +6,8 @@ import struct
|
||||||
import socket
|
import socket
|
||||||
import fcntl
|
import fcntl
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import urllib
|
||||||
|
|
||||||
|
|
||||||
class HostnameNotChangedError(PermissionError):
|
class HostnameNotChangedError(PermissionError):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -82,6 +84,10 @@ def get_ip_address(ifname=None):
|
||||||
return ip_address
|
return ip_address
|
||||||
|
|
||||||
|
|
||||||
|
def get_ip_from_url(url):
|
||||||
|
return urllib.parse.urlsplit(url).netloc.split(':')[0]
|
||||||
|
|
||||||
|
|
||||||
def play_sound(path):
|
def play_sound(path):
|
||||||
if is_linux() or is_darwin():
|
if is_linux() or is_darwin():
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -16,7 +16,9 @@ import sublime
|
||||||
import sublime_plugin
|
import sublime_plugin
|
||||||
|
|
||||||
from Highway import Client, Route, Pipe, DummyPipe
|
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 *
|
from SublimeMenu import *
|
||||||
import Logging
|
import Logging
|
||||||
|
@ -355,6 +357,8 @@ class Fl0w:
|
||||||
self.main_menu += Entry("Disconnect", "Disconnect from server",
|
self.main_menu += Entry("Disconnect", "Disconnect from server",
|
||||||
action=self.invoke_disconnect)
|
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
|
# Patch all sensor phantom that have been created before a fl0w instance
|
||||||
# was attached to the window
|
# was attached to the window
|
||||||
for sensor_phantom in sensor_phantoms:
|
for sensor_phantom in sensor_phantoms:
|
||||||
|
@ -503,7 +507,9 @@ class Fl0w:
|
||||||
set_status("Connection opened '%s'" % self.folder, self.window)
|
set_status("Connection opened '%s'" % self.folder, self.window)
|
||||||
self.connected = True
|
self.connected = True
|
||||||
self.settings.set("address", address)
|
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))
|
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)
|
set_status("Connection closed '%s'" % self.folder, self.window)
|
||||||
self.connected = False
|
self.connected = False
|
||||||
|
|
||||||
|
self.sync_client.close()
|
||||||
|
|
||||||
|
|
||||||
class Fl0wCommand(sublime_plugin.WindowCommand):
|
class Fl0wCommand(sublime_plugin.WindowCommand):
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
|
@ -3,6 +3,8 @@ import Logging
|
||||||
import Config
|
import Config
|
||||||
import Utils
|
import Utils
|
||||||
|
|
||||||
|
import behem0th
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
@ -331,6 +333,8 @@ except FileNotFoundError:
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
sync_client = behem0th.Client(path=self.folder, verbose_log=True)
|
||||||
|
|
||||||
ws = Handler(config.server_address)
|
ws = Handler(config.server_address)
|
||||||
# setup has to be called before the connection is established
|
# setup has to be called before the connection is established
|
||||||
ws.setup({"subscribe" : Subscribe(), "hostname" : Hostname(),
|
ws.setup({"subscribe" : Subscribe(), "hostname" : Hostname(),
|
||||||
|
@ -341,6 +345,9 @@ try:
|
||||||
"reboot" : Reboot()},
|
"reboot" : Reboot()},
|
||||||
debug=config.debug)
|
debug=config.debug)
|
||||||
ws.connect()
|
ws.connect()
|
||||||
|
sync_client.connect(Utils.get_ip_from_url(config.server_address))
|
||||||
|
|
||||||
ws.run_forever()
|
ws.run_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
ws.close()
|
ws.close()
|
||||||
|
sync_client.close()
|
||||||
|
|
Reference in a new issue