From 0e34e78f42cc9eabc404e93fd8ffcea20cbcc694 Mon Sep 17 00:00:00 2001 From: yomguy Date: Mon, 20 Feb 2012 13:36:11 +0100 Subject: [PATCH] fix station record mode, add urls --- telecaster/htdocs/css/telecaster.css | 3 + telecaster/htdocs/js/application.js | 8 +- telecaster/models.py | 18 ++-- telecaster/{ => old}/station.py | 0 telecaster/templates/telecaster/base.html | 6 +- telecaster/templates/telecaster/start.html | 14 ++- telecaster/templates/telecaster/stop.html | 50 ++++----- telecaster/tools/tools.py | 65 ++++++++++++ telecaster/urls.py | 18 ++-- telecaster/views.py | 118 ++++++--------------- 10 files changed, 162 insertions(+), 138 deletions(-) rename telecaster/{ => old}/station.py (100%) diff --git a/telecaster/htdocs/css/telecaster.css b/telecaster/htdocs/css/telecaster.css index 510f009..98a3081 100644 --- a/telecaster/htdocs/css/telecaster.css +++ b/telecaster/htdocs/css/telecaster.css @@ -230,3 +230,6 @@ table.hardware { .icon_trash{ background-image: url('../images/bin.png'); } +.icon_stop{ + background-image: url('../images/control_stop.png'); + } \ No newline at end of file diff --git a/telecaster/htdocs/js/application.js b/telecaster/htdocs/js/application.js index 16f4e1c..120b334 100644 --- a/telecaster/htdocs/js/application.js +++ b/telecaster/htdocs/js/application.js @@ -155,10 +155,14 @@ function server_status_callback(){ var line = res[i]; var wrapper = doc.getElementById('status_'+line.id); s = ''+line.value+''; - wrapper.innerHTML = s + wrapper.innerHTML = s; } }, - function(){return false;} + function(){ + var wrapper = doc.getElementById('server_status_table_wrapper'); + s = 'NOT connected'; + wrapper.innerHTML = s; + } ); }; refresh(); diff --git a/telecaster/models.py b/telecaster/models.py index cea73b6..6d20911 100644 --- a/telecaster/models.py +++ b/telecaster/models.py @@ -295,16 +295,18 @@ class Station(Model): audio.save() def start(self): - self.set_lock() - self.deefuzzer_setup() - self.deefuzzer_write_conf() - self.deefuzzer_start() + self.started = True +# self.set_lock() +# self.deefuzzer_setup() +# self.deefuzzer_write_conf() +# self.deefuzzer_start() def stop(self): - self.rec_stop() - time.sleep(2) - self.deefuzzer_stop() - self.del_lock() + self.started = False +# self.rec_stop() +# time.sleep(2) +# self.deefuzzer_stop() +# self.del_lock() class Record(Model): diff --git a/telecaster/station.py b/telecaster/old/station.py similarity index 100% rename from telecaster/station.py rename to telecaster/old/station.py diff --git a/telecaster/templates/telecaster/base.html b/telecaster/templates/telecaster/base.html index cc73ad9..42524a1 100644 --- a/telecaster/templates/telecaster/base.html +++ b/telecaster/templates/telecaster/base.html @@ -13,9 +13,13 @@ {% endblock javascript %} +{% block extrajavascript %} +{% endblock extrajavascript %} + + +
diff --git a/telecaster/templates/telecaster/start.html b/telecaster/templates/telecaster/start.html index 16fbdd8..636ee96 100644 --- a/telecaster/templates/telecaster/start.html +++ b/telecaster/templates/telecaster/start.html @@ -2,9 +2,18 @@ {% load telecaster_utils %} {% load i18n %} +{% block extrajavascript %} +jQuery(window).ready(function(){ + var a = jQuery('#_record'); + var f = jQuery('#_StationForm'); + a.unbind('click').click(function(){f.submit();return false;}); + }); +{% endblock extrajavascript %} + + {% block content %} -
{% csrf_token %} +{% csrf_token %}
@@ -28,8 +37,7 @@ {% block buttons %}
-Refresh -Record +Record Play Live Archives Trash diff --git a/telecaster/templates/telecaster/stop.html b/telecaster/templates/telecaster/stop.html index da72e9f..df58aea 100644 --- a/telecaster/templates/telecaster/stop.html +++ b/telecaster/templates/telecaster/stop.html @@ -2,49 +2,41 @@ {% load telecaster_utils %} {% load i18n %} -{% block javascript %} -{{ block.super }} - -{% endblock javascript %} - +{% block extrajavascript %} +jQuery(window).ready(function(){ + var a = jQuery('#_stop'); + var f = jQuery('#_StationForm'); + a.unbind('click').click(function(){f.submit();return false;}); + }); +{% endblock extrajavascript %} + {% block content %} -{% csrf_token %} +{% csrf_token %}
- +
{% endblock content %} + +{% block buttons %} +
+Stop +Play Live +Archives +Trash + +
+{% endblock buttons %} \ No newline at end of file diff --git a/telecaster/tools/tools.py b/telecaster/tools/tools.py index d3b481e..ee2d831 100644 --- a/telecaster/tools/tools.py +++ b/telecaster/tools/tools.py @@ -45,7 +45,9 @@ from xmltodict import * import socket import fcntl import struct +import acpi import subprocess +import pwd class SubProcessPipe: def __init__(self, command, stdin=None): @@ -161,3 +163,66 @@ def str_to_bool(string): def norm_string(string): pass + + +class Status(object): + + interfaces = ['eth0', 'eth1', 'eth2', 'eth0-eth2','eth3'] + acpi_states = {0: 'battery', 1: 'battery', 2: 'AC'} + + def __init__(self): + self.acpi = acpi.Acpi() + self.uid = os.getuid() + self.user = pwd.getpwuid(os.getuid())[0] + self.user_dir = '/home' + os.sep + self.user + os.sep + '.telecaster' + + def update(self): + self.acpi.update() + try: + self.temperature = self.acpi.temperature(0) + except: + self.temperature = 'N/A' + self.get_ids() + self.get_hosts() + + def to_dict(self): + status = [ + {'id': 'acpi_state','class': 'default', 'value': self.acpi_states[self.acpi.charging_state()], 'label': 'Power'}, + {'id': 'acpi_percent', 'class': 'default', 'value': str(self.acpi.percent()), 'label': 'Battery Charge'}, + {'id': 'temperature', 'class': 'default', 'value': self.temperature, 'label': 'Temperature'}, + {'id': 'jack_state', 'class': 'default', 'value': self.jacking, 'label': 'Jack server'}, + {'id': 'name', 'class': 'default', 'value': self.name, 'label': 'Name'}, + {'id': 'ip', 'class': 'default', 'value': self.ip, 'label': 'IP address'}, + {'id': 'encoder_state','class': 'default', 'value': self.writing, 'label': 'Encoder'}, + {'id': 'casting', 'class': 'default', 'value': self.casting, 'label': 'Broadcasting'}, + {'id': 'writing', 'class': 'default', 'value': self.writing, 'label': 'Recording'}, + ] + + for stat in status: + if stat['value'] == False or stat['value'] == 'localhost' or stat['value'] == 'battery': + stat['class'] = 'warning' + + return status + + def get_hosts(self): + ip = '' + for interface in self.interfaces: + try: + ip = get_ip_address(interface) + if ip: + self.ip = ip + break + except: + self.ip = '127.0.0.1' + self.url = 'http://' + self.ip + self.name = get_hostname() + + def get_ids(self): + edcast_pid = get_pid('edcast_jack', self.uid) + deefuzzer_pid = get_pid('/usr/bin/deefuzzer '+self.user_dir+os.sep+'deefuzzer.xml', self.uid) + jackd_pid = get_pid('jackd', self.uid) + if jackd_pid == []: + jackd_pid = get_pid('jackdbus', self.uid) + self.writing = edcast_pid != [] + self.casting = deefuzzer_pid != [] + self.jacking = jackd_pid != [] diff --git a/telecaster/urls.py b/telecaster/urls.py index bd06e8d..93d235f 100644 --- a/telecaster/urls.py +++ b/telecaster/urls.py @@ -48,21 +48,23 @@ htdocs = os.path.dirname(__file__) + '/htdocs' urlpatterns = patterns('', url(r'^$', web_view.index, name="telecaster-index"), - + url(r'^record/$', web_view.record, name="telecaster-record"), + url(r'^items/(?P.*)$', web_view.index, name="telecaster-item"), + # CSS+Images (FIXME: for developement only) - url(r'^css/(?P.*)$', 'django.views.static.serve', + url(r'^css/(?P.*)$', 'django.views.static.serve', {'document_root': htdocs+'/css'}, name="telecaster-css"), - url(r'images/(?P.*)$', 'django.views.static.serve', + url(r'images/(?P.*)$', 'django.views.static.serve', {'document_root': htdocs+'/images'}, name="telecaster-images"), - url(r'^js/(?P.*)$', 'django.views.static.serve', + url(r'^js/(?P.*)$', 'django.views.static.serve', {'document_root': htdocs+'/js'}, name="telecaster-js"), - + # JSON RPC - url(r'^json/$', jsonrpc_site.dispatch, name='jsonrpc_mountpoint'), + url(r'json/$', jsonrpc_site.dispatch, name='jsonrpc_mountpoint'), # for the graphical browser/web console only, omissible - url(r'^json/browse/', 'jsonrpc.views.browse', name="jsonrpc_browser"), - + url(r'json/browse/', 'jsonrpc.views.browse', name="jsonrpc_browser"), + ) diff --git a/telecaster/views.py b/telecaster/views.py index 85e2ea6..fb28394 100644 --- a/telecaster/views.py +++ b/telecaster/views.py @@ -1,7 +1,6 @@ # Create your views here. import os -import cgi import datetime import time import string @@ -55,40 +54,45 @@ class WebView(object): self.url = self.conf['infos']['url'] self.status = Status() - def index(self, request): + def index(self, request, id=None): stations = Station.objects.filter(started=True) - status = self.get_server_status() - - if stations or (status.writing or status.casting): - template = 'telecaster/stop.html' + if stations: # FIXME: manage multiple stations - station = stations[0] - station.set_conf(self.conf) - station.setup() + template = 'telecaster/stop.html' + if id: + station = Station.objects.get(id=id) + else: + station = stations[0] if request.method == 'POST': station.stop() time.sleep(2) + station.save() self.logger.write_info('stop') - return HttpResponseRedirect('/') - - else: - template = 'telecaster/start.html' - if request.method == 'POST': - station = StationForm(data=request.POST) - if station.is_valid(): - station.set_conf(self.conf) - station.setup() - station.start() - station.started = True - station.save() - self.logger.write_info('start') - time.sleep(2) - return HttpResponseRedirect('/') + return HttpResponseRedirect('/telecaster/record') else: - station = StationForm() - + return render(request, template, {'station': station, 'status': self.status.update(), + 'hidden_fields': self.hidden_fields, }) + else: + return HttpResponseRedirect('/telecaster/record') + + + def record(self, request): + template = 'telecaster/start.html' + if request.method == 'POST': + station = Station() + form = StationForm(data=request.POST, instance=station) + if form.is_valid(): + station.set_conf(self.conf) + station.setup() + station.start() + station.save() + self.logger.write_info('start') + time.sleep(2) + return HttpResponseRedirect('/telecaster/items/'+str(station.id)) + else: + form = StationForm() - return render(request, template, {'station': station, 'status': status, + return render(request, template, {'station': form, 'status': self.status.update(), 'hidden_fields': self.hidden_fields, }) @@ -112,64 +116,4 @@ class WebView(object): station = {} return station -class Status(object): - - interfaces = ['eth0', 'eth1', 'eth2', 'eth0-eth2','eth3'] - acpi_states = {0: 'battery', 1: 'battery', 2: 'AC'} - - def __init__(self): - self.acpi = acpi.Acpi() - self.uid = os.getuid() - self.user = pwd.getpwuid(os.getuid())[0] - self.user_dir = '/home' + os.sep + self.user + os.sep + '.telecaster' - - def update(self): - self.acpi.update() - try: - self.temperature = self.acpi.temperature(0) - except: - self.temperature = 'N/A' - self.get_ids() - self.get_hosts() - - def to_dict(self): - status = [ - {'id': 'acpi_state','class': 'default', 'value': self.acpi_states[self.acpi.charging_state()], 'label': 'Power'}, - {'id': 'acpi_percent', 'class': 'default', 'value': str(self.acpi.percent()), 'label': 'Battery Charge'}, - {'id': 'temperature', 'class': 'default', 'value': self.temperature, 'label': 'Temperature'}, - {'id': 'jack_state', 'class': 'default', 'value': self.jacking, 'label': 'Jack server'}, - {'id': 'name', 'class': 'default', 'value': self.name, 'label': 'Name'}, - {'id': 'ip', 'class': 'default', 'value': self.ip, 'label': 'IP address'}, - {'id': 'encoder_state','class': 'default', 'value': self.writing, 'label': 'Encoder'}, - {'id': 'casting', 'class': 'default', 'value': self.casting, 'label': 'Broadcasting'}, - {'id': 'writing', 'class': 'default', 'value': self.writing, 'label': 'Recording'}, - ] - - for stat in status: - if stat['value'] == False or stat['value'] == 'localhost' or stat['value'] == 'battery': - stat['class'] = 'warning' - - return status - def get_hosts(self): - ip = '' - for interface in self.interfaces: - try: - ip = get_ip_address(interface) - if ip: - self.ip = ip - break - except: - self.ip = '127.0.0.1' - self.url = 'http://' + self.ip - self.name = get_hostname() - - def get_ids(self): - edcast_pid = get_pid('edcast_jack', self.uid) - deefuzzer_pid = get_pid('/usr/bin/deefuzzer '+self.user_dir+os.sep+'deefuzzer.xml', self.uid) - jackd_pid = get_pid('jackd', self.uid) - if jackd_pid == []: - jackd_pid = get_pid('jackdbus', self.uid) - self.writing = edcast_pid != [] - self.casting = deefuzzer_pid != [] - self.jacking = jackd_pid != [] -- 2.39.5