install successfully using py3

This commit is contained in:
Kyle Robbertze 2020-01-16 16:32:51 +02:00
parent cf2dda4532
commit 8346e89e99
41 changed files with 259 additions and 287 deletions

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import traceback
"""
@ -76,7 +76,7 @@ logger = rootLogger
try:
config = ConfigObj('/etc/airtime/airtime.conf')
except Exception, e:
except Exception as e:
logger.error('Error loading config file: %s', e)
sys.exit()

View file

@ -1,10 +1,10 @@
""" Runs Airtime liquidsoap
"""
from __future__ import print_function
import argparse
import os
import generate_liquidsoap_cfg
from . import generate_liquidsoap_cfg
import logging
import subprocess

View file

@ -1,4 +1,4 @@
from __future__ import print_function
import logging
import os
import sys
@ -14,7 +14,7 @@ def generate_liquidsoap_config(ss):
fh.write("################################################\n")
fh.write("# The ignore() lines are to squash unused variable warnings\n")
for key, value in data.iteritems():
for key, value in data.items():
try:
if not "port" in key and not "bitrate" in key: # Stupid hack
raise ValueError()
@ -49,7 +49,7 @@ def run():
ss = ac.get_stream_setting()
generate_liquidsoap_config(ss)
successful = True
except Exception, e:
except Exception as e:
print("Unable to connect to the Airtime server.")
logging.error(str(e))
logging.error("traceback: %s", traceback.format_exc())

View file

@ -1,4 +1,4 @@
from __future__ import print_function
from api_clients import *
import sys

View file

@ -13,7 +13,7 @@ try:
tn.write('exit\n')
tn.read_all()
except Exception, e:
print('Error loading config file: %s', e)
except Exception as e:
print(('Error loading config file: %s', e))
sys.exit()

View file

@ -1,7 +1,7 @@
"""
Python part of radio playout (pypo)
"""
from __future__ import absolute_import
import locale
import logging
@ -16,10 +16,11 @@ from api_clients import api_client
from configobj import ConfigObj
from datetime import datetime
from optparse import OptionParser
import importlib
try:
from queue import Queue
except ImportError: # Python 2.7.5 (CentOS 7)
from Queue import Queue
from queue import Queue
from threading import Lock
from .listenerstat import ListenerStat
@ -119,7 +120,7 @@ try:
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)
except Exception as e:
print("Couldn't configure logging", e)
print(("Couldn't configure logging", e))
sys.exit(1)
@ -160,7 +161,7 @@ def configure_locale():
"New locale set to: %s", locale.setlocale(locale.LC_ALL, new_locale)
)
reload(sys)
importlib.reload(sys)
sys.setdefaultencoding("UTF-8")
current_locale_encoding = locale.getlocale()[1].lower()
logger.debug("sys default encoding %s", sys.getdefaultencoding())

View file

@ -1,5 +1,5 @@
from threading import Thread
import urllib2
import urllib.request, urllib.error, urllib.parse
import defusedxml.minidom
import base64
from datetime import datetime
@ -44,13 +44,13 @@ class ListenerStat(Thread):
user_agent = "Mozilla/5.0 (Linux; rv:22.0) Gecko/20130405 Firefox/22.0"
header["User-Agent"] = user_agent
req = urllib2.Request(
req = urllib.request.Request(
#assuming that the icecast stats path is /admin/stats.xml
#need to fix this
url=url,
headers=header)
f = urllib2.urlopen(req, timeout=ListenerStat.HTTP_REQUEST_TIMEOUT)
f = urllib.request.urlopen(req, timeout=ListenerStat.HTTP_REQUEST_TIMEOUT)
document = f.read()
return document
@ -109,7 +109,7 @@ class ListenerStat(Thread):
#Note that there can be optimizations done, since if all three
#streams are the same server, we will still initiate 3 separate
#connections
for k, v in stream_parameters.items():
for k, v in list(stream_parameters.items()):
if v["enable"] == 'true':
try:
if v["output"] == "icecast":
@ -146,7 +146,7 @@ class ListenerStat(Thread):
if stats:
self.push_stream_stats(stats)
except Exception, e:
except Exception as e:
self.logger.error('Exception: %s', e)
time.sleep(120)

View file

@ -11,14 +11,14 @@ import subprocess
import signal
from datetime import datetime
import traceback
import pure
from . import pure
import mimetypes
from Queue import Empty
from queue import Empty
from threading import Thread, Timer
from subprocess import Popen, PIPE
from api_clients import api_client
from timeout import ls_timeout
from .timeout import ls_timeout
def keyboardInterruptHandler(signum, frame):
@ -65,7 +65,7 @@ class PypoFetch(Thread):
"""
self.logger.debug("Cache dir does not exist. Creating...")
os.makedirs(dir)
except Exception, e:
except Exception as e:
pass
self.schedule_data = []
@ -120,7 +120,7 @@ class PypoFetch(Thread):
if self.listener_timeout < 0:
self.listener_timeout = 0
self.logger.info("New timeout: %s" % self.listener_timeout)
except Exception, e:
except Exception as e:
top = traceback.format_exc()
self.logger.error('Exception: %s', e)
self.logger.error("traceback: %s", top)
@ -151,13 +151,13 @@ class PypoFetch(Thread):
self.logger.debug('Getting information needed on bootstrap from Airtime')
try:
info = self.api_client.get_bootstrap_info()
except Exception, e:
except Exception as e:
self.logger.error('Unable to get bootstrap info.. Exiting pypo...')
self.logger.error(str(e))
self.logger.debug('info:%s', info)
commands = []
for k, v in info['switch_status'].iteritems():
for k, v in info['switch_status'].items():
commands.append(self.switch_source_temp(k, v))
stream_format = info['stream_label']
@ -194,11 +194,11 @@ class PypoFetch(Thread):
tn.read_all()
self.logger.info("Liquidsoap is up and running")
break
except Exception, e:
except Exception as e:
#sleep 0.5 seconds and try again
time.sleep(0.5)
except Exception, e:
except Exception as e:
self.logger.error(e)
finally:
if self.telnet_lock.locked():
@ -237,7 +237,7 @@ class PypoFetch(Thread):
tn.write('exit\n')
output = tn.read_all()
except Exception, e:
except Exception as e:
self.logger.error(str(e))
finally:
self.telnet_lock.release()
@ -271,7 +271,7 @@ class PypoFetch(Thread):
tn.write(command)
tn.write('exit\n')
tn.read_all()
except Exception, e:
except Exception as e:
self.logger.error("Exception %s", e)
finally:
self.telnet_lock.release()
@ -288,7 +288,7 @@ class PypoFetch(Thread):
tn.write(command)
tn.write('exit\n')
tn.read_all()
except Exception, e:
except Exception as e:
self.logger.error("Exception %s", e)
finally:
self.telnet_lock.release()
@ -306,11 +306,11 @@ class PypoFetch(Thread):
tn.write(command)
tn.write('exit\n')
tn.read_all()
except Exception, e:
except Exception as e:
self.logger.error(str(e))
finally:
self.telnet_lock.release()
except Exception, e:
except Exception as e:
self.logger.error("Exception %s", e)
"""
@ -336,7 +336,7 @@ class PypoFetch(Thread):
download_dir = self.cache_dir
try:
os.makedirs(download_dir)
except Exception, e:
except Exception as e:
pass
media_copy = {}
@ -344,7 +344,7 @@ class PypoFetch(Thread):
media_item = media[key]
if (media_item['type'] == 'file'):
fileExt = self.sanity_check_media_item(media_item)
dst = os.path.join(download_dir, unicode(media_item['id']) + unicode(fileExt))
dst = os.path.join(download_dir, str(media_item['id']) + str(fileExt))
media_item['dst'] = dst
media_item['file_ready'] = False
media_filtered[key] = media_item
@ -357,7 +357,7 @@ class PypoFetch(Thread):
self.media_prepare_queue.put(copy.copy(media_filtered))
except Exception, e: self.logger.error("%s", e)
except Exception as e: self.logger.error("%s", e)
# Send the data to pypo-push
self.logger.debug("Pushing to pypo-push")
@ -366,7 +366,7 @@ class PypoFetch(Thread):
# cleanup
try: self.cache_cleanup(media)
except Exception, e: self.logger.error("%s", e)
except Exception as e: self.logger.error("%s", e)
#do basic validation of file parameters. Useful for debugging
#purposes
@ -408,7 +408,7 @@ class PypoFetch(Thread):
for mkey in media:
media_item = media[mkey]
if media_item['type'] == 'file':
scheduled_file_set.add(unicode(media_item["id"]) + unicode(media_item["file_ext"]))
scheduled_file_set.add(str(media_item["id"]) + str(media_item["file_ext"]))
expired_files = cached_file_set - scheduled_file_set
@ -426,7 +426,7 @@ class PypoFetch(Thread):
self.logger.info("File '%s' removed" % path)
else:
self.logger.info("File '%s' not removed. Still busy!" % path)
except Exception, e:
except Exception as e:
self.logger.error("Problem removing file '%s'" % f)
self.logger.error(traceback.format_exc())

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from threading import Thread
from Queue import Empty
from ConfigParser import NoOptionError
from queue import Empty
from configparser import NoOptionError
import logging
import shutil
@ -12,7 +12,7 @@ import os
import sys
import stat
import requests
import ConfigParser
import configparser
import json
import hashlib
from requests.exceptions import ConnectionError, HTTPError, Timeout
@ -44,7 +44,7 @@ class PypoFile(Thread):
dst_exists = True
try:
dst_size = os.path.getsize(dst)
except Exception, e:
except Exception as e:
dst_exists = False
do_copy = False
@ -69,11 +69,11 @@ class PypoFile(Thread):
baseurl = self._config.get(CONFIG_SECTION, 'base_url')
try:
port = self._config.get(CONFIG_SECTION, 'base_port')
except NoOptionError, e:
except NoOptionError as e:
port = 80
try:
protocol = self._config.get(CONFIG_SECTION, 'protocol')
except NoOptionError, e:
except NoOptionError as e:
protocol = str(("http", "https")[int(port) == 443])
try:
@ -103,7 +103,7 @@ class PypoFile(Thread):
media_item["filesize"] = file_size
media_item['file_ready'] = True
except Exception, e:
except Exception as e:
self.logger.error("Could not copy from %s to %s" % (src, dst))
self.logger.error(e)
@ -172,7 +172,7 @@ class PypoFile(Thread):
def read_config_file(self, config_path):
"""Parse the application's config file located at config_path."""
config = ConfigParser.SafeConfigParser(allow_no_value=True)
config = configparser.SafeConfigParser(allow_no_value=True)
try:
config.readfp(open(config_path))
except IOError as e:
@ -202,14 +202,14 @@ class PypoFile(Thread):
"""
try:
self.media = self.media_queue.get_nowait()
except Empty, e:
except Empty as e:
pass
media_item = self.get_highest_priority_media_item(self.media)
if media_item is not None:
self.copy_file(media_item)
except Exception, e:
except Exception as e:
import traceback
top = traceback.format_exc()
self.logger.error(str(e))
@ -221,7 +221,7 @@ class PypoFile(Thread):
Entry point of the thread
"""
try: self.main()
except Exception, e:
except Exception as e:
top = traceback.format_exc()
self.logger.error('PypoFile Exception: %s', top)
time.sleep(5)

