diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index bf749cfad..dddd6349f 100644 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -142,6 +142,8 @@ class AirTimeApiClient(ApiClientInterface): logger.debug("Trying to contact %s", url) url = url.replace("%%api_key%%", self.config["api_key"]) + version = -1 + response = None try: response = urllib.urlopen(url) data = response.read() @@ -150,29 +152,22 @@ class AirTimeApiClient(ApiClientInterface): version = response_json['version'] logger.debug("Airtime Version %s detected", version) except Exception, e: - try: - if e[1] == 401: - if (verbose): - print '#####################################' - print '# YOUR API KEY SEEMS TO BE INVALID:' - print '# ' + self.config["api_key"] - print '#####################################' - return False - except Exception, e: - pass + if e[1] == 401: + if (verbose): + print '#####################################' + print '# YOUR API KEY SEEMS TO BE INVALID:' + print '# ' + self.config["api_key"] + print '#####################################' + return -1 - try: - if e[1] == 404: - if (verbose): - print '#####################################' - print '# Unable to contact the Airtime-API' - print '# ' + url - print '#####################################' - return False - except Exception, e: - pass + if e[1] == 404: + if (verbose): + print '#####################################' + print '# Unable to contact the Airtime-API' + print '# ' + url + print '#####################################' + return -1 - version = 0 logger.error("Unable to detect Airtime Version - %s, Response: %s", e, response) return version @@ -195,7 +190,7 @@ class AirTimeApiClient(ApiClientInterface): def is_server_compatible(self, verbose = True): version = self.__get_airtime_version(verbose) - if (version == 0 or version == False): + if (version == -1): if (verbose): print 'Unable to get Airtime version number.' print diff --git a/python_apps/pypo/pypo-cli.py b/python_apps/pypo/pypo-cli.py index 87b24b8b4..77a1573fe 100755 --- a/python_apps/pypo/pypo-cli.py +++ b/python_apps/pypo/pypo-cli.py @@ -3,29 +3,14 @@ """ Python part of radio playout (pypo) - -The main functions are "fetch" (./pypo_cli.py -f) and "push" (./pypo_cli.py -p) """ - import time -#import calendar -#import traceback from optparse import * import sys import os import signal -#import datetime import logging import logging.config -#import shutil -#import urllib -#import urllib2 -#import pickle -#import telnetlib -#import random -#import string -#import operator -#import inspect from Queue import Queue from pypopush import PypoPush @@ -50,8 +35,6 @@ parser = OptionParser(usage=usage) parser.add_option("-v", "--compat", help="Check compatibility with server API version", default=False, action="store_true", dest="check_compat") parser.add_option("-t", "--test", help="Do a test to make sure everything is working properly.", default=False, action="store_true", dest="test") -parser.add_option("-f", "--fetch-scheduler", help="Fetch the schedule from server. This is a polling process that runs forever.", default=False, action="store_true", dest="fetch_scheduler") -parser.add_option("-p", "--push-scheduler", help="Push the schedule to Liquidsoap. This is a polling process that runs forever.", default=False, action="store_true", dest="push_scheduler") parser.add_option("-b", "--cleanup", help="Cleanup", default=False, action="store_true", dest="cleanup") parser.add_option("-c", "--check", help="Check the cached schedule and exit", default=False, action="store_true", dest="check") @@ -76,8 +59,7 @@ class Global: def selfcheck(self): self.api_client = api_client.api_client_factory(config) - if (not self.api_client.is_server_compatible()): - sys.exit() + return self.api_client.is_server_compatible() def set_export_source(self, export_source): self.export_source = export_source @@ -130,7 +112,8 @@ if __name__ == '__main__': # initialize g = Global() - g.selfcheck() + + while not g.selfcheck(): time.sleep(5000) logger = logging.getLogger()