summaryrefslogtreecommitdiff
path: root/voctogui
diff options
context:
space:
mode:
authorMaZderMind <git@mazdermind.de>2015-09-02 15:19:30 +0200
committerMaZderMind <git@mazdermind.de>2015-09-02 15:19:30 +0200
commit20d75f6c7f5cad2f5c1b4da71ad5405848230201 (patch)
tree93894d7bc79a0b018275efbc0db524ac6f686570 /voctogui
parenta004948051e182edb3a7e40f1f7f2e14bebb0e0e (diff)
parent8646386d09ab6cdabf0b8421cece5c1ddd69633f (diff)
Merge branch 'control-server-resilience'
Based on the work made by zuntrax & mithro at cccamp15
Diffstat (limited to 'voctogui')
-rw-r--r--voctogui/default-config.ini3
-rw-r--r--voctogui/lib/config.py8
-rw-r--r--voctogui/lib/connection.py46
-rwxr-xr-xvoctogui/voctogui.py10
4 files changed, 67 insertions, 0 deletions
diff --git a/voctogui/default-config.ini b/voctogui/default-config.ini
index 28ffc0c..03b0300 100644
--- a/voctogui/default-config.ini
+++ b/voctogui/default-config.ini
@@ -1,3 +1,6 @@
+[server]
+host=localhost
+
[previews]
width=320
#height=180
diff --git a/voctogui/lib/config.py b/voctogui/lib/config.py
index b06075c..b18acfb 100644
--- a/voctogui/lib/config.py
+++ b/voctogui/lib/config.py
@@ -1,14 +1,22 @@
#!/usr/bin/python3
+import logging
import os.path
from configparser import SafeConfigParser
from lib.args import Args
+import lib.connection as Connection
__all__ = ['Config']
def getlist(self, section, option):
return [x.strip() for x in self.get(section, option).split(',')]
+def fetchRemoteConfig(self):
+ log = logging.getLogger('Config')
+ log.info("reading server-config %s", Connection)
+ Connection.ask('config')
+
SafeConfigParser.getlist = getlist
+SafeConfigParser.fetchRemoteConfig = fetchRemoteConfig
files = [
os.path.join(os.path.dirname(os.path.realpath(__file__)), '../default-config.ini'),
diff --git a/voctogui/lib/connection.py b/voctogui/lib/connection.py
new file mode 100644
index 0000000..ac7243d
--- /dev/null
+++ b/voctogui/lib/connection.py
@@ -0,0 +1,46 @@
+#!/usr/bin/python3
+import logging
+import socket
+
+log = logging.getLogger('Connection')
+sock = None
+port = 9999
+
+def establish(host):
+ log.info('establishing Connection to %s', host)
+ sock = socket.create_connection( (host, port) )
+ log.debug('Connection successful \o/')
+ # TODO: register IO callback here
+
+
+def send(command):
+ print("would send command talk to server now and read back the response")
+ filelike = sock.makefile('rw')
+ filelike.write(command + "\n")
+ filelike.flush()
+
+
+def on_data(args*):
+ filelike = sock.makefile()
+ line = ''
+ try:
+ line = filelike.readline()
+ except Exception as e:
+ log.warn("Can't read from socket: %s", e)
+
+ if len(line) == 0:
+ close_connection()
+ return False
+
+ line = line.strip()
+
+ process_line(line)
+
+
+def process_line(line):
+ msg_type = line.split()[0]
+
+
+def close_connection():
+ pass
+
diff --git a/voctogui/voctogui.py b/voctogui/voctogui.py
index 52bc3c0..932b8f9 100755
--- a/voctogui/voctogui.py
+++ b/voctogui/voctogui.py
@@ -24,8 +24,11 @@ Gst.init([])
# import local classes
from lib.args import Args
+from lib.config import Config
from lib.ui import Ui
+import lib.connection as Connection
+
# main class
class Voctogui(object):
def __init__(self):
@@ -100,6 +103,13 @@ def main():
logging.info('Python Version: %s', sys.version_info)
logging.info('GStreamer Version: %s', Gst.version())
+ # connect to server
+ Connection.establish(
+ Config.get('server', 'host'))
+
+ # fetch serverconfig from server
+ Config.fetchRemoteConfig()
+
# init main-class and main-loop
logging.debug('initializing Voctogui')
voctogui = Voctogui()