View file

@ -7,7 +7,7 @@ import sys
import time
from Queue import Empty
from queue import Empty
import signal
def keyboardInterruptHandler(signum, frame):
@ -38,7 +38,7 @@ class PypoLiqQueue(Thread):
time_until_next_play)
media_schedule = self.queue.get(block=True, \
timeout=time_until_next_play)
except Empty, e:
except Empty as e:
#Time to push a scheduled item.
media_item = schedule_deque.popleft()
self.pypo_liquidsoap.play(media_item)
@ -82,7 +82,7 @@ class PypoLiqQueue(Thread):
def run(self):
try: self.main()
except Exception, e:
except Exception as e:
self.logger.error('PypoLiqQueue Exception: %s', traceback.format_exc())

View file

@ -1,10 +1,10 @@
from pypofetch import PypoFetch
from telnetliquidsoap import TelnetLiquidsoap
from .pypofetch import PypoFetch
from .telnetliquidsoap import TelnetLiquidsoap
from datetime import datetime
from datetime import timedelta
import eventtypes
from . import eventtypes
import time
class PypoLiquidsoap():
@ -22,7 +22,7 @@ class PypoLiquidsoap():
logger,\
host,\
port,\
self.liq_queue_tracker.keys())
list(self.liq_queue_tracker.keys()))
def get_telnet_dispatcher(self):
return self.telnet_liquidsoap
@ -120,13 +120,12 @@ class PypoLiquidsoap():
try:
scheduled_now_files = \
filter(lambda x: x["type"] == eventtypes.FILE, scheduled_now)
[x for x in scheduled_now if x["type"] == eventtypes.FILE]
scheduled_now_webstream = \
filter(lambda x: x["type"] == eventtypes.STREAM_OUTPUT_START, \
scheduled_now)
[x for x in scheduled_now if x["type"] == eventtypes.STREAM_OUTPUT_START]
schedule_ids = set(map(lambda x: x["row_id"], scheduled_now_files))
schedule_ids = set([x["row_id"] for x in scheduled_now_files])
row_id_map = {}
liq_queue_ids = set()
@ -200,7 +199,7 @@ class PypoLiquidsoap():
return media_item["type"] == eventtypes.FILE
def clear_queue_tracker(self):
for i in self.liq_queue_tracker.keys():
for i in list(self.liq_queue_tracker.keys()):
self.liq_queue_tracker[i] = None
def modify_cue_point(self, link):

