Browse Source

Remove unused imports and functions (pyflakes)

pull/945/head
Safihre 8 years ago
parent
commit
2def600d21
  1. 4
      SABnzbd.py
  2. 5
      sabnzbd/__init__.py
  3. 17
      sabnzbd/api.py
  4. 2
      sabnzbd/assembler.py
  5. 2
      sabnzbd/decoder.py
  6. 15
      sabnzbd/encoding.py
  7. 7
      sabnzbd/interface.py
  8. 11
      sabnzbd/misc.py
  9. 3
      sabnzbd/newsunpack.py
  10. 1
      sabnzbd/newswrapper.py
  11. 10
      sabnzbd/nzbqueue.py
  12. 38
      sabnzbd/nzbstuff.py
  13. 34
      sabnzbd/panic.py
  14. 4
      sabnzbd/postproc.py
  15. 1
      sabnzbd/rss.py
  16. 50
      sabnzbd/trylist.py

4
SABnzbd.py

@ -56,8 +56,6 @@ if [int(n) for n in cherrypy.__version__.split('.')] < [8, 1, 2]:
print 'Sorry, requires Python module Cherrypy 8.1.2+ (use the included version)'
sys.exit(1)
from cherrypy import _cpserver
SQLITE_DLL = True
try:
from sqlite3 import version as sqlite3_version
@ -90,7 +88,7 @@ from sabnzbd.misc import real_path, \
check_latest_version, exit_sab, \
split_host, get_ext, create_https_certificates, \
windows_variant, ip_extract, set_serv_parms, get_serv_parms, globber_full
from sabnzbd.panic import panic_tmpl, panic_port, panic_host, panic_fwall, \
from sabnzbd.panic import panic_tmpl, panic_port, panic_host, \
panic_sqlite, panic, launch_a_browser
import sabnzbd.scheduler as scheduler
import sabnzbd.config as config

5
sabnzbd/__init__.py

@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Imported to be referenced from other files directly
from sabnzbd.version import __version__, __baseline__
import os
@ -23,8 +24,6 @@ import datetime
import tempfile
import cPickle
import pickle
import zipfile
import glob
import gzip
import subprocess
import time
@ -32,7 +31,7 @@ import socket
import cherrypy
import sys
import re
from threading import RLock, Lock, Condition, Thread
from threading import Lock, Thread
try:
import sleepless
except ImportError:

17
sabnzbd/api.py

