diff --git a/CHANGES.md b/CHANGES.md index adc46645..3eeff6a5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -32,6 +32,7 @@ * Change py2 exception clauses to py2/3 compatible clauses * Add py2/3 regression testing for exception clauses * Change add 'hevc', 'x265' and some langs to Config Search/Episode Search/Ignore result with any word. +* Change py2 print statements to py2/3 compatible functions [develop changelog] * Update Requests library 2.7.0 (ab1f493) to 2.7.0 (8b5e457) diff --git a/SickBeard.py b/SickBeard.py index e40a48ce..6584756b 100755 --- a/SickBeard.py +++ b/SickBeard.py @@ -18,6 +18,7 @@ # along with SickGear. If not, see . # Check needed software dependencies to nudge users to fix their setup +from __future__ import print_function from __future__ import with_statement import time @@ -32,7 +33,7 @@ import threading import getopt if sys.version_info < (2, 6): - print 'Sorry, requires Python 2.6 or 2.7.' + print('Sorry, requires Python 2.6 or 2.7.') sys.exit(1) try: @@ -41,10 +42,10 @@ try: if Cheetah.Version[0] != '2': raise ValueError except ValueError: - print 'Sorry, requires Python module Cheetah 2.1.0 or newer.' + print('Sorry, requires Python module Cheetah 2.1.0 or newer.') sys.exit(1) except: - print 'The Python module Cheetah is required' + print('The Python module Cheetah is required') sys.exit(1) sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib'))) @@ -146,8 +147,8 @@ class SickGear(object): # On non-unicode builds this will raise an AttributeError, if encoding type is not valid it throws a LookupError sys.setdefaultencoding(sickbeard.SYS_ENCODING) except: - print 'Sorry, you MUST add the SickGear folder to the PYTHONPATH environment variable' - print 'or find another way to force Python to use %s for string encoding.' % sickbeard.SYS_ENCODING + print('Sorry, you MUST add the SickGear folder to the PYTHONPATH environment variable') + print('or find another way to force Python to use %s for string encoding.' % sickbeard.SYS_ENCODING) sys.exit(1) # Need console logging for SickBeard.py and SickBeard-console.exe @@ -231,7 +232,7 @@ class SickGear(object): else: if self.consoleLogging: - print u'Not running in daemon mode. PID file creation disabled' + print(u'Not running in daemon mode. PID file creation disabled') self.CREATEPID = False @@ -260,11 +261,11 @@ class SickGear(object): os.chdir(sickbeard.DATA_DIR) if self.consoleLogging: - print u'Starting up SickGear from %s' % sickbeard.CONFIG_FILE + print(u'Starting up SickGear from %s' % sickbeard.CONFIG_FILE) # Load the config and publish it to the sickbeard package if not os.path.isfile(sickbeard.CONFIG_FILE): - print u'Unable to find "%s", all settings will be default!' % sickbeard.CONFIG_FILE + print(u'Unable to find "%s", all settings will be default!' % sickbeard.CONFIG_FILE) sickbeard.CFG = ConfigObj(sickbeard.CONFIG_FILE) @@ -272,12 +273,12 @@ class SickGear(object): if CUR_DB_VERSION > 0: if CUR_DB_VERSION < MIN_DB_VERSION: - print u'Your database version (%s) is too old to migrate from with this version of SickGear' \ - % CUR_DB_VERSION + print(u'Your database version (%s) is too old to migrate from with this version of SickGear' \ + % CUR_DB_VERSION) sys.exit(u'Upgrade using a previous version of SG first, or start with no database file to begin fresh') if CUR_DB_VERSION > MAX_DB_VERSION: - print u'Your database version (%s) has been incremented past what this version of SickGear supports' \ - % CUR_DB_VERSION + print(u'Your database version (%s) has been incremented past what this version of SickGear supports' \ + % CUR_DB_VERSION) sys.exit( u'If you have used other forks of SG, your database may be unusable due to their modifications') diff --git a/autoProcessTV/autoProcessTV.py b/autoProcessTV/autoProcessTV.py index 2ac902a9..adf1e0d8 100755 --- a/autoProcessTV/autoProcessTV.py +++ b/autoProcessTV/autoProcessTV.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . +from __future__ import print_function from __future__ import with_statement import os.path @@ -132,7 +133,7 @@ def processEpisode(dir_to_process, org_NZB_name=None, status=None): sess.post(login_url, data={'username': username, 'password': password}, stream=True, verify=False) result = sess.get(url, params=params, stream=True, verify=False) if result.status_code == 401: - print 'Verify and use correct username and password in autoProcessTV.cfg' + print('Verify and use correct username and password in autoProcessTV.cfg') else: for line in result.iter_lines(): if line: diff --git a/autoProcessTV/hellaToSickBeard.py b/autoProcessTV/hellaToSickBeard.py index 07d4426d..2a677ed8 100755 --- a/autoProcessTV/hellaToSickBeard.py +++ b/autoProcessTV/hellaToSickBeard.py @@ -19,12 +19,13 @@ # along with SickGear. If not, see . +from __future__ import print_function import sys import autoProcessTV if len(sys.argv) < 4: - print 'No folder supplied - is this being called from HellaVCR?' + print('No folder supplied - is this being called from HellaVCR?') sys.exit() else: autoProcessTV.processEpisode(sys.argv[3], sys.argv[2]) diff --git a/autoProcessTV/mediaToSickbeard.py b/autoProcessTV/mediaToSickbeard.py index cf321b50..24174365 100755 --- a/autoProcessTV/mediaToSickbeard.py +++ b/autoProcessTV/mediaToSickbeard.py @@ -1,4 +1,5 @@ #!/usr/bin/env python2 +from __future__ import print_function import sys import os import time @@ -23,8 +24,10 @@ try: config.readfp(fp) fp.close() except IOError as e: - print 'Could not find/read Sickbeard config.ini: ' + str(e) - print 'Possibly wrong mediaToSickbeard.py location. Ensure the file is in the autoProcessTV subdir of your Sickbeard installation' + print('Could not find/read Sickbeard config.ini: ' + str(e)) + print( + 'Possibly wrong mediaToSickbeard.py location. Ensure the file is in the autoProcessTV subdir of your Sickbeard ' + 'installation') time.sleep(3) sys.exit(1) @@ -41,7 +44,7 @@ logfile = os.path.join(logdir, 'sickbeard.log') try: handler = logging.FileHandler(logfile) except: - print 'Unable to open/create the log file at ' + logfile + print('Unable to open/create the log file at ' + logfile) time.sleep(3) sys.exit() @@ -53,7 +56,7 @@ def utorrent(): # print 'Calling utorrent' if len(sys.argv) < 2: scriptlogger.error('No folder supplied - is this being called from uTorrent?') - print 'No folder supplied - is this being called from uTorrent?' + print('No folder supplied - is this being called from uTorrent?') time.sleep(3) sys.exit() @@ -73,7 +76,7 @@ def deluge(): if len(sys.argv) < 4: scriptlogger.error('No folder supplied - is this being called from Deluge?') - print 'No folder supplied - is this being called from Deluge?' + print('No folder supplied - is this being called from Deluge?') time.sleep(3) sys.exit() @@ -86,7 +89,7 @@ def blackhole(): if None != os.getenv('TR_TORRENT_DIR'): scriptlogger.debug('Processing script triggered by Transmission') - print 'Processing script triggered by Transmission' + print('Processing script triggered by Transmission') scriptlogger.debug(u'TR_TORRENT_DIR: ' + os.getenv('TR_TORRENT_DIR')) scriptlogger.debug(u'TR_TORRENT_NAME: ' + os.getenv('TR_TORRENT_NAME')) dirName = os.getenv('TR_TORRENT_DIR') @@ -94,7 +97,7 @@ def blackhole(): else: if len(sys.argv) < 2: scriptlogger.error('No folder supplied - Your client should invoke the script with a Dir and a Relese Name') - print 'No folder supplied - Your client should invoke the script with a Dir and a Release Name' + print('No folder supplied - Your client should invoke the script with a Dir and a Release Name') time.sleep(3) sys.exit() @@ -127,13 +130,13 @@ def main(): if not use_torrents: scriptlogger.error(u'Enable Use Torrent on Sickbeard to use this Script. Aborting!') - print u'Enable Use Torrent on Sickbeard to use this Script. Aborting!' + print(u'Enable Use Torrent on Sickbeard to use this Script. Aborting!') time.sleep(3) sys.exit() if not torrent_method in ['utorrent', 'transmission', 'deluge', 'blackhole']: scriptlogger.error(u'Unknown Torrent Method. Aborting!') - print u'Unknown Torrent Method. Aborting!' + print(u'Unknown Torrent Method. Aborting!') time.sleep(3) sys.exit() @@ -141,13 +144,13 @@ def main(): if dirName is None: scriptlogger.error(u'MediaToSickbeard script need a dir to be run. Aborting!') - print u'MediaToSickbeard script need a dir to be run. Aborting!' + print(u'MediaToSickbeard script need a dir to be run. Aborting!') time.sleep(3) sys.exit() if not os.path.isdir(dirName): scriptlogger.error(u'Folder ' + dirName + ' does not exist. Aborting AutoPostProcess.') - print u'Folder ' + dirName + ' does not exist. Aborting AutoPostProcess.' + print(u'Folder ' + dirName + ' does not exist. Aborting AutoPostProcess.') time.sleep(3) sys.exit() @@ -174,7 +177,7 @@ def main(): login_url = protocol + host + ':' + port + web_root + '/login' scriptlogger.debug('Opening URL: ' + url + ' with params=' + str(params)) - print 'Opening URL: ' + url + ' with params=' + str(params) + print('Opening URL: ' + url + ' with params=' + str(params)) try: sess = requests.Session() @@ -187,13 +190,13 @@ def main(): if response.status_code == 401: scriptlogger.error(u'Verify and use correct username and password in autoProcessTV.cfg') - print 'Verify and use correct username and password in autoProcessTV.cfg' + print('Verify and use correct username and password in autoProcessTV.cfg') time.sleep(3) sys.exit() if response.status_code == 200: scriptlogger.info(u'Script ' + __file__ + ' Succesfull') - print 'Script ' + __file__ + ' Succesfull' + print('Script ' + __file__ + ' Succesfull') time.sleep(3) sys.exit() diff --git a/autoProcessTV/sabToSickBeard.py b/autoProcessTV/sabToSickBeard.py index ab215065..6ad44031 100755 --- a/autoProcessTV/sabToSickBeard.py +++ b/autoProcessTV/sabToSickBeard.py @@ -19,11 +19,12 @@ # along with SickGear. If not, see . +from __future__ import print_function import sys import autoProcessTV if len(sys.argv) < 2: - print 'No folder supplied - is this being called from SABnzbd?' + print('No folder supplied - is this being called from SABnzbd?') sys.exit() elif len(sys.argv) >= 8: autoProcessTV.processEpisode(sys.argv[1], sys.argv[2], sys.argv[7]) diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 24eecaf0..8346df03 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . +from __future__ import print_function from __future__ import with_statement import getpass import os @@ -777,7 +778,7 @@ def get_lan_ip(): for ifname in interfaces: try: ip = get_interface_ip(ifname) - print ifname, ip + print(ifname, ip) break except IOError: pass diff --git a/sickbeard/notifiers/growl.py b/sickbeard/notifiers/growl.py index b66649a2..843ff86a 100644 --- a/sickbeard/notifiers/growl.py +++ b/sickbeard/notifiers/growl.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . +from __future__ import print_function import socket import sickbeard @@ -80,7 +81,7 @@ class GrowlNotifier: return False def _send(self, host, port, data, debug=False): - if debug: print '\n', data, '\n' + if debug: print('\n', data, '\n') s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) @@ -88,7 +89,7 @@ class GrowlNotifier: response = gntp.parse_gntp(s.recv(1024)) s.close() - if debug: print '\n', response, '\n' + if debug: print('\n', response, '\n') return response diff --git a/tests/all_tests.py b/tests/all_tests.py index adf88fde..ca78c770 100644 --- a/tests/all_tests.py +++ b/tests/all_tests.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . +from __future__ import print_function if __name__ == "__main__": import glob import unittest @@ -28,12 +29,12 @@ if __name__ == "__main__": suites = [unittest.defaultTestLoader.loadTestsFromName(file_string) for file_string in module_strings] testSuite = unittest.TestSuite(suites) - print "==================" - print "STARTING - ALL TESTS" - print "==================" - print "this will include" + print('==================') + print('STARTING - ALL TESTS') + print('==================') + print('this will include') for includedfiles in test_file_strings: - print "- " + includedfiles + print('- ' + includedfiles) text_runner = unittest.TextTestRunner().run(testSuite) if not text_runner.wasSuccessful(): diff --git a/tests/compatibility_tests.py b/tests/compatibility_tests.py index 14918905..9c80ab34 100644 --- a/tests/compatibility_tests.py +++ b/tests/compatibility_tests.py @@ -16,7 +16,7 @@ class CompatibilityTests(unittest.TestCase): pyfiles.append(os.path.join(path,'SickBeard.py')) - output = subprocess.Popen('2to3 -f except %s' % ' '.join(pyfiles), shell=True, stdout=subprocess.PIPE, + output = subprocess.Popen('2to3 -f except -f print -p %s' % ' '.join(pyfiles), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] if output: print('Changes to be made for Python 2/3 compatibility as follows:') diff --git a/tests/db_tests.py b/tests/db_tests.py index e8f85b22..05751179 100644 --- a/tests/db_tests.py +++ b/tests/db_tests.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . +from __future__ import print_function import unittest import test_lib as test @@ -32,9 +33,9 @@ class DBBasicTests(test.SickbeardTestDBCase): self.db.close() if __name__ == '__main__': - print "==================" - print "STARTING - DB TESTS" - print "==================" - print "######################################################################" + print('==================') + print('STARTING - DB TESTS') + print('==================') + print('######################################################################') suite = unittest.TestLoader().loadTestsFromTestCase(DBBasicTests) unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/tests/migration_tests.py b/tests/migration_tests.py index 48440e8d..16db45d7 100644 --- a/tests/migration_tests.py +++ b/tests/migration_tests.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys import os.path import glob @@ -107,9 +108,9 @@ class AddDefaultEpStatusToTvShows(db.SchemaUpgrade): if __name__ == '__main__': - print '==================' - print 'Starting - Migration Tests' - print '==================' - print '######################################################################' + print('==================') + print('Starting - Migration Tests') + print('==================') + print('######################################################################') suite = unittest.TestLoader().loadTestsFromTestCase(MigrationBasicTests) unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/tests/name_parser_tests.py b/tests/name_parser_tests.py index c32c4d9f..9e519ce8 100644 --- a/tests/name_parser_tests.py +++ b/tests/name_parser_tests.py @@ -1,3 +1,4 @@ +from __future__ import print_function import datetime import unittest import test_lib as test @@ -266,7 +267,7 @@ class FailureCaseTests(test.SickbeardTestDBCase): return True if VERBOSE: - print 'Actual: ', parse_result.which_regex, parse_result + print('Actual: ', parse_result.which_regex, parse_result) return False def test_failures(self): @@ -278,8 +279,8 @@ class ComboTests(test.SickbeardTestDBCase): def _test_combo(self, name, result, which_regexes): if VERBOSE: - print - print 'Testing', name + print() + print('Testing', name) np = parser.NameParser(True) @@ -289,8 +290,8 @@ class ComboTests(test.SickbeardTestDBCase): return False if DEBUG: - print test_result, test_result.which_regex - print result, which_regexes + print(test_result, test_result.which_regex) + print(result, which_regexes) self.assertEqual(test_result, result) for cur_regex in which_regexes: @@ -309,15 +310,14 @@ class BasicTests(test.SickbeardTestDBCase): def _test_names(self, np, section, transform=None, verbose=False): if VERBOSE or verbose: - print - print 'Running', section, 'tests' + print('Running', section, 'tests') for cur_test_base in simple_test_cases[section]: if transform: cur_test = transform(cur_test_base) else: cur_test = cur_test_base if VERBOSE or verbose: - print 'Testing', cur_test + print('Testing', cur_test) result = simple_test_cases[section][cur_test_base] if not result: @@ -330,10 +330,10 @@ class BasicTests(test.SickbeardTestDBCase): # self.assertEqual(test_result.which_regex, [section]) self.assertEqual(test_result, result) except: - print 'air_by_date:', test_result.is_air_by_date, 'air_date:', test_result.air_date - print 'anime:', test_result.is_anime, 'ab_episode_numbers:', test_result.ab_episode_numbers - print test_result - print result + print('air_by_date:', test_result.is_air_by_date, 'air_date:', test_result.air_date) + print('anime:', test_result.is_anime, 'ab_episode_numbers:', test_result.ab_episode_numbers) + print(test_result) + print(result) raise diff --git a/tests/pp_tests.py b/tests/pp_tests.py index 791a1cc7..f366ef04 100644 --- a/tests/pp_tests.py +++ b/tests/pp_tests.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . +from __future__ import print_function import random import unittest @@ -62,12 +63,12 @@ class PPBasicTests(test.SickbeardTestDBCase): if __name__ == '__main__': - print "==================" - print "STARTING - PostProcessor TESTS" - print "==================" - print "######################################################################" + print('==================') + print('STARTING - PostProcessor TESTS') + print('==================') + print('######################################################################') suite = unittest.TestLoader().loadTestsFromTestCase(PPInitTests) unittest.TextTestRunner(verbosity=2).run(suite) - print "######################################################################" + print('######################################################################') suite = unittest.TestLoader().loadTestsFromTestCase(PPBasicTests) unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/tests/snatch_tests.py b/tests/snatch_tests.py index 45f8f45a..aa8446b6 100644 --- a/tests/snatch_tests.py +++ b/tests/snatch_tests.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . +from __future__ import print_function import random import unittest @@ -88,10 +89,10 @@ def test_generator(tvdbdid, show_name, curData, forceSearch): return test if __name__ == '__main__': - print "==================" - print "STARTING - Snatch TESTS" - print "==================" - print "######################################################################" + print('==================') + print('STARTING - Snatch TESTS') + print('==================') + print('######################################################################') # create the test methods tvdbdid = 1 for forceSearch in (True, False): diff --git a/tests/test_lib.py b/tests/test_lib.py index 8aca7bb7..ed1b8b83 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . +from __future__ import print_function from __future__ import with_statement import unittest @@ -208,7 +209,7 @@ def setUp_test_episode_file(): with open(FILEPATH, 'w') as f: f.write("foo bar") except EnvironmentError: - print "Unable to set up test episode" + print('Unable to set up test episode') raise @@ -229,15 +230,15 @@ def tearDown_test_show_dir(): tearDown_test_db() if __name__ == '__main__': - print "==================" - print "Dont call this directly" - print "==================" - print "you might want to call" + print('==================') + print('Dont call this directly') + print('==================') + print('you might want to call') dirList = os.listdir(TESTDIR) for fname in dirList: if (fname.find("_test") > 0) and (fname.find("pyc") < 0): - print "- " + fname + print('- ' + fname) - print "==================" - print "or just call all_tests.py" + print('==================') + print('or just call all_tests.py') diff --git a/tests/torrent_tests.py b/tests/torrent_tests.py index 6cbd92ed..32e3f72b 100644 --- a/tests/torrent_tests.py +++ b/tests/torrent_tests.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . +from __future__ import print_function from __future__ import with_statement import unittest @@ -68,11 +69,11 @@ class TorrentBasicTests(test.SickbeardTestDBCase): except (AttributeError, TypeError): continue - print title + print(title) if __name__ == "__main__": - print "==================" - print "STARTING - XEM Scene Numbering TESTS" - print "==================" - print "######################################################################" + print('==================') + print('STARTING - XEM Scene Numbering TESTS') + print('==================') + print('######################################################################') suite = unittest.TestLoader().loadTestsFromTestCase(TorrentBasicTests) \ No newline at end of file diff --git a/tests/tv_tests.py b/tests/tv_tests.py index 4bf1dde9..458764ae 100644 --- a/tests/tv_tests.py +++ b/tests/tv_tests.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . +from __future__ import print_function import unittest import test_lib as test @@ -98,15 +99,15 @@ class TVTests(test.SickbeardTestDBCase): if __name__ == '__main__': - print "==================" - print "STARTING - TV TESTS" - print "==================" - print "######################################################################" + print('==================') + print('STARTING - TV TESTS') + print('==================') + print('######################################################################') suite = unittest.TestLoader().loadTestsFromTestCase(TVShowTests) unittest.TextTestRunner(verbosity=2).run(suite) - print "######################################################################" + print('######################################################################') suite = unittest.TestLoader().loadTestsFromTestCase(TVEpisodeTests) unittest.TextTestRunner(verbosity=2).run(suite) - print "######################################################################" + print('######################################################################') suite = unittest.TestLoader().loadTestsFromTestCase(TVTests) unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/tests/xem_tests.py b/tests/xem_tests.py index c6fbccbf..9e7d61eb 100644 --- a/tests/xem_tests.py +++ b/tests/xem_tests.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with SickGear. If not, see . +from __future__ import print_function from __future__ import with_statement import unittest @@ -62,7 +63,7 @@ class XEMBasicTests(test.SickbeardTestDBCase): curShow = TVShow(int(sqlShow["indexer"]), int(sqlShow["indexer_id"])) sickbeard.showList.append(curShow) except Exception as e: - print "There was an error creating the show" + print('There was an error creating the show') def test_formating(self): name = "Game.of.Thrones.S03.720p.HDTV.x264-CtrlHD" @@ -80,8 +81,8 @@ class XEMBasicTests(test.SickbeardTestDBCase): if __name__ == "__main__": - print "==================" - print "STARTING - XEM Scene Numbering TESTS" - print "==================" - print "######################################################################" + print('==================') + print('STARTING - XEM Scene Numbering TESTS') + print('==================') + print('######################################################################') suite = unittest.TestLoader().loadTestsFromTestCase(XEMBasicTests) \ No newline at end of file