Commit 7f5696f9 authored by echel0n's avatar echel0n

Migration from Python 2 to Python 3.7.x

parent 01dfecd8
......@@ -4,6 +4,10 @@
/sickrage/libs/adba/anime-list.xml
/sickrage/libs/adba/animetitles.xml
# SR Tox Files #
######################
/.tox/
# SR GitLab Files #
######################
/.gitlab/
......@@ -54,7 +58,7 @@ sickrage.egg-info
/.settings/*
/build/
pre-commit-hook.sh
/venv/
/venv-*/
# OS Generated Files #
######################
......
FROM python:2.7.15-alpine3.8
FROM python:3.7.2-alpine3.8
MAINTAINER echel0n <[email protected]>
ENV TZ 'Canada/Pacific'
......
#!/usr/bin/env python2.7
#!/usr/bin/env python3
# Author: echel0n <[email protected]>
# URL: https://sickrage.ca
#
......@@ -22,9 +22,9 @@ import os
if __name__ == '__main__':
# removes stale .pyc files
for root, dirs, files in os.walk(os.path.dirname(__file__)):
pyc_files = filter(lambda filename: filename.endswith(".pyc"), files)
pyc_files = list(filter(lambda filename: filename.endswith(".pyc"), files))
py_files = set(filter(lambda filename: filename.endswith(".py"), files))
excess_pyc_files = filter(lambda pyc_filename: pyc_filename[:-1] not in py_files, pyc_files)
excess_pyc_files = list(filter(lambda pyc_filename: pyc_filename[:-1] not in py_files, pyc_files))
for excess_pyc_file in excess_pyc_files:
full_path = os.path.join(root, excess_pyc_file)
os.remove(full_path)
......
# Changelog
- * 8f00c06 - 2019-02-24: Release v9.4.77
- * 3bad5d0 - 2019-02-25: Migration from Python 2 to Python 3.7.x
- * a72ca25 - 2019-02-24: Release v9.4.77
- * b09d78a - 2019-02-24: Added Anime regex for Erai-raws
- * e0f2db6 - 2019-02-24: Release v9.4.76
- * ed84483 - 2019-02-24: Fixed IndexerErrors for TV cache. Added files to .gitignore related to AniDB.
......
twine
crowdin-cli-py
babel
wheel
\ No newline at end of file
wheel
tox
\ No newline at end of file
APScheduler == 3.5.3
babelfish == 0.5.5
bencode == 1.0
bencode3 == 0.1.0
CacheControl == 0.12.5
cfscrape == 1.9.5
configobj == 5.0.6
feedparser == 5.2.1
guessit == 3.0.3
hachoir_core == 1.3.3
hachoir_metadata == 1.3.3
hachoir_parser == 1.3.4
jsonrpclib == 0.1.7
hachoir3 == 3.0a2
Mako == 1.0.7
markdown2 == 2.3.6
oauth2 == 1.9.0.post1
......@@ -23,15 +20,14 @@ MultipartPostHandler == 0.1.0
beautifulsoup4 == 4.6.3
python_dateutil == 2.7.5
pynzb == 0.1.0
futures == 3.2.0
future == 0.17.1
gntp == 1.0.3
python_twitter == 3.5
pyxdg == 0.26
urllib3 == 1.24.1
py-unrar2 == 0.99.6
unrar == 0.3
lockfile == 0.12.2
requests == 2.20.1
codernitydb == 0.5.0
fake-useragent == 0.1.11
html5lib == 1.0.1
arrow == 0.12.1
......@@ -44,9 +40,11 @@ raven == 6.9.0
python-keycloak-client == 0.2.1
simplejson == 3.16.0
service_identity == 17.0.0
knowit == 0.2.4
certifi
pyasn1
lxml
ipaddress
psutil
cffi
sqlalchemy
\ No newline at end of file
import glob
import io
import os
import shutil
from setuptools import setup, Command
# Get the version number
with io.open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'sickrage', 'version.txt'))) as f:
with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'sickrage', 'version.txt'))) as f:
version = f.read()
def requires():
with io.open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'requirements.txt'))) as f:
with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'requirements.txt'))) as f:
return f.read().splitlines()
......
......@@ -16,12 +16,11 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function, unicode_literals, with_statement
import argparse
import atexit
import gettext
import io
import os
import site
import sys
......@@ -65,7 +64,7 @@ class Daemon(object):
if pid > 0:
# exit first parent
os._exit(0)
except OSError, e:
except OSError as e:
sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
sys.exit(1)
......@@ -78,7 +77,7 @@ class Daemon(object):
if pid > 0:
# exit from second parent
os._exit(0)
except OSError, e:
except OSError as e:
sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
sys.exit(1)
......@@ -88,9 +87,9 @@ class Daemon(object):
sys.stderr = sys.__stderr__
sys.stdout.flush()
sys.stderr.flush()
si = file(self.stdin, 'r')
so = file(self.stdout, 'a+')
se = file(self.stderr, 'a+', 0)
si = open(self.stdin, 'r')
so = open(self.stdout, 'a+')
se = open(self.stderr, 'a+', 0)
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
......@@ -98,7 +97,7 @@ class Daemon(object):
# write pidfile
atexit.register(self.delpid)
self.pid = os.getpid()
file(self.pidfile, 'w+').write("%s\n" % self.pid)
open(self.pidfile, 'w+').write("%s\n" % self.pid)
def delpid(self):
if os.path.exists(self.pidfile):
......@@ -110,7 +109,7 @@ class Daemon(object):
"""
# Check for a pidfile to see if the daemon already runs
try:
pf = file(self.pidfile, 'r')
pf = open(self.pidfile, 'r')
pid = int(pf.read().strip())
pf.close()
except IOError:
......@@ -131,7 +130,7 @@ class Daemon(object):
# Get the pid from the pidfile
try:
pf = file(self.pidfile, 'r')
pf = open(self.pidfile, 'r')
pid = int(pf.read().strip())
pf.close()
except IOError:
......@@ -147,7 +146,7 @@ class Daemon(object):
while 1:
os.kill(pid, SIGTERM)
time.sleep(0.1)
except OSError, err:
except OSError as err:
err = str(err)
if err.find("No such process") > 0:
self.delpid()
......@@ -181,20 +180,20 @@ def check_requirements():
if not v >= v_needed:
print('OpenSSL installed but {} is needed while {} is installed. '
'Run `pip install -U pyopenssl`'.format(v_needed, v))
except:
except ImportError:
print('OpenSSL not available, please install for better requests validation: '
'`https://pyopenssl.readthedocs.org/en/latest/install.html`')
def version():
# Get the version number
with io.open(VERSION_FILE) as f:
with open(VERSION_FILE) as f:
return f.read()
def changelog():
# Get the version number
with io.open(CHANGELOG_FILE) as f:
with open(CHANGELOG_FILE) as f:
return f.read()
......@@ -214,7 +213,7 @@ def main():
sys.path.extend(remainder)
# set system default language
gettext.install('messages', LOCALE_DIR, unicode=1, codeset='UTF-8', names=["ngettext"])
gettext.install('messages', LOCALE_DIR, codeset='UTF-8', names=["ngettext"])
try:
from sickrage.core import Core
......@@ -317,12 +316,9 @@ def main():
# start app
app.start()
except (SystemExit, KeyboardInterrupt):
if app: app.shutdown()
except ImportError:
traceback.print_exc()
if os.path.isfile(REQS_FILE):
print('Failed to import required libs, please run "pip install -r {}" from console'.format(REQS_FILE))
except Exception:
if app:
app.shutdown()
except Exception as e:
traceback.print_exc()
......
......@@ -16,4 +16,4 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
#!/usr/bin/env python2.7
#!/usr/bin/env python3
# Author: echel0n <[email protected]>
# URL: https://sickrage.ca
#
......@@ -17,12 +17,10 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import io
import os.path
import sys
from ConfigParser import RawConfigParser, NoOptionError
from configparser import RawConfigParser, NoOptionError
import requests
......@@ -53,7 +51,7 @@ def processEpisode(dir_to_process, org_nzb_name=None, status=None):
try:
print ("Loading config from " + config_filename + "\n")
with io.open(config_filename, "r") as fp:
with open(config_filename, "r") as fp:
config.readfp(fp)
# Replace default values with config_file values
......
#!/usr/bin/env python2.7
#!/usr/bin/env python3
# Author: echel0n <[email protected]>
# URL: https://sickrage.ca
#
......@@ -17,14 +17,14 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import sys
import autoProcessTV
from sickrage.autoProcessTV 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])
#!/usr/bin/env python2.7
#!/usr/bin/env python3
# Author: echel0n <[email protected]>
# URL: https://sickrage.ca
#
......@@ -17,14 +17,12 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function, unicode_literals
import ConfigParser
import io
import logging
import os
import sys
import time
from configparser import ConfigParser
import requests
......@@ -32,10 +30,10 @@ sickragePath = os.path.split(os.path.split(sys.argv[0])[0])[0]
sys.path.append(sickragePath)
configFilename = os.path.join(sickragePath, "config.ini")
config = ConfigParser.ConfigParser()
config = ConfigParser()
try:
with io.open(configFilename, "r") as fp:
with open(configFilename, "r") as fp:
config.readfp(fp)
except IOError as e:
print("Could not find/read SiCKRAGE config.ini: " + str(e))
......@@ -83,7 +81,7 @@ def transmission():
dirName = os.getenv('TR_TORRENT_DIR')
nzbName = os.getenv('TR_TORRENT_NAME')
return (dirName, nzbName)
return dirName, nzbName
def deluge():
......@@ -96,7 +94,7 @@ def deluge():
dirName = sys.argv[3]
nzbName = sys.argv[2]
return (dirName, nzbName)
return dirName, nzbName
def blackhole():
......@@ -117,7 +115,7 @@ def blackhole():
dirName = sys.argv[1]
nzbName = sys.argv[2]
return (dirName, nzbName)
return dirName, nzbName
def main():
......
#!/usr/bin/env python2.7
#!/usr/bin/env python3
# Author: echel0n <[email protected]>
# URL: https://sickrage.ca
#
......@@ -17,14 +17,13 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import sys
import autoProcessTV
from sickrage.autoProcessTV 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])
......
......@@ -16,14 +16,14 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import re
import time
from base64 import b16encode, b32decode
from hashlib import sha1
from bencode import BTFailure, bdecode, bencode
from bencode3 import bdecode, bencode, BencodeError
import sickrage
from sickrage.core.websession import WebSession
......@@ -293,7 +293,7 @@ class GenericClient(object):
try:
torrent_bdecode = bdecode(result.content)
except BTFailure:
except BencodeError:
sickrage.app.log.error('Unable to bdecode torrent')
sickrage.app.log.debug('Torrent bencoded data: %r' % result.content)
raise
......@@ -314,11 +314,11 @@ class GenericClient(object):
sickrage.app.log.debug('Calling ' + self.name + ' Client')
if not self._get_auth():
sickrage.app.log.warning(self.name + ': Authentication Failed')
return r_code
try:
if not self._get_auth():
sickrage.app.log.warning(self.name + ': Authentication Failed')
return r_code
# Sets per provider seed ratio
result.ratio = result.provider.seed_ratio
......@@ -359,7 +359,7 @@ class GenericClient(object):
except Exception as e:
sickrage.app.log.warning(self.name + ': Failed Sending Torrent')
sickrage.app.log.debug(
self.name + ': Exception raised when sending torrent: ' + str(result) + '. Error: ' + str(e))
self.name + ': Exception raised when sending torrent: {}. Error: {}'.format(result, e))
return r_code
return r_code
......
......@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import json
from base64 import b64encode
......
......@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from base64 import b64encode
......@@ -170,7 +170,6 @@ class DelugeRPC(object):
return torrent_id
def add_torrent_file(self, filename, torrent, options, torrent_hash):
torrent_id = False
try:
self.connect()
torrent_id = self.client.core.add_torrent_file(filename, b64encode(torrent), options).get()
......@@ -212,7 +211,7 @@ class DelugeRPC(object):
self.connect()
if priority:
self.client.core.queue_top([torrent_ids]).get()
except Exception, err:
except Exception as err:
return False
finally:
if self.client:
......@@ -224,7 +223,7 @@ class DelugeRPC(object):
self.connect()
self.client.core.set_torrent_stop_at_ratio(torrent_ids, True).get()
self.client.core.set_torrent_stop_ratio(torrent_ids, ratio).get()
except Exception, err:
except Exception as err:
return False
finally:
if self.client:
......
......@@ -16,11 +16,11 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import os
import re
from urlparse import urljoin
from urllib.parse import urljoin
from requests import RequestException
......
......@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import sickrage
from sickrage.clients import GenericClient
......
......@@ -17,12 +17,11 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import httplib
import xmlrpclib
from base64 import standard_b64encode
from datetime import date, timedelta
from http import client
from xmlrpc.client import ServerProxy, ProtocolError
import sickrage
from sickrage.core.common import Quality
......@@ -60,18 +59,18 @@ class NZBGet(object):
"password": sickrage.app.config.nzbget_password
}
nzbGetRPC = xmlrpclib.ServerProxy(url)
nzbGetRPC = ServerProxy(url)
try:
if nzbGetRPC.writelog("INFO", "SiCKRAGE connected to drop of %s any moment now." % (nzb.name + ".nzb")):
sickrage.app.log.debug("Successful connected to NZBget")
else:
sickrage.app.log.warning("Successful connected to NZBget, but unable to send a message")
except httplib.socket.error:
except client.socket.error:
sickrage.app.log.warning("Please check your NZBget host and port (if it is running). NZBget is not "
"responding to this combination")
return False
except xmlrpclib.ProtocolError as e:
except ProtocolError as e:
if e.errmsg == "Unauthorized":
sickrage.app.log.warning("NZBget username or password is incorrect.")
else:
......@@ -108,7 +107,8 @@ class NZBGet(object):
sickrage.app.log.debug("URL: " + url)
try:
# Find out if nzbget supports priority (Version 9.0+), old versions beginning with a 0.x will use the old command
# Find out if nzbget supports priority (Version 9.0+), old versions beginning with a 0.x will use the old
# command
nzbget_version_str = nzbGetRPC.version()
nzbget_version = try_int(nzbget_version_str[:nzbget_version_str.find(".")])
if nzbget_version == 0:
......
......@@ -16,10 +16,10 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import re
from urllib import urlencode
from urllib.parse import urlencode
import sickrage
from sickrage.clients import GenericClient
......
......@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import sickrage
from sickrage.clients import GenericClient
......
......@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import traceback
......
......@@ -17,10 +17,10 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import datetime
from urlparse import urljoin
from urllib.parse import urljoin
import sickrage
from sickrage.core.websession import WebSession
......@@ -104,9 +104,6 @@ class SabNZBd(object):
"""
Find out how we should connect to SAB
:param host: hostname where SAB lives
:param username: username to use
:param password: password to use
:param apikey: apikey to use
:return: (boolean, string) with True if method was successful
"""
params = {'mode': 'auth', 'output': 'json'}
......
......@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals