From 632ba9acfe69da684c747473aae5cca52a48625b Mon Sep 17 00:00:00 2001 From: Kyle Robbertze Date: Thu, 16 Jan 2020 15:33:44 +0200 Subject: [PATCH] convert print statements to py3 --- .../airtime_analyzer/config_file.py | 7 ++++--- .../airtime_analyzer/bin/airtime_analyzer | 7 ++++--- python_apps/airtime_analyzer/setup.py | 15 ++++++++------- .../tests/metadata_analyzer_tests.py | 5 +++-- .../tests/replaygain_analyzer_tests.py | 3 ++- python_apps/api_clients/setup.py | 5 +++-- python_apps/icecast2/install/icecast2-install.py | 5 +++-- python_apps/pypo/bin/pyponotify | 16 ++++++++-------- python_apps/pypo/liquidsoap/__main__.py | 3 ++- .../pypo/liquidsoap/generate_liquidsoap_cfg.py | 3 ++- python_apps/pypo/liquidsoap/liquidsoap_auth.py | 5 +++-- python_apps/pypo/pypo/recorder.py | 3 ++- python_apps/pypo/pypo/telnetliquidsoap.py | 5 +++-- python_apps/pypo/pypo/testpypoliqqueue.py | 3 ++- python_apps/pypo/setup.py | 9 +++++---- 15 files changed, 54 insertions(+), 40 deletions(-) diff --git a/python_apps/airtime_analyzer/airtime_analyzer/config_file.py b/python_apps/airtime_analyzer/airtime_analyzer/config_file.py index 7bd5a0b59..506af020a 100644 --- a/python_apps/airtime_analyzer/airtime_analyzer/config_file.py +++ b/python_apps/airtime_analyzer/airtime_analyzer/config_file.py @@ -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 \ No newline at end of file + return config diff --git a/python_apps/airtime_analyzer/bin/airtime_analyzer b/python_apps/airtime_analyzer/bin/airtime_analyzer index b3e4ab0aa..e81fb5085 100755 --- a/python_apps/airtime_analyzer/bin/airtime_analyzer +++ b/python_apps/airtime_analyzer/bin/airtime_analyzer @@ -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 diff --git a/python_apps/airtime_analyzer/setup.py b/python_apps/airtime_analyzer/setup.py index eb697d941..d819a171a 100644 --- a/python_apps/airtime_analyzer/setup.py +++ b/python_apps/airtime_analyzer/setup.py @@ -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.") diff --git a/python_apps/airtime_analyzer/tests/metadata_analyzer_tests.py b/python_apps/airtime_analyzer/tests/metadata_analyzer_tests.py index 2af30326b..3c60244bc 100644 --- a/python_apps/airtime_analyzer/tests/metadata_analyzer_tests.py +++ b/python_apps/airtime_analyzer/tests/metadata_analyzer_tests.py @@ -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 diff --git a/python_apps/airtime_analyzer/tests/replaygain_analyzer_tests.py b/python_apps/airtime_analyzer/tests/replaygain_analyzer_tests.py index 4a4e8ca58..0739e3126 100644 --- a/python_apps/airtime_analyzer/tests/replaygain_analyzer_tests.py +++ b/python_apps/airtime_analyzer/tests/replaygain_analyzer_tests.py @@ -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(): diff --git a/python_apps/api_clients/setup.py b/python_apps/api_clients/setup.py index b71f509a2..a615e6c0f 100644 --- a/python_apps/api_clients/setup.py +++ b/python_apps/api_clients/setup.py @@ -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=[]) \ No newline at end of file + data_files=[]) diff --git a/python_apps/icecast2/install/icecast2-install.py b/python_apps/icecast2/install/icecast2-install.py index 0b411d8da..f1424f9bc 100644 --- a/python_apps/icecast2/install/icecast2-install.py +++ b/python_apps/icecast2/install/icecast2-install.py @@ -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) diff --git a/python_apps/pypo/bin/pyponotify b/python_apps/pypo/bin/pyponotify index 9d8fe4ab8..b3ca44b4d 100755 --- a/python_apps/pypo/bin/pyponotify +++ b/python_apps/pypo/bin/pyponotify @@ -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()) diff --git a/python_apps/pypo/liquidsoap/__main__.py b/python_apps/pypo/liquidsoap/__main__.py index 09e4abe5f..f696ef999 100644 --- a/python_apps/pypo/liquidsoap/__main__.py +++ b/python_apps/pypo/liquidsoap/__main__.py @@ -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() diff --git a/python_apps/pypo/liquidsoap/generate_liquidsoap_cfg.py b/python_apps/pypo/liquidsoap/generate_liquidsoap_cfg.py index 4f104c62c..4043b83be 100644 --- a/python_apps/pypo/liquidsoap/generate_liquidsoap_cfg.py +++ b/python_apps/pypo/liquidsoap/generate_liquidsoap_cfg.py @@ -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: diff --git a/python_apps/pypo/liquidsoap/liquidsoap_auth.py b/python_apps/pypo/liquidsoap/liquidsoap_auth.py index fe4725305..fb07905bd 100644 --- a/python_apps/pypo/liquidsoap/liquidsoap_auth.py +++ b/python_apps/pypo/liquidsoap/liquidsoap_auth.py @@ -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) diff --git a/python_apps/pypo/pypo/recorder.py b/python_apps/pypo/pypo/recorder.py index bc74f3c10..b98f5d4ef 100644 --- a/python_apps/pypo/pypo/recorder.py +++ b/python_apps/pypo/pypo/recorder.py @@ -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 diff --git a/python_apps/pypo/pypo/telnetliquidsoap.py b/python_apps/pypo/pypo/telnetliquidsoap.py index c294a3b0f..d3a7d39d1 100644 --- a/python_apps/pypo/pypo/telnetliquidsoap.py +++ b/python_apps/pypo/pypo/telnetliquidsoap.py @@ -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 diff --git a/python_apps/pypo/pypo/testpypoliqqueue.py b/python_apps/pypo/pypo/testpypoliqqueue.py index f1847b34f..d3fe2ead2 100644 --- a/python_apps/pypo/pypo/testpypoliqqueue.py +++ b/python_apps/pypo/pypo/testpypoliqqueue.py @@ -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 = {} diff --git a/python_apps/pypo/setup.py b/python_apps/pypo/setup.py index 618339435..325b0a916 100644 --- a/python_apps/pypo/setup.py +++ b/python_apps/pypo/setup.py @@ -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\"")