]> git.parisson.com Git - telecaster-client.git/commitdiff
big cleanup in station setup, working with teleforma
authoryomguy <yomguy@parisson.com>
Thu, 12 Jul 2012 17:04:04 +0000 (19:04 +0200)
committeryomguy <yomguy@parisson.com>
Thu, 12 Jul 2012 17:04:04 +0000 (19:04 +0200)
telecaster/admin.py
telecaster/models.py
telecaster/urls.py
telecaster/views.py

index 316568c336528539684f0a8b726bcc4c1961cd61..60ed2a867d6318de1d8b40b05f8188b9db22575d 100644 (file)
@@ -3,3 +3,4 @@ from django.contrib import admin
 
 
 admin.site.register(Station)
+
index 2a43ab5a7fca7f86f0407430e991c64e1e6ef308..755dffeee8634bb015525fd916b1136ccdf1bcfa 100644 (file)
@@ -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()
 
index b722163c2d9f48a0b684399caaf025c0218d186c..fd3c0d39884754649544435e0d514662f1507926 100644 (file)
 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<id>.*)/detail/$', web_view.index, name="telecaster-station-detail"),
 
     # JSON RPC
     url(r'json/$', jsonrpc_site.dispatch, name='jsonrpc_mountpoint'),
index ab1248dab9791317a788dca4334d90304d272c3d..ea8f11c1b727bafad632795998316cba63e3179f 100644 (file)
@@ -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