View file

@ -53,7 +53,7 @@ class PypoMessageHandler(Thread):
heartbeat = 5) as connection:
rabbit = RabbitConsumer(connection, [schedule_queue], self)
rabbit.run()
except Exception, e:
except Exception as e:
self.logger.error(e)
"""
@ -98,13 +98,13 @@ class PypoMessageHandler(Thread):
self.recorder_queue.put(message)
else:
self.logger.info("Unknown command: %s" % command)
except Exception, e:
except Exception as e:
self.logger.error("Exception in handling RabbitMQ message: %s", e)
def main(self):
try:
self.init_rabbit_mq()
except Exception, e:
except Exception as e:
self.logger.error('Exception: %s', e)
self.logger.error("traceback: %s", traceback.format_exc())
self.logger.error("Error connecting to RabbitMQ Server. Trying again in few seconds")

View file

@ -13,15 +13,15 @@ import math
import traceback
import os
from pypofetch import PypoFetch
from pypoliqqueue import PypoLiqQueue
from .pypofetch import PypoFetch
from .pypoliqqueue import PypoLiqQueue
from Queue import Empty, Queue
from queue import Empty, Queue
from threading import Thread
from api_clients import api_client
from timeout import ls_timeout
from .timeout import ls_timeout
logging.captureWarnings(True)
@ -67,7 +67,7 @@ class PypoPush(Thread):
while True:
try:
media_schedule = self.queue.get(block=True)
except Exception, e:
except Exception as e:
self.logger.error(str(e))
raise
else:
@ -138,7 +138,7 @@ class PypoPush(Thread):
tn.write("exit\n")
self.logger.debug(tn.read_all())
except Exception, e:
except Exception as e:
self.logger.error(str(e))
finally:
self.telnet_lock.release()
@ -146,7 +146,7 @@ class PypoPush(Thread):
def run(self):
while True:
try: self.main()
except Exception, e:
except Exception as e:
top = traceback.format_exc()
self.logger.error('Pypo Push Exception: %s', top)
time.sleep(5)

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import logging
import json
import time
@ -36,8 +36,8 @@ def api_client(logger):
# loading config file
try:
config = ConfigObj('/etc/airtime/airtime.conf')
except Exception, e:
print('Error loading config file: %s', e)
except Exception as e:
print(('Error loading config file: %s', e))
sys.exit()
# TODO : add docstrings everywhere in this module
@ -153,10 +153,10 @@ class ShowRecorder(Thread):
recorded_file['title'] = "%s-%s-%s" % (self.show_name,
full_date, full_time)
#You cannot pass ints into the metadata of a file. Even tracknumber needs to be a string
recorded_file['tracknumber'] = unicode(self.show_instance)
recorded_file['tracknumber'] = str(self.show_instance)
recorded_file.save()
except Exception, e:
except Exception as e:
top = traceback.format_exc()
self.logger.error('Exception: %s', e)
self.logger.error("traceback: %s", top)
@ -173,7 +173,7 @@ class ShowRecorder(Thread):
self.upload_file(filepath)
os.remove(filepath)
except Exception, e:
except Exception as e:
self.logger.error(e)
else:
self.logger.info("problem recording show")
@ -196,7 +196,7 @@ class Recorder(Thread):
try:
self.api_client.register_component('show-recorder')
success = True
except Exception, e:
except Exception as e:
self.logger.error(str(e))
time.sleep(10)
@ -221,12 +221,12 @@ class Recorder(Thread):
temp_shows_to_record = {}
shows = m['shows']
for show in shows:
show_starts = getDateTimeObj(show[u'starts'])
show_end = getDateTimeObj(show[u'ends'])
show_starts = getDateTimeObj(show['starts'])
show_end = getDateTimeObj(show['ends'])
time_delta = show_end - show_starts
temp_shows_to_record[show[u'starts']] = [time_delta,
show[u'instance_id'], show[u'name'], m['server_timezone']]
temp_shows_to_record[show['starts']] = [time_delta,
show['instance_id'], show['name'], m['server_timezone']]
self.shows_to_record = temp_shows_to_record
def get_time_till_next_show(self):
@ -298,7 +298,7 @@ class Recorder(Thread):
#remove show from shows to record.
del self.shows_to_record[start_time]
#self.time_till_next_show = self.get_time_till_next_show()
except Exception, e :
except Exception as e :
top = traceback.format_exc()
self.logger.error('Exception: %s', e)
self.logger.error("traceback: %s", top)
@ -318,7 +318,7 @@ class Recorder(Thread):
if temp is not None:
self.process_recorder_schedule(temp)
self.logger.info("Bootstrap recorder schedule received: %s", temp)
except Exception, e:
except Exception as e:
self.logger.error( traceback.format_exc() )
self.logger.error(e)
@ -338,16 +338,16 @@ class Recorder(Thread):
if temp is not None:
self.process_recorder_schedule(temp)
self.logger.info("updated recorder schedule received: %s", temp)
except Exception, e:
except Exception as e:
self.logger.error( traceback.format_exc() )
self.logger.error(e)
try: self.handle_message()
except Exception, e:
except Exception as e:
self.logger.error( traceback.format_exc() )
self.logger.error('Pypo Recorder Exception: %s', e)
time.sleep(PUSH_INTERVAL)
self.loops += 1
except Exception, e :
except Exception as e :
top = traceback.format_exc()
self.logger.error('Exception: %s', e)
self.logger.error("traceback: %s", top)

View file

@ -1,6 +1,6 @@
from __future__ import print_function
import telnetlib
from timeout import ls_timeout
from .timeout import ls_timeout
def create_liquidsoap_annotation(media):
# We need liq_start_next value in the annotate. That is the value that controls overlap duration of crossfade.
@ -140,7 +140,7 @@ class TelnetLiquidsoap:
tn.write("exit\n")
self.logger.debug(tn.read_all())
except Exception, e:
except Exception as e:
self.logger.error(str(e))
finally:
self.telnet_lock.release()
@ -159,7 +159,7 @@ class TelnetLiquidsoap:
tn.write("exit\n")
self.logger.debug(tn.read_all())
except Exception, e:
except Exception as e:
self.logger.error(str(e))
finally:
self.telnet_lock.release()
@ -182,7 +182,7 @@ class TelnetLiquidsoap:
self.logger.debug(tn.read_all())
self.current_prebuffering_stream_id = None
except Exception, e:
except Exception as e:
self.logger.error(str(e))
finally:
self.telnet_lock.release()
@ -205,7 +205,7 @@ class TelnetLiquidsoap:
self.logger.debug(tn.read_all())
self.current_prebuffering_stream_id = media_item['row_id']
except Exception, e:
except Exception as e:
self.logger.error(str(e))
finally:
self.telnet_lock.release()
@ -225,7 +225,7 @@ class TelnetLiquidsoap:
self.logger.debug("stream_id: %s" % stream_id)
return stream_id
except Exception, e:
except Exception as e:
self.logger.error(str(e))
finally:
self.telnet_lock.release()
@ -246,7 +246,7 @@ class TelnetLiquidsoap:
tn.write(command)
tn.write('exit\n')
tn.read_all()
except Exception, e:
except Exception as e:
self.logger.error(traceback.format_exc())
finally:
self.telnet_lock.release()
@ -263,7 +263,7 @@ class TelnetLiquidsoap:
tn.write('exit\n')
tn.read_all()
except Exception, e:
except Exception as e:
self.logger.error(str(e))
finally:
self.telnet_lock.release()

View file

@ -1,9 +1,9 @@
from __future__ import print_function
from pypoliqqueue import PypoLiqQueue
from telnetliquidsoap import DummyTelnetLiquidsoap, TelnetLiquidsoap
from .pypoliqqueue import PypoLiqQueue
from .telnetliquidsoap import DummyTelnetLiquidsoap, TelnetLiquidsoap
from Queue import Queue
from queue import Queue
from threading import Lock
import sys

View file

@ -1,5 +1,5 @@
import threading
import pypofetch
from . import pypofetch
def __timeout(func, timeout_duration, default, args, kwargs):

View file

@ -17,7 +17,7 @@ else:
for root, dirnames, filenames in os.walk('pypo'):
for filename in filenames:
pypo_files.append(os.path.join(root, filename))
data_files = [
('/etc/init', ['install/upstart/airtime-playout.conf.template']),
('/etc/init', ['install/upstart/airtime-liquidsoap.conf.template']),
@ -55,12 +55,11 @@ setup(name='airtime-playout',
'future',
'kombu',
'mutagen',
'poster',
'poster3',
'PyDispatcher',
'pyinotify',
'pytz',
'requests',
'wsgiref',
'defusedxml'
],
zip_safe=False,

View file

@ -1,6 +1,6 @@
from pypopush import PypoPush
from threading import Lock
from Queue import Queue
from queue import Queue
import datetime