From 3c6aff093ea2aea66389da8cdab66a7af9056944 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 14 Mar 2012 10:22:41 -0400 Subject: [PATCH] CC-3437: Live Stream: Liquidsoap(Pypo) should preserve the last switch status when it restarts. - Pypo contacts airtime on bootup and ask what the last switch status was --- python_apps/api_clients/api_client.cfg | 2 ++ python_apps/api_clients/api_client.py | 27 +++++++++++++++++++++++--- python_apps/pypo/pypofetch.py | 14 +++++++++++-- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/python_apps/api_clients/api_client.cfg b/python_apps/api_clients/api_client.cfg index 4aab5816b..cc73bd534 100644 --- a/python_apps/api_clients/api_client.cfg +++ b/python_apps/api_clients/api_client.cfg @@ -107,3 +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%%' + diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index 5dda980b5..766908db6 100755 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -602,7 +602,7 @@ class AirTimeApiClient(ApiClientInterface): This function updates status of mounted file system information on airtime """ def update_file_system_mount(self, added_dir, removed_dir): - logger = logging.getLogger() + 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["update_fs_mount"]) @@ -629,7 +629,7 @@ class AirTimeApiClient(ApiClientInterface): and will call appropriate function on Airtime. """ def handle_watched_dir_missing(self, dir): - logger = logging.getLogger() + 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["handle_watched_dir_missing"]) @@ -644,4 +644,25 @@ class AirTimeApiClient(ApiClientInterface): top = traceback.format_exc() logger.error('Exception: %s', e) logger.error("traceback: %s", top) - + + """ + Retrive current switch status of streams sources + """ + def get_switch_status(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 = 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) + except Exception, e: + import traceback + top = traceback.format_exc() + logger.error('Exception: %s', e) + logger.error("traceback: %s", top) + return response + \ No newline at end of file diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index aeb50b7a4..c29aac61f 100644 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -125,6 +125,16 @@ class PypoFetch(Thread): except Exception, e: self.logger.debug(e) self.logger.debug('Could not connect to liquidsoap') + + """ + This check current switch status from Airtime and update the status + """ + 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(): + self.switch_source(k, v) def stop_current_show(self): self.logger.debug('Notifying Liquidsoap to stop playback.') @@ -249,8 +259,7 @@ class PypoFetch(Thread): """ updates the status of liquidsoap connection to the streaming server This fucntion updates the bootup time variable in liquidsoap script - """ - def update_liquidsoap_connection_status(self): + """ tn = telnetlib.Telnet(LS_HOST, LS_PORT) # update the boot up time of liquidsoap. Since liquidsoap is not restarting, # we are manually adjusting the bootup time variable so the status msg will get @@ -512,6 +521,7 @@ class PypoFetch(Thread): if success: self.logger.info("Bootstrap schedule received: %s", self.schedule_data) self.process_schedule(self.schedule_data, True) + self.check_switch_status() loops = 1 while True: