From: yomguy Date: Thu, 12 Jul 2012 17:04:04 +0000 (+0200) Subject: big cleanup in station setup, working with teleforma X-Git-Tag: 0.9~68 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=d9e44a808699e639786575cb079840c60c2c6167;p=telecaster-client.git big cleanup in station setup, working with teleforma --- diff --git a/telecaster/admin.py b/telecaster/admin.py index 316568c..60ed2a8 100644 --- a/telecaster/admin.py +++ b/telecaster/admin.py @@ -3,3 +3,4 @@ from django.contrib import admin admin.site.register(Station) + diff --git a/telecaster/models.py b/telecaster/models.py index 2a43ab5..755dffe 100644 --- a/telecaster/models.py +++ b/telecaster/models.py @@ -56,7 +56,7 @@ from south.modelsinspector import add_introspection_rules from teleforma.models import * app_label = 'telecaster' - +spacer = '_-_' class ShortTextField(models.TextField): @@ -105,46 +105,24 @@ class Station(Model): return self.conference.description def setup(self, conf_file): - self.department = self.conference.course.department.name - self.organization = self.conference.course.department.organization.name - conf_dict = xml2dict(conf_file) - self.conf = conf_dict['telecaster'] + self.course = self.conference.course + self.department = self.course.department.name + self.organization = self.course.department.organization.name + self.mount_point = self.conference.slug + + self.conf = xml2dict(conf_file) self.date = datetime.datetime.now().strftime("%Y") self.time = datetime.datetime.now().strftime("%x-%X") self.time_txt = self.time.replace('/','_').replace(':','_').replace(' ','_') - self.user = pwd.getpwuid(os.getuid())[0] - self.user_dir = '/home' + os.sep + self.user + os.sep + '.telecaster' - self.rec_dir = self.conf['media']['rec_dir'] - self.deefuzzer_default_conf_file = self.conf['deefuzzer']['conf'] - self.deefuzzer_user_file = self.user_dir + os.sep + 'deefuzzer.xml' - self.bitrate = self.conf['media']['bitrate'] - self.record = str_to_bool(self.conf['media']['record']) - self.rec_dir = self.conf['media']['rec_dir'] - self.play_dir = self.conf['media']['play_dir'] - self.ogg_quality = self.conf['media']['ogg_quality'] - self.format = self.conf['media']['format'] - self.channels = int(self.conf['media']['channels']) - self.server_name = [self.organization, self.department, self.conference.slug] - self.ServerDescription = clean_string(self.description) - self.ServerName = clean_string('_-_'.join(self.server_name)) - self.mount_point = self.conference.slug - self.filename = clean_string('_-_'.join(self.description[1:])) + \ - '-' + self.time_txt + '.' + self.format - self.output_dir = self.rec_dir + os.sep + self.date + os.sep + self.department - self.file_dir = self.output_dir + os.sep + self.ServerName + self.uid = os.getuid() - self.new_title = clean_string('-'.join(self.description)) - self.short_title = self.new_title - self.genre = self.conf['infos']['genre'] - self.encoder = 'TeleCaster by Parisson' + self.user = pwd.getpwuid(self.uid)[0] + self.user_dir = '/home' + os.sep + self.user + os.sep + '.telecaster' + self.deefuzzer_user_file = self.user_dir + os.sep + 'station_' + self.public_id + '.xml' + self.encoder = 'TeleCaster system by Parisson' self.save() - if not os.path.exists(self.file_dir): - os.makedirs(self.file_dir) - - self.deefuzzer_dict = xml2dict(self.deefuzzer_default_conf_file) - - for station in self.deefuzzer_dict['deefuzzer']['station']: + for station in self.conf['deefuzzer']['station']: if station['control']['mode'] == '1': port = int(station['control']['port']) osc = OSC.objects.filter(port=port) @@ -159,21 +137,18 @@ class Station(Model): # self.conf['play_port'] = '8000' def deefuzzer_setup(self): - i = 0 - for station in self.deefuzzer_dict['deefuzzer']['station']: + for station in self.conf['deefuzzer']['station']: + output_dir = os.sep.join([station['record']['dir'], + self.date, self.department, + unicode(self.course), self.public_id]) + if not os.path.exists(output_dir): + os.makedirs(output_dir) station['infos']['short_name'] = self.mount_point - station['infos']['name'] = self.ServerName - station['infos']['description'] = self.ServerDescription.replace(' ','_') - station['infos']['genre'] = self.genre - station['media']['bitrate'] = self.bitrate - station['media']['dir'] = self.play_dir - station['record']['dir'] = self.file_dir - station['relay']['mode'] = '1' + station['infos']['name'] = self.description + station['infos']['description'] = self.description + station['record']['dir'] = output_dir station['relay']['author'] = unicode(self.conference.professor) - self.deefuzzer_dict['deefuzzer']['station'][i] = station - i += 1 - print self.deefuzzer_dict - self.deefuzzer_xml = dicttoxml(self.deefuzzer_dict) + self.deefuzzer_xml = dicttoxml(self.conf) def deefuzzer_write_conf(self): conf_file = open(self.deefuzzer_user_file,'w') @@ -183,7 +158,7 @@ class Station(Model): def deefuzzer_start(self): command = 'deefuzzer ' + self.deefuzzer_user_file + ' > /dev/null &' os.system(command) - time.sleep(2) + time.sleep(1) self.pid = get_pid('deefuzzer', args=self.deefuzzer_user_file) self.save() @@ -239,7 +214,7 @@ class Station(Model): self.started = False self.datetime_stop = datetime.datetime.now() self.rec_stop() - time.sleep(2) + time.sleep(1) self.deefuzzer_stop() self.save() diff --git a/telecaster/urls.py b/telecaster/urls.py index b722163..fd3c0d3 100644 --- a/telecaster/urls.py +++ b/telecaster/urls.py @@ -37,16 +37,13 @@ from django.conf.urls.defaults import * from django.conf import settings from telecaster.models import * -from telecaster.views import StationView +from telecaster.views import * from jsonrpc import jsonrpc_site import os.path # initialization -web_view = StationView() urlpatterns = patterns('', - url(r'^$', web_view.index, name="telecaster-index"), - url(r'^stations/(?P.*)/detail/$', web_view.index, name="telecaster-station-detail"), # JSON RPC url(r'json/$', jsonrpc_site.dispatch, name='jsonrpc_mountpoint'), diff --git a/telecaster/views.py b/telecaster/views.py index ab1248d..ea8f11c 100644 --- a/telecaster/views.py +++ b/telecaster/views.py @@ -35,40 +35,16 @@ def render(request, template, data = None, mimetype = None): return render_to_response(template, data, context_instance=RequestContext(request), mimetype=mimetype) -class StationView(object): +def get_host(request): + host = request.META['HTTP_HOST'] + if ':' in host: + host = host.split(':')[0] + return host - hidden_fields = ['started', 'datetime_start', 'datetime_stop', 'public_id'] - def __init__(self): - self.uid = os.getuid() - self.user = pwd.getpwuid(os.getuid())[0] - self.user_dir = '/home' + os.sep + self.user + os.sep + '.telecaster' - if not os.path.exists(self.user_dir): - os.makedirs(self.user_dir) - self.conf_file = settings.TELECASTER_CONF - conf_dict = xml2dict(self.conf_file) - self.conf = conf_dict['telecaster'] - self.title = self.conf['infos']['name'] - self.log_file = self.conf['log'] - self.logger = Logger(self.log_file) - self.url = self.conf['infos']['url'] - self.status = Status() - - def index(self, request): - template = 'telecaster/base.html' - stations = Station.objects.filter(started=True) - if stations: - messages.warning(request, 'A station is already started !') - form = StationForm() - return render(request, template, {'station': form, 'hidden_fields': self.hidden_fields, - 'host': self.get_host(request) }) +class StatusView(object): - def get_host(self, request): - host = request.META['HTTP_HOST'] - if ':' in host: - host = host.split(':')[0] - return host @jsonrpc_method('telecaster.get_server_status') def get_server_status(request): @@ -87,20 +63,8 @@ class StationView(object): @jsonrpc_method('telecaster.start') def start(request, station_dict): - if isinstance(station_dict, dict): - station = Station(public_id=dict['public_id']) - station.configure(station_dict) - conf = xml2dict(settings.TELECASTER_CONF) - conf = conf['telecaster'] - station.set_conf(conf) - station.setup() - station.start() - else: - messages.error(request, 'Bad station dictionary') + pass @jsonrpc_method('telecaster.stop') def stop(request): - stations = Station.objects.filter(started=True) - for station in stations: - station.stop() - + pass