aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2015-03-14 20:27:25 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2015-03-14 20:27:25 +0100
commita36150d2305e93de9d0f58cb48273ed9909cab05 (patch)
tree03f0b75c178d6de9b05b83ee8954f1e3d6b63573
parente5dd6e1775da4f6f1f4933fc8b8fe4dc0b5dc2bd (diff)
downloaddabmux-a36150d2305e93de9d0f58cb48273ed9909cab05.tar.gz
dabmux-a36150d2305e93de9d0f58cb48273ed9909cab05.tar.bz2
dabmux-a36150d2305e93de9d0f58cb48273ed9909cab05.zip
GUI: create a second page with a service table
-rw-r--r--gui/muxconfig.py112
-rwxr-xr-xgui/odr-dabmux-gui.py91
-rw-r--r--gui/views/index.tpl2
-rw-r--r--gui/views/services.tpl31
4 files changed, 165 insertions, 71 deletions
diff --git a/gui/muxconfig.py b/gui/muxconfig.py
new file mode 100644
index 0000000..efa4b93
--- /dev/null
+++ b/gui/muxconfig.py
@@ -0,0 +1,112 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2015
+# Matthias P. Braendli, matthias.braendli@mpb.li
+#
+# http://www.opendigitalradio.org
+#
+# This file is part of ODR-DabMux.
+#
+# ODR-DabMux is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# ODR-DabMux is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
+import socket
+import json
+
+class Service(object):
+ """Container object for a service"""
+ def __init__(self, name, ptree):
+ self.name = name
+
+ for fieldname in ['id',
+ "label",
+ "shortlabel",
+ "pty",
+ "language" ]:
+ if fieldname in ptree:
+ setattr(self, fieldname.replace("-", "_"), ptree[fieldname])
+ else:
+ setattr(self, fieldname.replace("-", "_"), "")
+
+class Subchannel(object):
+ """Container object for a subchannel"""
+ def __init__(self, name, ptree):
+ self.name = name
+ for fieldname in ['type',
+ "inputfile",
+ "zmq-buffer",
+ "zmq-prebuffering",
+ "bitrate",
+ "id",
+ "protection",
+ "encryption",
+ "secret-key",
+ "public-key",
+ "encoder-key"]:
+ if fieldname in ptree:
+ setattr(self, fieldname.replace("-", "_"), ptree[fieldname])
+ else:
+ setattr(self, fieldname.replace("-", "_"), "")
+
+class Component(object):
+ """Container object for a component"""
+ def __init__(self, name, ptree):
+ self.name = name
+ for fieldname in ['label', 'shortlabel', 'service',
+ 'subchannel', 'figtype']:
+ if fieldname in ptree:
+ setattr(self, fieldname.replace("-", "_"), ptree[fieldname])
+ else:
+ setattr(self, fieldname.replace("-", "_"), "")
+
+class ConfigurationHandler(object):
+ """Load and present the configration from ODR-DabMux"""
+
+ def __init__(self, mux_host, mux_port=12720):
+ self._host = mux_host
+ self._port = mux_port
+
+ # local copy of the configuration
+ self._server_version = None
+ self._config = None
+
+ def load(self):
+ """Load the configuration from the multiplexer and
+ save it locally"""
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+ s.connect((self._host, self._port))
+ s.sendall(b'getptree\n')
+ server_info = s.recv(32768)
+ config_info = s.recv(32768)
+ s.close()
+
+ self._server_version = json.loads(server_info.decode())['service']
+ self._config = json.loads(config_info.decode())
+
+ def get_full_configuration(self):
+ return self._config
+
+ def get_mux_version(self):
+ return self._server_version
+
+ def get_services(self):
+ srv_pt = self._config['services']
+ return [Service(name, srv_pt[name]) for name in srv_pt]
+
+ def get_subchannels(self):
+ sub_pt = self._config['subchannels']
+ return [Subchannel(name, sub_pt[name]) for name in sub_pt]
+
+ def get_components(self):
+ comp_pt = self._config['components']
+ return [Component(name, comp_pt[name]) for name in comp_pt]
diff --git a/gui/odr-dabmux-gui.py b/gui/odr-dabmux-gui.py
index abfd124..2ba61a7 100755
--- a/gui/odr-dabmux-gui.py
+++ b/gui/odr-dabmux-gui.py
@@ -26,88 +26,39 @@
# You should have received a copy of the GNU General Public License
# along with ODR-DabMux. If not, see <http://www.gnu.org/licenses/>.
+from muxconfig import *
from bottle import route, run, template, static_file
-import socket
import json
-import collections
-class Service(object):
- def __init__(self, name, ptree):
- self.name = name
- self.label = ptree['label']
- if 'shortlabel' in ptree:
- self.shortlabel = ptree['shortlabel']
- else:
- self.shortlabel = ""
- self.srvid = ptree['id']
-
-
-class Subchannel(object):
- def __init__(self, name, ptree):
- self.name = name
- for fieldname in ['type',
- "inputfile",
- "zmq-buffer",
- "zmq-prebuffering",
- "bitrate",
- "id",
- "protection",
- "encryption",
- "secret-key",
- "public-key",
- "encoder-key"]:
- if fieldname in ptree:
- setattr(self, fieldname.replace("-", "_"), ptree[fieldname])
- else:
- setattr(self, fieldname.replace("-", "_"), "")
-
-class Component(object):
- def __init__(self, name, ptree):
- self.name = name
- for fieldname in ['label', 'shortlabel', 'service',
- 'subchannel', 'figtype']:
- if fieldname in ptree:
- setattr(self, fieldname.replace("-", "_"), ptree[fieldname])
- else:
- setattr(self, fieldname.replace("-", "_"), "")
-
-def get_mgmt_ptree():
- HOST = 'localhost'
- PORT = 12720
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((HOST, PORT))
- s.sendall(b'getptree\n')
- server_info = s.recv(32768)
- config_info = s.recv(32768)
- s.close()
-
- server_version = json.loads(server_info.decode())['service']
- config = json.loads(config_info.decode())
-
- return {'version': server_version, 'config': config}
+conf = ConfigurationHandler('localhost')
@route('/config')
def config():
- return get_mgmt_ptree()
+ """Return a application/json containing the full
+ ptree of the mux"""
+
+ conf.load()
+
+ return {'version': conf.get_mux_version(),
+ 'config': conf.get_full_configuration()}
@route('/')
def index():
- ptree = get_mgmt_ptree()
- version = ptree['version']
- srv_pt = ptree['config']['services']
- services = [Service(name, srv_pt[name]) for name in srv_pt]
+ conf.load()
- sub_pt = ptree['config']['subchannels']
- subchannels = [Subchannel(name, sub_pt[name]) for name in sub_pt]
+ return template('index',
+ version = conf.get_mux_version(),
+ services = conf.get_services(),
+ subchannels = conf.get_subchannels(),
+ components = conf.get_components())
- comp_pt = ptree['config']['components']
- components = [Component(name, comp_pt[name]) for name in comp_pt]
+@route('/services')
+def index():
+ conf.load()
- return template('index',
- version=version,
- services=services,
- components=components,
- subchannels=subchannels)
+ return template('services',
+ version = conf.get_mux_version(),
+ services = conf.get_services())
@route('/static/<filename:path>')
diff --git a/gui/views/index.tpl b/gui/views/index.tpl
index c847402..a73d6d2 100644
--- a/gui/views/index.tpl
+++ b/gui/views/index.tpl
@@ -12,7 +12,7 @@ body {
<h2>Services</h2>
<ul>
% for s in services:
- <li>{{s.name}}: <i>{{s.label}} ({{s.shortlabel}})</i> &mdash; id = {{s.srvid}}</li>
+ <li>{{s.name}}: <i>{{s.label}} ({{s.shortlabel}})</i> &mdash; id = {{s.id}}</li>
% end
</ul>
<h2>Subchannels</h2>
diff --git a/gui/views/services.tpl b/gui/views/services.tpl
new file mode 100644
index 0000000..7ca2f9f
--- /dev/null
+++ b/gui/views/services.tpl
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html><head>
+<title>ODR-DabMux Services</title>
+<style>
+body {
+ font-family: sans;
+}
+</style>
+</head>
+<body>
+ <h1>Services for {{version}}</h1>
+ <table>
+ <tr>
+ <th>name</th>
+ <th>id</th>
+ <th>label</th>
+ <th>pty</th>
+ <th>language</th>
+ </tr>
+ % for s in services:
+ <tr><td>{{s.name}}</td>
+ <td>{{s.id}}</td>
+ <td>{{s.label}} ({{s.shortlabel}})</td>
+ <td>{{s.pty}}</td>
+ <td>{{s.language}}</td>
+ </tr>
+ % end
+ </ul>
+</body>
+</html>
+