@ -27,7 +27,7 @@ import time
import json
import cherrypy
import locale
import socket
from threading import Thread
try:
locale.setlocale(locale.LC_ALL, "")
@ -40,10 +40,9 @@ try:
except ImportError:
pass
import sabnzbd
from sabnzbd.constants import VALID_ARCHIVES, Status, \
TOP_PRIORITY, REPAIR_PRIORITY, HIGH_PRIORITY, HIGH_PRIORITY, NORMAL_PRIORITY, LOW_PRIORITY, \
TOP_PRIORITY, REPAIR_PRIORITY, HIGH_PRIORITY, NORMAL_PRIORITY, LOW_PRIORITY, \
KIBI, MEBI, GIGI, JOB_ADMIN
import sabnzbd.config as config
import sabnzbd.cfg as cfg
@ -165,14 +164,8 @@ def _api_del_config(name, output, kwargs):
def _api_qstatus(name, output, kwargs):
""" API: accepts output """
if output == 'json':
# Compatibility Fix:
# Old qstatus did not have a keyword, so do not use one now.
keyword = ''
else:
keyword = 'queue'
info, pnfo_list, bytespersec = build_queue()
return report(output, keyword='', data=remove_callable(info))
return report(output, data=remove_callable(info))
def _api_queue(name, output, kwargs):
@ -1340,7 +1333,6 @@ def build_queue(start=0, limit=0, trans=False, output=None, search=None):
priority = pnfo.priority
mbleft = (bytesleft / MEBI)
mb = (bytes / MEBI)
missing = pnfo.missing
slot = {'index': n, 'nzo_id': str(nzo_id)}
slot['unpackopts'] = str(sabnzbd.opts_to_pp(pnfo.repair, pnfo.unpack, pnfo.delete))
@ -1812,9 +1804,6 @@ def build_history(start=None, limit=None, verbose=False, verbose_list=None, sear
cookie = cherrypy.request.cookie
if 'history_verbosity' in cookie:
k = cookie['history_verbosity'].value
c_path = cookie['history_verbosity']['path']
c_age = cookie['history_verbosity']['max-age']
c_version = cookie['history_verbosity']['version']
if k == 'all':
details_show_all = True

2
sabnzbd/assembler.py

@ -37,7 +37,7 @@ from sabnzbd.articlecache import ArticleCache
from sabnzbd.postproc import PostProcessor
import sabnzbd.downloader
import sabnzbd.utils.rarfile as rarfile
from sabnzbd.encoding import unicoder, deunicode, is_utf8
from sabnzbd.encoding import unicoder, is_utf8
from sabnzbd.rating import Rating

2
sabnzbd/decoder.py

@ -19,7 +19,6 @@
sabnzbd.decoder - article decoder
"""
import Queue
import binascii
import logging
import re
@ -31,7 +30,6 @@ from sabnzbd.constants import Status, MAX_DECODE_QUEUE, LIMIT_DECODE_QUEUE, SABY
import sabnzbd.articlecache
import sabnzbd.downloader
import sabnzbd.nzbqueue
import sabnzbd.cfg as cfg
from sabnzbd.encoding import yenc_name_fixer
from sabnzbd.misc import match_str

15
sabnzbd/encoding.py

@ -51,14 +51,6 @@ def change_fsys(value):
auto_fsys()
def reliable_unpack_names():
""" See if it is safe to rely on unrar names """
if sabnzbd.WIN32 or sabnzbd.DARWIN:
return True
else:
return gUTF
def platform_encode(p):
""" Return Unicode name, if not already Unicode, decode with UTF-8 or latin1 """
if isinstance(p, str):
@ -145,13 +137,6 @@ def unicoder(p, force=False):
return unicode(str(p))
def unicode2local(p):
""" Convert Unicode filename to appropriate local encoding
Leave ? characters for uncovertible characters
"""
return p
def xml_name(p, keep_escape=False, encoding=None):
""" Prepare name for use in HTML/XML contect """

7
sabnzbd/interface.py

@ -21,7 +21,6 @@ sabnzbd.interface - webinterface
import os
import time
import datetime
import cherrypy
import logging
import urllib
@ -41,7 +40,6 @@ from Cheetah.Template import Template
from sabnzbd.misc import real_path, to_units, from_units, \
time_format, long_path, calc_age, \
cat_to_opts, int_conv, globber, globber_full, remove_all, get_base_url
from sabnzbd.panic import panic_old_queue
from sabnzbd.newswrapper import GetServerParms
from sabnzbd.rating import Rating
from sabnzbd.bpsmeter import BPSMeter
@ -60,9 +58,8 @@ from sabnzbd.utils.sslinfo import ssl_version, ssl_protocols_labels
from sabnzbd.utils.diskspeed import diskspeedmeasure
from sabnzbd.utils.getperformance import getpystone
from sabnzbd.constants import \
NORMAL_PRIORITY, MEBI, DEF_SKIN_COLORS, DEF_STDINTF, DEF_STDCONFIG, DEF_MAIN_TMPL, \
DEFAULT_PRIORITY
from sabnzbd.constants import NORMAL_PRIORITY, MEBI, DEF_SKIN_COLORS, DEF_STDINTF, \
DEF_STDCONFIG, DEF_MAIN_TMPL, DEFAULT_PRIORITY
from sabnzbd.lang import list_languages, set_language

11
sabnzbd/misc.py

@ -1009,15 +1009,6 @@ def trim_win_path(path):
return path
def check_win_maxpath(folder):
""" Return False if any file path in folder exceeds the Windows maximum """
if sabnzbd.WIN32:
for p in os.listdir(folder):
if len(os.path.join(folder, p)) > 259:
return False
return True
def make_script_path(script):
""" Return full script path, if any valid script exists, else None """
s_path = None
@ -1231,7 +1222,7 @@ def create_https_certificates(ssl_cert, ssl_key):
try:
from sabnzbd.utils.certgen import generate_key, generate_local_cert
private_key = generate_key(key_size=2048, output_file=ssl_key)
cert = generate_local_cert(private_key, days_valid=3560, output_file=ssl_cert, LN=u'SABnzbd', ON=u'SABnzbd', CN=u'localhost')
generate_local_cert(private_key, days_valid=3560, output_file=ssl_cert, LN=u'SABnzbd', ON=u'SABnzbd', CN=u'localhost')
logging.info('Self-signed certificates generated successfully')
except:
logging.error(T('Error creating SSL key and certificate'))

3
sabnzbd/newsunpack.py

@ -29,8 +29,7 @@ import binascii
import shutil
import sabnzbd
from sabnzbd.encoding import TRANS, UNTRANS, unicode2local, \
reliable_unpack_names, unicoder, platform_encode, deunicode
from sabnzbd.encoding import TRANS, UNTRANS, unicoder, platform_encode, deunicode
import sabnzbd.utils.rarfile as rarfile
from sabnzbd.misc import format_time_string, find_on_path, make_script_path, int_conv, \
flag_file, real_path, globber, globber_full, get_all_passwords, renamer, clip_path, \

1
sabnzbd/newswrapper.py

@ -26,7 +26,6 @@ from nntplib import NNTPPermanentError
import time
import logging
import re
import select
import ssl
import sabnzbd

10
sabnzbd/nzbqueue.py

@ -31,11 +31,10 @@ from sabnzbd.misc import exit_sab, cat_to_opts, \
from sabnzbd.panic import panic_queue
import sabnzbd.database as database
from sabnzbd.decorators import NZBQUEUE_LOCK, synchronized, synchronized_CV
from sabnzbd.constants import QUEUE_FILE_NAME, QUEUE_VERSION, FUTURE_Q_FOLDER, JOB_ADMIN, \
LOW_PRIORITY, NORMAL_PRIORITY, HIGH_PRIORITY, TOP_PRIORITY, \
from sabnzbd.constants import QUEUE_FILE_NAME, QUEUE_VERSION, FUTURE_Q_FOLDER, \
JOB_ADMIN, LOW_PRIORITY, NORMAL_PRIORITY, HIGH_PRIORITY, TOP_PRIORITY, \
REPAIR_PRIORITY, STOP_PRIORITY, VERIFIED_FILE, \
Status, QUEUE_FILE_TMPL, \
IGNORED_FOLDERS, QNFO
Status, IGNORED_FOLDERS, QNFO
import sabnzbd.cfg as cfg
from sabnzbd.articlecache import ArticleCache
@ -68,7 +67,7 @@ class NzbQueue(object):
# Read the queue from the saved files
data = sabnzbd.load_admin(QUEUE_FILE_NAME)
if not data:
# Warn bout old queue
# Warn about old queue
if sabnzbd.OLD_QUEUE and cfg.warned_old_queue() < QUEUE_VERSION:
logging.warning(T('Old queue detected, use Status->Repair to convert the queue'))
cfg.warned_old_queue.set(QUEUE_VERSION)
@ -864,7 +863,6 @@ class NzbQueue(object):
enough, _ratio = nzo.check_quality()
if enough:
# Enough data present, do real download
_workdir = nzo.downpath
self.cleanup_nzo(nzo, keep_basic=True)
self.send_back(nzo)
return

38
sabnzbd/nzbstuff.py

@ -43,12 +43,11 @@ from sabnzbd.constants import GIGI, ATTRIB_FILE, JOB_ADMIN, \
RENAMES_FILE, Status, PNFO
from sabnzbd.misc import to_units, cat_to_opts, cat_convert, sanitize_foldername, \
get_unique_path, get_admin_path, remove_all, sanitize_filename, globber_full, \
sanitize_foldername, int_conv, set_permissions, format_time_string, long_path, \
trim_win_path, fix_unix_encoding, calc_age
int_conv, set_permissions, format_time_string, long_path, trim_win_path, \
fix_unix_encoding, calc_age
from sabnzbd.decorators import synchronized, IO_LOCK
import sabnzbd.config as config
import sabnzbd.cfg as cfg
from sabnzbd.trylist import TryList
from sabnzbd.encoding import unicoder, platform_encode
from sabnzbd.database import HistoryDB
from sabnzbd.rating import Rating
@ -61,6 +60,36 @@ PROBABLY_PAR2_RE = re.compile(r'(.*)\.vol(\d*)[\+\-](\d*)\.par2', re.I)
REJECT_PAR2_RE = re.compile(r'\.par2\.\d+', re.I) # Reject duplicate par2 files
RE_NORMAL_NAME = re.compile(r'\.\w{2,5}$') # Test reasonably sized extension at the end
##############################################################################
# Trylist
##############################################################################
class TryList(object):
""" TryList keeps track of which servers have been tried for a specific article
This used to have a Lock, but it's not needed (all atomic) and faster without
"""
# Pre-define attributes to save memory
__slots__ = ('__try_list', 'fetcher_priority')
def __init__(self):
self.__try_list = []
self.fetcher_priority = 0
def server_in_try_list(self, server):
""" Return whether specified server has been tried """
return server in self.__try_list
def add_to_try_list(self, server):
""" Register server as having been tried already """
self.__try_list.append(server)
def reset_try_list(self):
""" Clean the list """
self.__try_list = []
self.fetcher_priority = 0
##############################################################################
# Article
##############################################################################
@ -865,7 +894,7 @@ class NzbObject(TryList):
if accept == 2:
self.deleted = True
self.status = Status.FAILED
nzo_id = sabnzbd.NzbQueue.do.add(self, quiet=True)
sabnzbd.NzbQueue.do.add(self, quiet=True)
sabnzbd.NzbQueue.do.end_job(self)
# Raise error, so it's not added
raise TypeError
@ -1239,7 +1268,6 @@ class NzbObject(TryList):
@synchronized(IO_LOCK)
def set_download_report(self):
import sabnzbd.api
if self.avg_bps_total and self.bytes_downloaded and self.avg_bps_freq:
# get the deltatime since the download started
avg_bps = self.avg_bps_total / self.avg_bps_freq

34
sabnzbd/panic.py

@ -34,7 +34,6 @@ PANIC_NONE = 0
PANIC_PORT = 1
PANIC_TEMPL = 2
PANIC_QUEUE = 3
PANIC_FWALL = 4
PANIC_OTHER = 5
PANIC_SQLITE = 7
PANIC_HOST = 8
@ -59,16 +58,6 @@ def MSG_BAD_NEWS():
'''
def MSG_BAD_FWALL():
return Ta(r'''
SABnzbd is not compatible with some software firewalls.<br>
%s<br>
Sorry, but we cannot solve this incompatibility right now.<br>
Please file a complaint at your firewall supplier.<br>
<br>
''')
def MSG_BAD_PORT():
return Ta(r'''
SABnzbd needs a free tcp/ip port for its internal web server.<br>
@ -127,15 +116,6 @@ def MSG_OTHER():
return T('SABnzbd detected a fatal error:') + '<br>%s<br><br>%s<br>'
def MSG_OLD_QUEUE():
return Ta(r'''
SABnzbd detected a queue from an older release.<br><br>
You can convert the queue by clicking "Repair" in Status-&gt;"Queue Repair".<br><br>
You may choose to stop SABnzbd and finish the queue with the older program.<br><br>
Click OK to proceed to SABnzbd''') + \
('''<br><br><FORM><input type="button" onclick="this.form.action='/.'; this.form.submit(); return false;" value="%s"/></FORM>''' % T('OK'))
def MSG_SQLITE():
return Ta(r'''
SABnzbd detected that the file sqlite3.dll is missing.<br><br>
@ -162,11 +142,6 @@ def panic_message(panic, a=None, b=None):
msg = MSG_BAD_TEMPL() % a
elif panic == PANIC_QUEUE:
msg = MSG_BAD_QUEUE() % (a, os_str, prog_path)
elif panic == PANIC_FWALL:
if a:
msg = MSG_BAD_FWALL() % T('It is likely that you are using ZoneAlarm on Vista.<br>')
else:
msg = MSG_BAD_FWALL() % "<br>"
elif panic == PANIC_SQLITE:
msg = MSG_SQLITE()
elif panic == PANIC_HOST:
@ -189,10 +164,6 @@ def panic_message(panic, a=None, b=None):
return url
def panic_fwall(vista):
launch_a_browser(panic_message(PANIC_FWALL, vista))
def panic_port(host, port):
print "\n%s:\n %s" % (T('Fatal error'), T('Unable to bind to port %s on %s. Some other software uses the port or SABnzbd is already running.') % (port, host))
launch_a_browser(panic_message(PANIC_PORT, host, port))
@ -214,11 +185,6 @@ def panic_sqlite(name):
launch_a_browser(panic_message(PANIC_SQLITE, name, 0))
def panic_old_queue():
msg = MSG_OLD_QUEUE()
return MSG_BAD_NEWS() % (sabnzbd.MY_NAME, sabnzbd.__version__, sabnzbd.MY_NAME, sabnzbd.__version__, msg, '')
def panic(reason, remedy=""):
print "\n%s:\n %s\n%s" % (T('Fatal error'), reason, remedy)
launch_a_browser(panic_message(PANIC_OTHER, reason, remedy))

4
sabnzbd/postproc.py

@ -34,12 +34,12 @@ from threading import Thread
from sabnzbd.misc import real_path, get_unique_path, create_dirs, move_to_path, \
make_script_path, long_path, clip_path, \
on_cleanup_list, renamer, remove_dir, remove_all, globber, globber_full, \
set_permissions, cleanup_empty_directories, check_win_maxpath, fix_unix_encoding, \
set_permissions, cleanup_empty_directories, fix_unix_encoding, \
sanitize_and_trim_path, sanitize_files_in_folder
from sabnzbd.tvsort import Sorter
from sabnzbd.constants import REPAIR_PRIORITY, TOP_PRIORITY, POSTPROC_QUEUE_FILE_NAME, \
POSTPROC_QUEUE_VERSION, sample_match, JOB_ADMIN, Status, VERIFIED_FILE
from sabnzbd.encoding import TRANS, unicoder, deunicode
from sabnzbd.encoding import TRANS, unicoder
from sabnzbd.rating import Rating
import sabnzbd.emailer as emailer
import sabnzbd.dirscanner as dirscanner

1
sabnzbd/rss.py

@ -197,7 +197,6 @@ class RSSQueue(object):
continue
self.jobs[feed] = {}
for link in feeds[feed]:
data = feeds[feed][link]
# Consistency check on data
try:
item = feeds[feed][link]

50
sabnzbd/trylist.py

@ -1,50 +0,0 @@
#!/usr/bin/python -OO
# Copyright 2008-2017 The SABnzbd-Team <team@sabnzbd.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
sabnzbd.trylist - trylist class
"""
import logging
from threading import Lock
import sabnzbd
from sabnzbd.decorators import synchronized
# TryList keeps track of which servers have been tried for a specific article
# This used to have a Lock, but it's not needed (all atomic) and faster without
class TryList(object):
# Pre-define attributes to save memory
__slots__ = ('__try_list', 'fetcher_priority')
def __init__(self):
self.__try_list = []
self.fetcher_priority = 0
def server_in_try_list(self, server):
""" Return whether specified server has been tried """
return server in self.__try_list
def add_to_try_list(self, server):
""" Register server as having been tried already """
self.__try_list.append(server)
def reset_try_list(self):
""" Clean the list """
self.__try_list = []
self.fetcher_priority = 0
Loading…
Cancel
Save