CC-3484: Pypo: On bootup, it should grab station name and stream

label for liquidsoap

- fixed
- created new function set_bootstrap_variables()
This commit is contained in:
James 2012-03-20 16:41:15 -04:00
parent e76cffd8b0
commit d4142f8b8b
5 changed files with 21 additions and 20 deletions

View File

@ -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*/

View File

@ -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];

View File

@ -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%%'

View File

@ -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()

View File

@ -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: