From 3cd85ca4b3e355ea9f510525623aad9297267f02 Mon Sep 17 00:00:00 2001 From: yomguy Date: Mon, 4 Jul 2011 11:14:15 +0200 Subject: [PATCH] cleanup, fix deefuzzer path, fix get_pid --- station.py | 14 +++++++++----- telecaster.py | 42 +++++++++++++++++++++++------------------- tests.py | 23 +++++++++++++++++++++++ tools/tools.py | 2 +- webview.py | 3 +-- 5 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 tests.py diff --git a/station.py b/station.py index 0d8155e..c16da88 100644 --- a/station.py +++ b/station.py @@ -99,7 +99,11 @@ class Station(Conference): self.file_dir = self.output_dir + os.sep + self.ServerName self.uid = os.getuid() self.odd_pid = get_pid('^edcast_jack', self.uid) - self.deefuzzer_pid = get_pid('/usr/bin/deefuzzer '+self.deefuzzer_user_file, self.uid) + if os.path.exists('/usr/local/bin/deefuzzer'): + self.deefuzzer_path = '/usr/local/bin/deefuzzer' + elif os.path.exists('/usr/bin/deefuzzer'): + self.deefuzzer_path = '/usr/bin/deefuzzer' + self.deefuzzer_pid = get_pid(self.deefuzzer_path+' '+self.deefuzzer_user_file, self.uid) self.new_title = clean_string('-'.join(self.server_name)+'-'+self.session+'-'+self.professor+'-'+self.comment) self.short_title = clean_string('-'.join(self.conference)+'-'+self.session+'-'+self.professor+'-'+self.comment) self.genre = self.conf['infos']['genre'] @@ -168,13 +172,13 @@ class Station(Conference): os.remove(self.lock_file) def deefuzzer_stop(self): - if len(self.deefuzzer_pid) != 0: - os.system('kill -9 '+self.deefuzzer_pid[0]) + if len(self.deefuzzer_pid) != 0: + os.system('kill -9 '+self.deefuzzer_pid[0]) def rec_stop(self): if len(self.deefuzzer_pid) != 0: - for port in self.deefuzzer_osc_ports: - target = liblo.Address(int(port)) + for port in self.deefuzzer_osc_ports: + target = liblo.Address(int(port)) liblo.send(target, '/record', 0) def mp3_convert(self): diff --git a/telecaster.py b/telecaster.py index b68a15c..7973641 100755 --- a/telecaster.py +++ b/telecaster.py @@ -69,7 +69,11 @@ class TeleCaster: if not os.path.exists(self.user_dir): os.makedirs(self.user_dir) self.lock_file = self.user_dir + os.sep + 'telecaster.lock' - + if os.path.exists('/usr/local/bin/deefuzzer'): + self.deefuzzer_path = '/usr/local/bin/deefuzzer' + elif os.path.exists('/usr/bin/deefuzzer'): + self.deefuzzer_path = '/usr/bin/deefuzzer' + def transition_head(self): html_file = open('telecaster_starting_head.html', 'r') html = html_file.read() @@ -84,7 +88,8 @@ class TeleCaster: def main(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) + + deefuzzer_pid = get_pid(self.deefuzzer_path+' '+self.user_dir+os.sep+'deefuzzer.xml', self.uid) writing = edcast_pid != [] casting = deefuzzer_pid != [] form = WebView(self.conf, version) @@ -92,7 +97,7 @@ class TeleCaster: if deefuzzer_pid == [] and form.has_key("action") and \ form.has_key("department") and form.has_key("conference") and \ form.has_key("session") and form["action"].value == "start": - + self.conference_dict = {'title': '', 'department': '', 'conference': '', @@ -100,17 +105,17 @@ class TeleCaster: 'professor': '', 'comment': ''} - for data in self.conference_dict: - if not form.has_key(data): - self.conference_dict[data] = 'Inconnu' - else: - value = form.getfirst(data) - if '....' in value: - self.conference_dict[data] = 'Inconnu' - else: - self.conference_dict[data] = value - - self.conference_dict['title'] = self.title + for data in self.conference_dict: + if not form.has_key(data): + self.conference_dict[data] = 'Inconnu' + else: + value = form.getfirst(data) + if '....' in value: + self.conference_dict[data] = 'Inconnu' + else: + self.conference_dict[data] = value + + self.conference_dict['title'] = self.title s = Station(self.conf_file, self.conference_dict, self.lock_file) s.start() time.sleep(2) @@ -123,13 +128,13 @@ class TeleCaster: self.logger.write_info('started') elif deefuzzer_pid and form.has_key("action") and form["action"].value == "stop": - self.logger.write_info('stopping') + self.logger.write_info('stopping') if os.path.exists(self.lock_file): self.conference_dict = get_conference_from_lock(self.lock_file) - s = Station(self.conf_file, self.conference_dict, self.lock_file) + s = Station(self.conf_file, self.conference_dict, self.lock_file) s.stop() - time.sleep(2) - self.main() + time.sleep(2) + self.main() elif deefuzzer_pid == []: form.start_form(writing, casting) @@ -138,7 +143,6 @@ class TeleCaster: elif deefuzzer_pid != []: os.system('kill -9 '+deefuzzer_pid[0]) self.main() - conf_file = '/etc/telecaster/telecaster.xml' diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..2247054 --- /dev/null +++ b/tests.py @@ -0,0 +1,23 @@ +""" +This file demonstrates two different styles of tests (one doctest and one +unittest). These will both pass when you run "manage.py test". + +Replace these with more appropriate tests for your application. +""" + +from django.test import TestCase + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.failUnlessEqual(1 + 1, 2) + +__test__ = {"doctest": """ +Another way to test that 1 + 1 is equal to 2. + +>>> 1 + 1 == 2 +True +"""} + diff --git a/tools/tools.py b/tools/tools.py index 776bf97..80d7371 100644 --- a/tools/tools.py +++ b/tools/tools.py @@ -108,7 +108,7 @@ def get_pid(proc,uid): pid = proc.split(' ')[0] command = ' '.join(proc.split(' ')[1:])[:-1] pids.append(pid) - if len(pids) == 1: + if len(pids) < 1: return [] else: return [pids[0]] diff --git a/webview.py b/webview.py index 48cee74..a0a3587 100644 --- a/webview.py +++ b/webview.py @@ -1,6 +1,5 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# *-* coding: utf-8 *-* """ telecaster @@ -231,7 +230,7 @@ class WebView(FieldStorage): self.casting = writing self.writing = casting self.refresh = False - self.mount_point = 'telecaster_live.' + self.format + self.mount_point = 'telecaster_live.' + self.format self.header() self.javascript() self.sub_header() -- 2.39.5