From d4142f8b8ba9fd95abf6adb0d90d6d85a95566be Mon Sep 17 00:00:00 2001 From: James <james@james-HP-Pavilion-g6-Notebook-PC> Date: Tue, 20 Mar 2012 16:41:15 -0400 Subject: [PATCH] CC-3484: Pypo: On bootup, it should grab station name and stream label for liquidsoap - fixed - created new function set_bootstrap_variables() --- .../application/controllers/ApiController.php | 8 +++++--- .../application/models/StreamSetting.php | 4 ---- python_apps/api_clients/api_client.cfg | 2 +- python_apps/api_clients/api_client.py | 8 ++++---- python_apps/pypo/pypofetch.py | 19 +++++++++++-------- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 5a0d53cd9..77069c8fc 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -30,7 +30,7 @@ class ApiController extends Zend_Controller_Action ->addActionContext('rabbitmq-do-push', 'json') ->addActionContext('check-live-stream-auth', 'json') ->addActionContext('update-source-status', 'json') - ->addActionContext('get-switch-status', 'json') + ->addActionContext('get-bootstrap-info', 'json') ->initContext(); } @@ -1000,13 +1000,15 @@ class ApiController extends Zend_Controller_Action Application_Model_RabbitMq::PushSchedule(); } - public function getSwitchStatusAction(){ + public function getBootstrapInfoAction(){ $live_dj = Application_Model_Preference::GetSourceSwitchStatus('live_dj'); $master_dj = Application_Model_Preference::GetSourceSwitchStatus('master_dj'); $scheduled_play = Application_Model_Preference::GetSourceSwitchStatus('scheduled_play'); $res = array("live_dj"=>$live_dj, "master_dj"=>$master_dj, "scheduled_play"=>$scheduled_play); - $this->view->status = $res; + $this->view->switch_status = $res; + $this->view->station_name = Application_Model_Preference::GetStationName(); + $this->view->stream_label = Application_Model_Preference::GetStreamLabelFormat(); } /* This is used but Liquidsoap to check authentication of live streams*/ diff --git a/airtime_mvc/application/models/StreamSetting.php b/airtime_mvc/application/models/StreamSetting.php index bc0fe6f06..ab05fadb9 100644 --- a/airtime_mvc/application/models/StreamSetting.php +++ b/airtime_mvc/application/models/StreamSetting.php @@ -154,10 +154,6 @@ class Application_Model_StreamSetting { } else if ($key == "output_sound_device_type") { $sql = "UPDATE cc_stream_setting SET value='$d' WHERE keyname='$key'"; $CC_DBC->query($sql); - } else if ($key == "streamFormat"){ - // this goes into cc_pref table - Logging::log("Insert stream label format $d"); - Application_Model_Preference::SetStreamLabelFormat($d); } else if (is_array($d)) { $temp = explode('_', $key); $prefix = $temp[0]; diff --git a/python_apps/api_clients/api_client.cfg b/python_apps/api_clients/api_client.cfg index cc73bd534..2ff113b9c 100644 --- a/python_apps/api_clients/api_client.cfg +++ b/python_apps/api_clients/api_client.cfg @@ -107,5 +107,5 @@ check_live_stream_auth = 'check-live-stream-auth/format/json/api_key/%%api_key%% #URL to update source status update_source_status = 'update-source-status/format/json/api_key/%%api_key%%/sourcename/%%sourcename%%/status/%%status%%' -get_switch_status = 'get-switch-status/format/json/api_key/%%api_key%%' +get_bootstrap_info = 'get-bootstrap-info/format/json/api_key/%%api_key%%' diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index 766908db6..4ff0f1cf9 100755 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -646,19 +646,19 @@ class AirTimeApiClient(ApiClientInterface): logger.error("traceback: %s", top) """ - Retrive current switch status of streams sources + Retrive infomations needed on bootstrap time """ - def get_switch_status(self): + def get_bootstrap_info(self): logger = self.logger try: - url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["get_switch_status"]) + url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["get_bootstrap_info"]) url = url.replace("%%api_key%%", self.config["api_key"]) req = urllib2.Request(url) response = urllib2.urlopen(req).read() response = json.loads(response) - logger.info("Switch status retrieved %s", response) + logger.info("Bootstrap info retrieved %s", response) except Exception, e: import traceback top = traceback.format_exc() diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index 7189f5ca9..67285c366 100644 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -139,16 +139,19 @@ class PypoFetch(Thread): self.logger.error(str(e)) finally: self.telnet_lock.release() - + """ - This check current switch status from Airtime and update the status + grabs some information that are needed to be set on bootstrap time + and configures them """ - def check_switch_status(self): - self.logger.debug('Checking current switch status with Airtime') - switch_status = self.api_client.get_switch_status() - self.logger.debug('switch_status:%s',switch_status) - for k, v in switch_status['status'].iteritems(): + def set_bootstrap_variables(self): + self.logger.debug('Getting information needed on bootstrap from Airtime') + info = self.api_client.get_bootstrap_info() + self.logger.debug('info:%s',info) + for k, v in info['switch_status'].iteritems(): self.switch_source(k, v) + self.update_liquidsoap_stream_format(info['stream_label']) + self.update_liquidsoap_station_name(info['station_name']) def regenerateLiquidsoapConf(self, setting_p): existing = {} @@ -509,7 +512,7 @@ class PypoFetch(Thread): if success: self.logger.info("Bootstrap schedule received: %s", self.schedule_data) self.process_schedule(self.schedule_data) - self.check_switch_status() + self.set_bootstrap_variables() loops = 1 while True: