-Fix unbound "response" variable when pypo got 404 error
-Sleep for few seconds after failing is_server_compatible instead of exiting and instantly being awoken by daemon tools (less stuff in log files) -removed some useless try/except blocks
This commit is contained in:
parent
6657f22d21
commit
c2960e9c2a
2 changed files with 20 additions and 42 deletions
|
@ -142,6 +142,8 @@ class AirTimeApiClient(ApiClientInterface):
|
||||||
logger.debug("Trying to contact %s", url)
|
logger.debug("Trying to contact %s", url)
|
||||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||||
|
|
||||||
|
version = -1
|
||||||
|
response = None
|
||||||
try:
|
try:
|
||||||
response = urllib.urlopen(url)
|
response = urllib.urlopen(url)
|
||||||
data = response.read()
|
data = response.read()
|
||||||
|
@ -150,29 +152,22 @@ class AirTimeApiClient(ApiClientInterface):
|
||||||
version = response_json['version']
|
version = response_json['version']
|
||||||
logger.debug("Airtime Version %s detected", version)
|
logger.debug("Airtime Version %s detected", version)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
try:
|
if e[1] == 401:
|
||||||
if e[1] == 401:
|
if (verbose):
|
||||||
if (verbose):
|
print '#####################################'
|
||||||
print '#####################################'
|
print '# YOUR API KEY SEEMS TO BE INVALID:'
|
||||||
print '# YOUR API KEY SEEMS TO BE INVALID:'
|
print '# ' + self.config["api_key"]
|
||||||
print '# ' + self.config["api_key"]
|
print '#####################################'
|
||||||
print '#####################################'
|
return -1
|
||||||
return False
|
|
||||||
except Exception, e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
if e[1] == 404:
|
||||||
if e[1] == 404:
|
if (verbose):
|
||||||
if (verbose):
|
print '#####################################'
|
||||||
print '#####################################'
|
print '# Unable to contact the Airtime-API'
|
||||||
print '# Unable to contact the Airtime-API'
|
print '# ' + url
|
||||||
print '# ' + url
|
print '#####################################'
|
||||||
print '#####################################'
|
return -1
|
||||||
return False
|
|
||||||
except Exception, e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
version = 0
|
|
||||||
logger.error("Unable to detect Airtime Version - %s, Response: %s", e, response)
|
logger.error("Unable to detect Airtime Version - %s, Response: %s", e, response)
|
||||||
|
|
||||||
return version
|
return version
|
||||||
|
@ -195,7 +190,7 @@ class AirTimeApiClient(ApiClientInterface):
|
||||||
|
|
||||||
def is_server_compatible(self, verbose = True):
|
def is_server_compatible(self, verbose = True):
|
||||||
version = self.__get_airtime_version(verbose)
|
version = self.__get_airtime_version(verbose)
|
||||||
if (version == 0 or version == False):
|
if (version == -1):
|
||||||
if (verbose):
|
if (verbose):
|
||||||
print 'Unable to get Airtime version number.'
|
print 'Unable to get Airtime version number.'
|
||||||
print
|
print
|
||||||
|
|
|
@ -3,29 +3,14 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Python part of radio playout (pypo)
|
Python part of radio playout (pypo)
|
||||||
|
|
||||||
The main functions are "fetch" (./pypo_cli.py -f) and "push" (./pypo_cli.py -p)
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
#import calendar
|
|
||||||
#import traceback
|
|
||||||
from optparse import *
|
from optparse import *
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
#import datetime
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
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 Queue import Queue
|
||||||
|
|
||||||
from pypopush import PypoPush
|
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("-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("-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("-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")
|
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):
|
def selfcheck(self):
|
||||||
self.api_client = api_client.api_client_factory(config)
|
self.api_client = api_client.api_client_factory(config)
|
||||||
if (not self.api_client.is_server_compatible()):
|
return self.api_client.is_server_compatible()
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
def set_export_source(self, export_source):
|
def set_export_source(self, export_source):
|
||||||
self.export_source = export_source
|
self.export_source = export_source
|
||||||
|
@ -130,7 +112,8 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
# initialize
|
# initialize
|
||||||
g = Global()
|
g = Global()
|
||||||
g.selfcheck()
|
|
||||||
|
while not g.selfcheck(): time.sleep(5000)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue