convert print statements to py3

This commit is contained in:
Kyle Robbertze 2020-01-16 15:33:44 +02:00
parent 2aa4392a38
commit 632ba9acfe
15 changed files with 54 additions and 40 deletions

View file

@ -1,3 +1,4 @@
from __future__ import print_function
import ConfigParser
def read_config_file(config_path):
@ -6,10 +7,10 @@ def read_config_file(config_path):
try:
config.readfp(open(config_path))
except IOError as e:
print "Failed to open config file at " + config_path + ": " + e.strerror
print("Failed to open config file at {}: {}".format(config_path, e.strerror))
exit(-1)
except Exception as e:
print e.strerror
print(e.strerror)
exit(-1)
return config
return config

View file

@ -2,6 +2,7 @@
"""Runs the airtime_analyzer application.
"""
from __future__ import print_function
import daemon
import argparse
import os
@ -14,7 +15,7 @@ DEFAULT_HTTP_RETRY_PATH = '/tmp/airtime_analyzer_http_retries'
def run():
'''Entry-point for this application'''
print "Airtime Analyzer " + VERSION
print("Airtime Analyzer {}".format(VERSION))
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--daemon", help="run as a daemon", action="store_true")
parser.add_argument("--debug", help="log full debugging output", action="store_true")
@ -57,8 +58,8 @@ def check_if_media_monitor_is_running():
try:
process_name = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read()
if 'media_monitor.py' in process_name:
print "Error: This process conflicts with media_monitor, and media_monitor is running."
print " Please terminate the running media_monitor.py process and try again."
print("Error: This process conflicts with media_monitor, and media_monitor is running.")
print(" Please terminate the running media_monitor.py process and try again.")
exit(1)
except IOError: # proc has already terminated
continue

View file

@ -1,3 +1,4 @@
from __future__ import print_function
from setuptools import setup
from subprocess import call
import sys
@ -5,7 +6,7 @@ import os
# Change directory since setuptools uses relative paths
script_path = os.path.dirname(os.path.realpath(__file__))
print script_path
print(script_path)
os.chdir(script_path)
# Allows us to avoid installing the upstart init script when deploying airtime_analyzer
@ -16,7 +17,7 @@ if '--no-init-script' in sys.argv:
else:
data_files = [('/etc/init', ['install/upstart/airtime_analyzer.conf']),
('/etc/init.d', ['install/sysvinit/airtime_analyzer'])]
print data_files
print(data_files)
setup(name='airtime_analyzer',
version='0.1',
@ -49,8 +50,8 @@ setup(name='airtime_analyzer',
# Remind users to reload the initctl config so that "service start airtime_analyzer" works
if data_files:
print "Remember to reload the initctl configuration"
print "Run \"sudo initctl reload-configuration; sudo service airtime_analyzer restart\" now."
print "Or on Ubuntu Xenial (16.04)"
print "Remember to reload the systemd configuration"
print "Run \"sudo systemctl daemon-reload; sudo service airtime_analyzer restart\" now."
print("Remember to reload the initctl configuration")
print("Run \"sudo initctl reload-configuration; sudo service airtime_analyzer restart\" now.")
print("Or on Ubuntu Xenial (16.04)")
print("Remember to reload the systemd configuration")
print("Run \"sudo systemctl daemon-reload; sudo service airtime_analyzer restart\" now.")

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import datetime
import mutagen
import mock
@ -79,8 +80,8 @@ def test_ogg_stereo():
''' faac and avconv can't seem to create a proper mono AAC file... ugh
def test_aac_mono():
metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-mono.m4a')
print "Mono AAC metadata:"
print metadata
print("Mono AAC metadata:")
print(metadata)
check_default_metadata(metadata)
assert metadata['channels'] == 1
assert metadata['bit_rate'] == 80000

View file

@ -1,3 +1,4 @@
from __future__ import print_function
from nose.tools import *
from airtime_analyzer.replaygain_analyzer import ReplayGainAnalyzer
@ -28,7 +29,7 @@ def check_default_metadata(metadata):
'''
tolerance = 0.30
expected_replaygain = 5.0
print metadata['replay_gain']
print(metadata['replay_gain'])
assert abs(metadata['replay_gain'] - expected_replaygain) < tolerance
def test_missing_replaygain():

View file

@ -1,10 +1,11 @@
from __future__ import print_function
from setuptools import setup
from subprocess import call
import sys
import os
script_path = os.path.dirname(os.path.realpath(__file__))
print script_path
print(script_path)
os.chdir(script_path)
setup(name='api_clients',
@ -30,4 +31,4 @@ setup(name='api_clients',
# 'wsgiref'
],
zip_safe=False,
data_files=[])
data_files=[])

View file

@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import shutil
import os
import sys
if os.geteuid() != 0:
print "Please run this as root."
print("Please run this as root.")
sys.exit(1)
def get_current_script_dir():
@ -18,5 +19,5 @@ try:
shutil.copy(current_script_dir+"/../airtime-icecast-status.xsl", "/usr/share/icecast2/web")
except Exception, e:
print "exception: %s" % e
print("exception: {}".format(e))
sys.exit(1)

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import traceback
"""
@ -133,21 +134,20 @@ class Notify:
elif options.liquidsoap_started:
self.notify_liquidsoap_started()
else:
logger.debug("Unrecognized option in options(%s). Doing nothing" \
% str(options))
logger.debug("Unrecognized option in options({}). Doing nothing".format(options))
if __name__ == '__main__':
print
print '#########################################'
print '# *** pypo *** #'
print '# pypo notification gateway #'
print '#########################################'
print()
print('#########################################')
print('# *** pypo *** #')
print('# pypo notification gateway #')
print('#########################################')
# initialize
try:
n = Notify()
n.run_with_options(options)
except Exception as e:
print( traceback.format_exc() )
print(traceback.format_exc())

View file

@ -1,6 +1,7 @@
""" Runs Airtime liquidsoap
"""
from __future__ import print_function
import argparse
import os
import generate_liquidsoap_cfg
@ -11,7 +12,7 @@ PYPO_HOME = '/var/tmp/airtime/pypo/'
def run():
'''Entry-point for this application'''
print "Airtime Liquidsoap"
print("Airtime Liquidsoap")
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--debug", help="run in debug mode", action="store_true")
args = parser.parse_args()

View file

@ -1,3 +1,4 @@
from __future__ import print_function
import logging
import os
import sys
@ -49,7 +50,7 @@ def run():
generate_liquidsoap_config(ss)
successful = True
except Exception, e:
print "Unable to connect to the Airtime server."
print("Unable to connect to the Airtime server.")
logging.error(str(e))
logging.error("traceback: %s", traceback.format_exc())
if attempts == max_attempts:

View file

@ -1,3 +1,4 @@
from __future__ import print_function
from api_clients import *
import sys
@ -16,8 +17,8 @@ elif dj_type == '--dj':
response = api_clients.check_live_stream_auth(username, password, source_type)
if 'msg' in response and response['msg'] == True:
print response['msg']
print(response['msg'])
sys.exit(0)
else:
print False
print(False)
sys.exit(1)

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import logging
import json
import time
@ -36,7 +37,7 @@ def api_client(logger):
try:
config = ConfigObj('/etc/airtime/airtime.conf')
except Exception, e:
print ('Error loading config file: %s', e)
print('Error loading config file: %s', e)
sys.exit()
# TODO : add docstrings everywhere in this module

View file

@ -1,3 +1,4 @@
from __future__ import print_function
import telnetlib
from timeout import ls_timeout
@ -302,7 +303,7 @@ class DummyTelnetLiquidsoap:
self.logger.info("Pushing %s to queue %s" % (media_item, queue_id))
from datetime import datetime
print "Time now: %s" % datetime.utcnow()
print("Time now: {:s}".format(datetime.utcnow()))
annotation = create_liquidsoap_annotation(media_item)
self.liquidsoap_mock_queues[queue_id].append(annotation)
@ -318,7 +319,7 @@ class DummyTelnetLiquidsoap:
self.logger.info("Purging queue %s" % queue_id)
from datetime import datetime
print "Time now: %s" % datetime.utcnow()
print("Time now: {:s}".format(datetime.utcnow()))
except Exception:
raise

View file

@ -1,3 +1,4 @@
from __future__ import print_function
from pypoliqqueue import PypoLiqQueue
from telnetliquidsoap import DummyTelnetLiquidsoap, TelnetLiquidsoap
@ -45,7 +46,7 @@ plq.daemon = True
plq.start()
print "Time now: %s" % datetime.utcnow()
print("Time now: {:s}".format(datetime.utcnow()))
media_schedule = {}

View file

@ -1,10 +1,11 @@
from __future__ import print_function
from setuptools import setup
from subprocess import call
import sys
import os
script_path = os.path.dirname(os.path.realpath(__file__))
print script_path
print(script_path)
os.chdir(script_path)
# Allows us to avoid installing the upstart init script when deploying on Airtime Pro:
@ -29,7 +30,7 @@ else:
('/var/tmp/airtime/pypo/files', []),
('/var/tmp/airtime/pypo/tmp', []),
]
print data_files
print(data_files)
setup(name='airtime-playout',
version='1.0',
@ -67,6 +68,6 @@ setup(name='airtime-playout',
# Reload the initctl config so that playout services works
if data_files:
print "Reloading initctl configuration"
print("Reloading initctl configuration")
#call(['initctl', 'reload-configuration'])
print "Run \"sudo service airtime-playout start\" and \"sudo service airtime-liquidsoap start\""
print("Run \"sudo service airtime-playout start\" and \"sudo service airtime-liquidsoap start\"")