Browse Source

Corrections after running PyLint.

Mostly non-functionals like: unnecessary imports, unused variables, irregular indentation etc.
Also found some potential problems:
- Incorrect use of a global in __init__.py (health guardian)
- Missing error texts in API
- Bandwidth limit did not support KMG notation, while it should
tags/0.6.0
shypike 16 years ago
parent
commit
742ce95949
  1. 1
      main/SABnzbd.py
  2. 6
      main/sabnzbd/__init__.py
  3. 8
      main/sabnzbd/assembler.py
  4. 3
      main/sabnzbd/cfg.py
  5. 2
      main/sabnzbd/codecs.py
  6. 28
      main/sabnzbd/config.py
  7. 3
      main/sabnzbd/database.py
  8. 4
      main/sabnzbd/decoder.py
  9. 10
      main/sabnzbd/dirscanner.py
  10. 1
      main/sabnzbd/email.py
  11. 40
      main/sabnzbd/interface.py
  12. 9
      main/sabnzbd/lang.py
  13. 5
      main/sabnzbd/misc.py
  14. 15
      main/sabnzbd/newsunpack.py
  15. 19
      main/sabnzbd/newswrapper.py
  16. 1
      main/sabnzbd/newzbin.py
  17. 28
      main/sabnzbd/nzbqueue.py
  18. 2
      main/sabnzbd/nzbstuff.py
  19. 21
      main/sabnzbd/postproc.py
  20. 4
      main/sabnzbd/scheduler.py
  21. 2
      main/sabnzbd/tvsort.py
  22. 4
      main/sabnzbd/urlgrabber.py
  23. 2
      main/sabnzbd/wizard.py

1
main/SABnzbd.py

@ -982,7 +982,6 @@ def main():
logging.info('[osx] IO priority set to throttle for process scope') logging.info('[osx] IO priority set to throttle for process scope')
except: except:
logging.info('[osx] IO priority setting not supported') logging.info('[osx] IO priority setting not supported')
pass
if AUTOBROWSER != None: if AUTOBROWSER != None:
sabnzbd.cfg.AUTOBROWSER.set(AUTOBROWSER) sabnzbd.cfg.AUTOBROWSER.set(AUTOBROWSER)

6
main/sabnzbd/__init__.py

@ -154,8 +154,8 @@ def connect_db(thread_index):
@synchronized(INIT_LOCK) @synchronized(INIT_LOCK)
def initialize(pause_downloader = False, clean_up = False, force_save= False, evalSched=False): def initialize(pause_downloader = False, clean_up = False, evalSched=False):
global __INITIALIZED__, \ global __INITIALIZED__, __SHUTTING_DOWN__,\
LOGFILE, WEBLOGFILE, LOGHANDLER, GUIHANDLER, AMBI_LOCALHOST, WAITEXIT, \ LOGFILE, WEBLOGFILE, LOGHANDLER, GUIHANDLER, AMBI_LOCALHOST, WAITEXIT, \
DEBUG_DELAY, \ DEBUG_DELAY, \
DAEMON, MY_NAME, MY_FULLNAME, NEW_VERSION, \ DAEMON, MY_NAME, MY_FULLNAME, NEW_VERSION, \
@ -271,7 +271,7 @@ def start():
@synchronized(INIT_LOCK) @synchronized(INIT_LOCK)
def halt(): def halt():
global __INITIALIZED__ global __INITIALIZED__, __SHUTTING_DOWN__
if __INITIALIZED__: if __INITIALIZED__:
logging.info('SABnzbd shutting down...') logging.info('SABnzbd shutting down...')

8
main/sabnzbd/assembler.py

@ -19,7 +19,6 @@
sabnzbd.assembler - threaded assembly/decoding of files sabnzbd.assembler - threaded assembly/decoding of files
""" """
import sys
import os import os
import Queue import Queue
import binascii import binascii
@ -27,7 +26,6 @@ import logging
import struct import struct
from threading import Thread from threading import Thread
from time import sleep from time import sleep
import subprocess
try: try:
import hashlib import hashlib
new_md5 = hashlib.md5 new_md5 = hashlib.md5
@ -41,7 +39,7 @@ import sabnzbd.cfg as cfg
import sabnzbd.articlecache import sabnzbd.articlecache
import sabnzbd.postproc import sabnzbd.postproc
import sabnzbd.downloader import sabnzbd.downloader
from sabnzbd.lang import T, Ta from sabnzbd.lang import Ta
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -118,7 +116,7 @@ class Assembler(Thread):
if filepath: if filepath:
logging.info('Decoding %s %s', filepath, nzf.get_type()) logging.info('Decoding %s %s', filepath, nzf.get_type())
try: try:
filepath = _assemble(nzo, nzf, filepath, dupe) filepath = _assemble(nzf, filepath, dupe)
except IOError, (errno, strerror): except IOError, (errno, strerror):
# 28 == disk full => pause downloader # 28 == disk full => pause downloader
if errno == 28: if errno == 28:
@ -139,7 +137,7 @@ class Assembler(Thread):
sabnzbd.postproc.process(nzo) sabnzbd.postproc.process(nzo)
def _assemble(nzo, nzf, path, dupe): def _assemble(nzf, path, dupe):
if os.path.exists(path): if os.path.exists(path):
unique_path = get_unique_path(path, create_dir = False) unique_path = get_unique_path(path, create_dir = False)
if dupe: if dupe:

3
main/sabnzbd/cfg.py

@ -19,7 +19,6 @@
sabnzbd.cfg - Configuration Parameters sabnzbd.cfg - Configuration Parameters
""" """
import os
import sabnzbd import sabnzbd
from sabnzbd.constants import * from sabnzbd.constants import *
from sabnzbd.config import OptionBool, OptionNumber, OptionPassword, \ from sabnzbd.config import OptionBool, OptionNumber, OptionPassword, \
@ -149,7 +148,7 @@ else:
USERNAME = OptionStr('misc', 'username') USERNAME = OptionStr('misc', 'username')
PASSWORD = OptionPassword('misc', 'password') PASSWORD = OptionPassword('misc', 'password')
BANDWIDTH_LIMIT = OptionNumber('misc', 'bandwidth_limit', 0) BANDWIDTH_LIMIT = OptionStr('misc', 'bandwidth_limit', 0)
REFRESH_RATE = OptionNumber('misc', 'refresh_rate', 0) REFRESH_RATE = OptionNumber('misc', 'refresh_rate', 0)
RSS_RATE = OptionNumber('misc', 'rss_rate', 60, 15, 24*60) RSS_RATE = OptionNumber('misc', 'rss_rate', 60, 15, 24*60)
CACHE_LIMIT = OptionStr('misc', 'cache_limit') CACHE_LIMIT = OptionStr('misc', 'cache_limit')

2
main/sabnzbd/codecs.py

@ -19,8 +19,6 @@
sabnzbd.codecs - Unicoded filename support sabnzbd.codecs - Unicoded filename support
""" """
import os
import sys
import locale import locale
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
from Cheetah.Filters import Filter from Cheetah.Filters import Filter

28
main/sabnzbd/config.py

@ -86,7 +86,7 @@ class Option:
""" Set value based on dictionary """ """ Set value based on dictionary """
try: try:
return self.set(dict['value']) return self.set(dict['value'])
except: except KeyError:
return False return False
def __set(self, value): def __set(self, value):
@ -130,7 +130,7 @@ class OptionNumber(Option):
value = int(value) value = int(value)
else: else:
value = float(value) value = float(value)
except: except ValueError:
value = 0 value = 0
if self.__validation: if self.__validation:
error, val = self.__validation(value) error, val = self.__validation(value)
@ -305,13 +305,13 @@ def add_to_database(section, keyword, object):
@synchronized(CONFIG_LOCK) @synchronized(CONFIG_LOCK)
def delete_from_database(section, keyword): def delete_from_database(section, keyword):
global database, CFG, modified global database, CFG, modified
del database[section][keyword] del database[section][keyword]
try: try:
del CFG[section][keyword] del CFG[section][keyword]
except KeyError: except KeyError:
pass pass
modified = True modified = True
class ConfigServer: class ConfigServer:
@ -621,7 +621,7 @@ def read_config(path):
""" Read the complete INI file and check its version number """ Read the complete INI file and check its version number
if OK, pass values to config-database if OK, pass values to config-database
""" """
global CFG, database, categories, rss_feeds, servers, modified global CFG, database, modified
if not os.path.exists(path): if not os.path.exists(path):
# No file found, create default INI file # No file found, create default INI file
@ -660,9 +660,9 @@ def read_config(path):
except KeyError: except KeyError:
pass pass
categories = define_categories() define_categories()
rss_feeds = define_rss() define_rss()
servers = define_servers() define_servers()
modified = False modified = False
return True return True
@ -821,7 +821,7 @@ def decode_password(pw, name):
if pw and pw.startswith(__PW_PREFIX): if pw and pw.startswith(__PW_PREFIX):
for n in range(len(__PW_PREFIX), len(pw), 2): for n in range(len(__PW_PREFIX), len(pw), 2):
try: try:
ch = chr( int(pw[n] + pw[n+1],16) ) ch = chr( int(pw[n] + pw[n+1], 16) )
except: except:
logging.error(Ta('error-encPw@1'), name) logging.error(Ta('error-encPw@1'), name)
return '' return ''

3
main/sabnzbd/database.py

@ -33,11 +33,10 @@ import datetime
from calendar import MONDAY from calendar import MONDAY
import zlib import zlib
import logging import logging
from threading import Thread
import sabnzbd import sabnzbd
import sabnzbd.cfg import sabnzbd.cfg
from sabnzbd.constants import DB_HISTORY_VERSION, DB_HISTORY_NAME from sabnzbd.constants import DB_HISTORY_NAME
from sabnzbd.lang import T, Ta from sabnzbd.lang import T, Ta
from sabnzbd.codecs import unicoder from sabnzbd.codecs import unicoder

4
main/sabnzbd/decoder.py

@ -38,7 +38,7 @@ import sabnzbd.downloader
import sabnzbd.cfg as cfg import sabnzbd.cfg as cfg
import sabnzbd.nzbqueue import sabnzbd.nzbqueue
from sabnzbd.codecs import name_fixer from sabnzbd.codecs import name_fixer
from sabnzbd.lang import T, Ta from sabnzbd.lang import Ta
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@ -59,7 +59,7 @@ class Decoder(Thread):
def __init__(self, servers): def __init__(self, servers):
Thread.__init__(self) Thread.__init__(self)
self.queue = Queue.Queue(); self.queue = Queue.Queue()
self.servers = servers self.servers = servers
def decode(self, article, lines): def decode(self, article, lines):

10
main/sabnzbd/dirscanner.py

@ -20,20 +20,14 @@ sabnzbd.dirscanner - Scanner for Watched Folder
""" """
import os import os
import sys
import time import time
import logging import logging
import urllib
import re import re
import zipfile import zipfile
import gzip import gzip
import webbrowser
import tempfile
import shutil
import threading import threading
import sabnzbd import sabnzbd
from sabnzbd.decorators import synchronized
from sabnzbd.constants import * from sabnzbd.constants import *
from sabnzbd.utils.rarfile import is_rarfile, RarFile from sabnzbd.utils.rarfile import is_rarfile, RarFile
import sabnzbd.nzbstuff as nzbstuff import sabnzbd.nzbstuff as nzbstuff
@ -41,7 +35,7 @@ import sabnzbd.misc as misc
import sabnzbd.config as config import sabnzbd.config as config
import sabnzbd.cfg as cfg import sabnzbd.cfg as cfg
import sabnzbd.nzbqueue import sabnzbd.nzbqueue
from sabnzbd.lang import T, Ta from sabnzbd.lang import Ta
################################################################################ ################################################################################
# Wrapper functions # Wrapper functions
@ -271,6 +265,8 @@ class DirScanner(threading.Thread):
self.shutdown = False self.shutdown = False
self.error_reported = False # Prevents mulitple reporting of missing watched folder self.error_reported = False # Prevents mulitple reporting of missing watched folder
self.dirscan_dir = cfg.DIRSCAN_DIR.get_path()
self.dirscan_speed = cfg.DIRSCAN_SPEED.get()
cfg.DIRSCAN_DIR.callback(self.newdir) cfg.DIRSCAN_DIR.callback(self.newdir)
def newdir(self): def newdir(self):

1
main/sabnzbd/email.py

@ -24,7 +24,6 @@ from sabnzbd.utils import ssmtplib
import smtplib import smtplib
import os import os
import logging import logging
import subprocess
import re import re
import time import time
import glob import glob

40
main/sabnzbd/interface.py

@ -29,18 +29,16 @@ import glob
import urllib import urllib
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
from sabnzbd.utils.rsslib import RSS, Item, Namespace from sabnzbd.utils.rsslib import RSS, Item
from sabnzbd.utils.json import JsonWriter from sabnzbd.utils.json import JsonWriter
import sabnzbd import sabnzbd
import sabnzbd.rss import sabnzbd.rss
import sabnzbd.scheduler as scheduler import sabnzbd.scheduler as scheduler
from sabnzbd.utils import listquote
from sabnzbd.utils.configobj import ConfigObj
from Cheetah.Template import Template from Cheetah.Template import Template
import sabnzbd.email as email import sabnzbd.email as email
from sabnzbd.misc import real_path, create_real_path, loadavg, \ from sabnzbd.misc import real_path, loadavg, \
to_units, from_units, diskfree, disktotal, get_ext, sanitize_foldername, \ to_units, diskfree, disktotal, get_ext, sanitize_foldername, \
get_filename, cat_to_opts, IntConv get_filename, cat_to_opts, IntConv
from sabnzbd.newswrapper import GetServerParms from sabnzbd.newswrapper import GetServerParms
import sabnzbd.newzbin as newzbin import sabnzbd.newzbin as newzbin
@ -53,7 +51,7 @@ import sabnzbd.postproc as postproc
import sabnzbd.downloader as downloader import sabnzbd.downloader as downloader
import sabnzbd.bpsmeter as bpsmeter import sabnzbd.bpsmeter as bpsmeter
import sabnzbd.nzbqueue as nzbqueue import sabnzbd.nzbqueue as nzbqueue
from sabnzbd.database import get_history_handle, build_history_info, unpack_history_info from sabnzbd.database import build_history_info, unpack_history_info
import sabnzbd.wizard import sabnzbd.wizard
from sabnzbd.utils.servertests import test_nntp_server_dict from sabnzbd.utils.servertests import test_nntp_server_dict
@ -197,11 +195,9 @@ def check_session(kwargs):
if not key: if not key:
logging.warning(Ta('warn-missingKey')) logging.warning(Ta('warn-missingKey'))
msg = T('error-missingKey') msg = T('error-missingKey')
pass
elif key != cfg.API_KEY.get(): elif key != cfg.API_KEY.get():
logging.warning(Ta('warn-badKey')) logging.warning(Ta('warn-badKey'))
msg = T('error-badKey') msg = T('error-badKey')
pass
return msg return msg
@ -261,6 +257,8 @@ class NoPage:
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
_MSG_NO_VALUE = 'expect one parameter' _MSG_NO_VALUE = 'expect one parameter'
_MSG_NO_VALUE2 = 'expect two parameters' _MSG_NO_VALUE2 = 'expect two parameters'
_MSG_INT_VALUE = 'expect integer value'
_MSG_NO_ITEM = 'item does not exist'
_MSG_NOT_IMPLEMENTED = 'not implemented' _MSG_NOT_IMPLEMENTED = 'not implemented'
_MSG_NO_FILE = 'no file given' _MSG_NO_FILE = 'no file given'
_MSG_NO_PATH = 'file does not exist' _MSG_NO_PATH = 'file does not exist'
@ -551,7 +549,7 @@ class MainPage:
return report(output) return report(output)
elif value: elif value:
items = value.split(',') items = value.split(',')
nzbqueue.remove_multiple_nzos(items, False) nzbqueue.remove_multiple_nzos(items)
return report(output) return report(output)
else: else:
return report(output, _MSG_NO_VALUE) return report(output, _MSG_NO_VALUE)
@ -1758,21 +1756,21 @@ class ConfigGeneral:
raise dcRaiser(self.__root, kwargs) raise dcRaiser(self.__root, kwargs)
def change_web_dir(web_dir): def change_web_dir(web_dir):
try:
web_dir, web_color = web_dir.split(' - ')
except:
try: try:
web_dir, web_color = web_dir.split(' - ') web_color = DEF_SKIN_COLORS[web_dir.lower()]
except: except:
try: web_color = ''
web_color = DEF_SKIN_COLORS[web_dir.lower()]
except:
web_color = ''
web_dir_path = real_path(sabnzbd.DIR_INTERFACES, web_dir) web_dir_path = real_path(sabnzbd.DIR_INTERFACES, web_dir)
if not os.path.exists(web_dir_path): if not os.path.exists(web_dir_path):
return badParameterResponse('Cannot find web template: %s' % web_dir_path) return badParameterResponse('Cannot find web template: %s' % web_dir_path)
else: else:
cfg.WEB_DIR.set(web_dir) cfg.WEB_DIR.set(web_dir)
cfg.WEB_COLOR.set(web_color) cfg.WEB_COLOR.set(web_color)
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -3296,7 +3294,7 @@ class xml_factory:
elif isinstance(lst, tuple): elif isinstance(lst, tuple):
text = self._tuple(keyw, lst) text = self._tuple(keyw, lst)
elif keyw: elif keyw:
text = '<%s>%s</%s>\n' % (keyw, xml_name(lst, encoding='utf-8'), keyw) text = '<%s>%s</%s>\n' % (keyw, xml_name(lst, encoding='utf-8'), keyw)
else: else:
text = '' text = ''
return text return text

9
main/sabnzbd/lang.py

@ -97,7 +97,7 @@ def list_languages(path):
""" Return list of languages-choices """ Return list of languages-choices
Each choice is a list, 0: short name, 1: long name Each choice is a list, 0: short name, 1: long name
""" """
list = [] lst = []
for name in glob.glob(path + '/*.txt'): for name in glob.glob(path + '/*.txt'):
lang = os.path.basename(name).replace('.txt','') lang = os.path.basename(name).replace('.txt','')
try: try:
@ -106,8 +106,8 @@ def list_languages(path):
continue continue
encoding, language = _get_headers(fp) encoding, language = _get_headers(fp)
long = u"%s" % language long_name = u"%s" % language
list.append((lang, long)) lst.append((lang, long_name))
fp.close() fp.close()
return list return list
@ -121,7 +121,7 @@ def _parse_lang_file(dic, name, prefix=''):
""" """
try: try:
f = open(name, "r") f = open(name, "r")
except: except IOError:
logging.error("Cannot open language file %s", name) logging.error("Cannot open language file %s", name)
return False return False
@ -133,6 +133,7 @@ def _parse_lang_file(dic, name, prefix=''):
prefix += '-' prefix += '-'
lcount = 0 lcount = 0
multi = False multi = False
msg = ''
for line in f.xreadlines(): for line in f.xreadlines():
line = line.strip('\n').decode(encoding) line = line.strip('\n').decode(encoding)
lcount += 1 lcount += 1

5
main/sabnzbd/misc.py

@ -35,7 +35,7 @@ import time
import sabnzbd import sabnzbd
from sabnzbd.decorators import synchronized from sabnzbd.decorators import synchronized
from sabnzbd.constants import * from sabnzbd.constants import *
import nzbqueue import sabnzbd.nzbqueue
import sabnzbd.config as config import sabnzbd.config as config
import sabnzbd.cfg as cfg import sabnzbd.cfg as cfg
from sabnzbd.lang import T, Ta from sabnzbd.lang import T, Ta
@ -265,7 +265,6 @@ def get_user_shellfolders():
except: except:
# probably a pywintypes.error error such as folder does not exist # probably a pywintypes.error error such as folder does not exist
logging.error("Traceback: ", exc_info = True) logging.error("Traceback: ", exc_info = True)
pass
i += 1 i += 1
_winreg.CloseKey(key) _winreg.CloseKey(key)
_winreg.CloseKey(hive) _winreg.CloseKey(hive)
@ -945,7 +944,7 @@ def create_https_certificates(ssl_cert, ssl_key):
try: try:
from OpenSSL import crypto from OpenSSL import crypto
from sabnzbd.utils.certgen import createKeyPair, createCertRequest, createCertificate,\ from sabnzbd.utils.certgen import createKeyPair, createCertRequest, createCertificate,\
TYPE_RSA, TYPE_DSA, serial TYPE_RSA, serial
except: except:
logging.warning(Ta('warn-pyopenssl')) logging.warning(Ta('warn-pyopenssl'))
return False return False

15
main/sabnzbd/newsunpack.py

@ -28,7 +28,7 @@ from time import time
import sabnzbd import sabnzbd
from sabnzbd.codecs import TRANS, unicode2local,name_fixer, reliable_unpack_names, unicoder from sabnzbd.codecs import TRANS, unicode2local,name_fixer, reliable_unpack_names, unicoder
from sabnzbd.utils.rarfile import is_rarfile, RarFile from sabnzbd.utils.rarfile import RarFile
from sabnzbd.misc import format_time_string, find_on_path from sabnzbd.misc import format_time_string, find_on_path
import sabnzbd.cfg as cfg import sabnzbd.cfg as cfg
from sabnzbd.lang import T, Ta from sabnzbd.lang import T, Ta
@ -388,12 +388,10 @@ def rar_unpack(nzo, workdir, workdir_complete, delete, rars):
# Delete the old files if we have to # Delete the old files if we have to
if delete and newfiles: if delete and newfiles:
i = 0
for rar in rars: for rar in rars:
logging.info("Deleting %s", rar) logging.info("Deleting %s", rar)
try: try:
os.remove(rar) os.remove(rar)
i += 1
except OSError: except OSError:
logging.warning(Ta('warn-delFailed@1'), rar) logging.warning(Ta('warn-delFailed@1'), rar)
@ -403,7 +401,6 @@ def rar_unpack(nzo, workdir, workdir_complete, delete, rars):
logging.info("Deleting %s", brokenrar) logging.info("Deleting %s", brokenrar)
try: try:
os.remove(brokenrar) os.remove(brokenrar)
i += 1
except OSError: except OSError:
logging.warning(Ta('warn-delFailed@1'), brokenrar) logging.warning(Ta('warn-delFailed@1'), brokenrar)
@ -661,7 +658,7 @@ def par2_repair(parfile_nzf, nzo, workdir, setname):
readd = False readd = False
try: try:
nzo.set_action_line(T('msg-repair'), T('msg-startRepair')) nzo.set_action_line(T('msg-repair'), T('msg-startRepair'))
logging.info('Scanning "%s"' % parfile) logging.info('Scanning "%s"', parfile)
joinables, zips, rars, ts = build_filelists(workdir, None) joinables, zips, rars, ts = build_filelists(workdir, None)
@ -690,8 +687,6 @@ def par2_repair(parfile_nzf, nzo, workdir, setname):
try: try:
if cfg.enable_par_cleanup.get(): if cfg.enable_par_cleanup.get():
i = 0
new_dir_content = os.listdir(workdir) new_dir_content = os.listdir(workdir)
for path in new_dir_content: for path in new_dir_content:
@ -701,7 +696,6 @@ def par2_repair(parfile_nzf, nzo, workdir, setname):
logging.info("Deleting %s", path) logging.info("Deleting %s", path)
os.remove(path) os.remove(path)
i += 1
except: except:
logging.warning(Ta('warn-delFailed@1'), path) logging.warning(Ta('warn-delFailed@1'), path)
@ -712,7 +706,6 @@ def par2_repair(parfile_nzf, nzo, workdir, setname):
try: try:
logging.info("Deleting %s", path) logging.info("Deleting %s", path)
os.remove(path) os.remove(path)
i += 1
except: except:
logging.warning(Ta('warn-delFailed@1'), path) logging.warning(Ta('warn-delFailed@1'), path)
@ -720,7 +713,6 @@ def par2_repair(parfile_nzf, nzo, workdir, setname):
try: try:
logging.info("Deleting %s", path2) logging.info("Deleting %s", path2)
os.remove(path2) os.remove(path2)
i += 1
except: except:
logging.warning(Ta('warn-delFailed@1'), path2) logging.warning(Ta('warn-delFailed@1'), path2)
@ -728,7 +720,6 @@ def par2_repair(parfile_nzf, nzo, workdir, setname):
try: try:
logging.info("Deleting %s", parfile) logging.info("Deleting %s", parfile)
os.remove(parfile) os.remove(parfile)
i += 1
except OSError: except OSError:
logging.warning(Ta('warn-delFailed@1'), parfile) logging.warning(Ta('warn-delFailed@1'), parfile)
@ -741,7 +732,6 @@ def par2_repair(parfile_nzf, nzo, workdir, setname):
logging.info("Deleting %s", filepath) logging.info("Deleting %s", filepath)
try: try:
os.remove(filepath) os.remove(filepath)
i += 1
except OSError: except OSError:
logging.warning(Ta('warn-delFailed@1'), filepath) logging.warning(Ta('warn-delFailed@1'), filepath)
except: except:
@ -793,7 +783,6 @@ def PAR_Verify(parfile, parfile_nzf, nzo, setname, joinables):
verifytotal = 0 verifytotal = 0
verified = 0 verified = 0
lines = []
# Loop over the output, whee # Loop over the output, whee
while 1: while 1:
char = proc.read(1) char = proc.read(1)

19
main/sabnzbd/newswrapper.py

@ -23,12 +23,12 @@ import errno
import socket import socket
from threading import Thread from threading import Thread
from nntplib import NNTPPermanentError from nntplib import NNTPPermanentError
from time import time import time
import logging import logging
import sabnzbd import sabnzbd
from sabnzbd.constants import * from sabnzbd.constants import *
from sabnzbd.lang import T, Ta from sabnzbd.lang import Ta
try: try:
from OpenSSL import SSL from OpenSSL import SSL
@ -45,7 +45,6 @@ _RLock = threading.RLock
del threading del threading
import select import select
import os
socket.setdefaulttimeout(DEF_TIMEOUT) socket.setdefaulttimeout(DEF_TIMEOUT)
@ -204,7 +203,7 @@ class NewsWrapper:
self.server.username, self.server.password, self.blocking) self.server.username, self.server.password, self.blocking)
self.recv = self.nntp.sock.recv self.recv = self.nntp.sock.recv
self.timeout = time() + self.server.timeout self.timeout = time.time() + self.server.timeout
def finish_connect(self): def finish_connect(self):
if not self.server.username or not self.server.password: if not self.server.username or not self.server.password:
@ -235,20 +234,20 @@ class NewsWrapper:
else: else:
self.connected = True self.connected = True
self.timeout = time() + self.server.timeout self.timeout = time.time() + self.server.timeout
def body(self): def body(self):
self.timeout = time() + self.server.timeout self.timeout = time.time() + self.server.timeout
command = 'BODY <%s>\r\n' % (self.article.article) command = 'BODY <%s>\r\n' % (self.article.article)
self.nntp.sock.sendall(command) self.nntp.sock.sendall(command)
def send_group(self, group): def send_group(self, group):
self.timeout = time() + self.server.timeout self.timeout = time.time() + self.server.timeout
command = 'GROUP %s\r\n' % (group) command = 'GROUP %s\r\n' % (group)
self.nntp.sock.sendall(command) self.nntp.sock.sendall(command)
def recv_chunk(self, block=False): def recv_chunk(self, block=False):
self.timeout = time() + self.server.timeout self.timeout = time.time() + self.server.timeout
while 1: while 1:
try: try:
chunk = self.recv(32768) chunk = self.recv(32768)
@ -295,10 +294,10 @@ class NewsWrapper:
# Wait before re-using this newswrapper # Wait before re-using this newswrapper
if wait: if wait:
# Reset due to error condition, use server timeout # Reset due to error condition, use server timeout
self.timeout = time() + self.server.timeout self.timeout = time.time() + self.server.timeout
else: else:
# Reset for internal reasons, just wait 5 sec # Reset for internal reasons, just wait 5 sec
self.timeout = time() + 5 self.timeout = time.time() + 5
def terminate(self): def terminate(self):
""" Close connection and remove nntp object """ """ Close connection and remove nntp object """

1
main/sabnzbd/newzbin.py

@ -342,6 +342,7 @@ class Bookmarks:
self.bookmarks = sabnzbd.load_data(BOOKMARK_FILE_NAME) self.bookmarks = sabnzbd.load_data(BOOKMARK_FILE_NAME)
if not self.bookmarks: if not self.bookmarks:
self.bookmarks = [] self.bookmarks = []
self.__busy = False
@synchronized(BOOK_LOCK) @synchronized(BOOK_LOCK)
def run(self, delete=None): def run(self, delete=None):

28
main/sabnzbd/nzbqueue.py

@ -19,15 +19,11 @@
sabnzbd.nzbqueue - nzb queue sabnzbd.nzbqueue - nzb queue
""" """
import sys
import os import os
import logging import logging
import sabnzbd
import time
import datetime import datetime
from threading import Thread, RLock import sabnzbd
from sabnzbd.trylist import TryList from sabnzbd.trylist import TryList
from sabnzbd.nzbstuff import NzbObject from sabnzbd.nzbstuff import NzbObject
from sabnzbd.misc import panic_queue, exit_sab, sanitize_foldername, cat_to_opts from sabnzbd.misc import panic_queue, exit_sab, sanitize_foldername, cat_to_opts
@ -115,8 +111,10 @@ class NzbQueue(TryList):
return future_nzo return future_nzo
@synchronized(NZBQUEUE_LOCK) @synchronized(NZBQUEUE_LOCK)
def insert_future(self, future, filename, msgid, data, pp=None, script=None, cat=None, priority=NORMAL_PRIORITY, nzbname=None, nzo_info={}): def insert_future(self, future, filename, msgid, data, pp=None, script=None, cat=None, priority=NORMAL_PRIORITY, nzbname=None, nzo_info=None):
""" Refresh a placeholder nzo with an actual nzo """ """ Refresh a placeholder nzo with an actual nzo """
if nzo_info is None:
nzo_info = {}
nzo_id = future.nzo_id nzo_id = future.nzo_id
if nzo_id in self.__nzo_table: if nzo_id in self.__nzo_table:
try: try:
@ -264,7 +262,7 @@ class NzbQueue(TryList):
@synchronized(NZBQUEUE_LOCK) @synchronized(NZBQUEUE_LOCK)
def remove_multiple(self, nzo_ids, add_to_history = True): def remove_multiple(self, nzo_ids):
for nzo_id in nzo_ids: for nzo_id in nzo_ids:
self.remove(nzo_id, add_to_history = False, save = False) self.remove(nzo_id, add_to_history = False, save = False)
self.save() self.save()
@ -485,10 +483,12 @@ class NzbQueue(TryList):
@synchronized(NZBQUEUE_LOCK) @synchronized(NZBQUEUE_LOCK)
def set_priority_multiple(self, nzo_ids, priority): def set_priority_multiple(self, nzo_ids, priority):
try: try:
n = -1
for nzo_id in nzo_ids: for nzo_id in nzo_ids:
self.set_priority(nzo_id, priority) n = self.set_priority(nzo_id, priority)
return n
except: except:
pass return -1
@synchronized(NZBQUEUE_LOCK) @synchronized(NZBQUEUE_LOCK)
def set_original_dirname(self, nzo_id, name): def set_original_dirname(self, nzo_id, name):
@ -757,9 +757,9 @@ def remove_nzo(nzo_id, add_to_history = True, unload=False):
global __NZBQ global __NZBQ
if __NZBQ: __NZBQ.remove(nzo_id, add_to_history, unload) if __NZBQ: __NZBQ.remove(nzo_id, add_to_history, unload)
def remove_multiple_nzos(nzo_ids, add_to_history = True): def remove_multiple_nzos(nzo_ids):
global __NZBQ global __NZBQ
if __NZBQ: __NZBQ.remove_multiple(nzo_ids, add_to_history) if __NZBQ: __NZBQ.remove_multiple(nzo_ids)
def remove_all_nzo(): def remove_all_nzo():
global __NZBQ global __NZBQ
@ -896,8 +896,10 @@ def add_nzo(nzo):
if __NZBQ: __NZBQ.add(nzo) if __NZBQ: __NZBQ.add(nzo)
@synchronized_CV @synchronized_CV
def insert_future_nzo(future_nzo, filename, msgid, data, pp=None, script=None, cat=None, priority=NORMAL_PRIORITY, nzbname=None, nzo_info={}): def insert_future_nzo(future_nzo, filename, msgid, data, pp=None, script=None, cat=None, priority=NORMAL_PRIORITY, nzbname=None, nzo_info=None):
global __NZBQ global __NZBQ
if nzo_info is None:
nzo_info = {}
if __NZBQ: __NZBQ.insert_future(future_nzo, filename, msgid, data, pp=pp, script=script, cat=cat, priority=priority, nzbname=nzbname, nzo_info=nzo_info) if __NZBQ: __NZBQ.insert_future(future_nzo, filename, msgid, data, pp=pp, script=script, cat=cat, priority=priority, nzbname=nzbname, nzo_info=nzo_info)
@synchronized_CV @synchronized_CV
@ -915,7 +917,7 @@ def get_nzo(nzo_id):
@synchronized_CV @synchronized_CV
def set_priority_multiple(nzo_ids, priority): def set_priority_multiple(nzo_ids, priority):
global __NZBQ global __NZBQ
if __NZBQ: __NZBQ.set_priority_multiple(nzo_ids, priority) if __NZBQ: return __NZBQ.set_priority_multiple(nzo_ids, priority)
@synchronized_CV @synchronized_CV
def sort_queue(field, reverse=False): def sort_queue(field, reverse=False):

2
main/sabnzbd/nzbstuff.py

@ -907,8 +907,6 @@ class NzbObject(TryList):
return None return None
def purge_data(self): def purge_data(self):
nzf_ids = []
for nzf in self.__files: for nzf in self.__files:
sabnzbd.remove_data(nzf.nzf_id) sabnzbd.remove_data(nzf.nzf_id)

21
main/sabnzbd/postproc.py

@ -27,17 +27,14 @@ import sabnzbd
import urllib import urllib
import time import time
import re import re
from xml.sax.saxutils import escape
import subprocess
from sabnzbd.decorators import synchronized
from sabnzbd.newsunpack import unpack_magic, par2_repair, external_processing from sabnzbd.newsunpack import unpack_magic, par2_repair, external_processing
from threading import Thread, RLock from threading import Thread
from sabnzbd.misc import real_path, get_unique_path, create_dirs, move_to_path, \ from sabnzbd.misc import real_path, get_unique_path, create_dirs, move_to_path, \
get_unique_filename, \ get_unique_filename, \
on_cleanup_list on_cleanup_list
from sabnzbd.tvsort import Sorter from sabnzbd.tvsort import Sorter
from sabnzbd.constants import TOP_PRIORITY, DB_HISTORY_NAME, POSTPROC_QUEUE_FILE_NAME, \ from sabnzbd.constants import TOP_PRIORITY, POSTPROC_QUEUE_FILE_NAME, \
POSTPROC_QUEUE_VERSION, sample_match POSTPROC_QUEUE_VERSION, sample_match
from sabnzbd.codecs import TRANS, unicoder from sabnzbd.codecs import TRANS, unicoder
import sabnzbd.newzbin import sabnzbd.newzbin
@ -539,13 +536,13 @@ def Cat2Dir(cat, defdir):
def addPrefixes(path,nzo): def addPrefixes(path,nzo):
dirprefix = nzo.get_dirprefix() dirprefix = nzo.get_dirprefix()
for _dir in dirprefix: for _dir in dirprefix:
if not _dir: if not _dir:
continue continue
if not path: if not path:
break break
basepath = os.path.basename(os.path.abspath(path)) basepath = os.path.basename(os.path.abspath(path))
if _dir != basepath.lower(): if _dir != basepath.lower():
path = os.path.join(path, _dir) path = os.path.join(path, _dir)
return path return path

4
main/sabnzbd/scheduler.py

@ -32,7 +32,7 @@ import sabnzbd.downloader
import sabnzbd.misc import sabnzbd.misc
import sabnzbd.config as config import sabnzbd.config as config
import sabnzbd.cfg as cfg import sabnzbd.cfg as cfg
from sabnzbd.lang import T, Ta from sabnzbd.lang import Ta
__SCHED = None # Global pointer to Scheduler instance __SCHED = None # Global pointer to Scheduler instance
@ -295,7 +295,7 @@ def scheduled_resume():
""" """
global __PAUSE_END global __PAUSE_END
if __PAUSE_END is None: if __PAUSE_END is None:
sabnzbd.unpause_all() sabnzbd.unpause_all()
def __oneshot_resume(when): def __oneshot_resume(when):

2
main/sabnzbd/tvsort.py

@ -31,7 +31,7 @@ from sabnzbd.misc import move_to_path, cleanup_empty_directories, get_unique_fil
from sabnzbd.constants import series_match, date_match, year_match, sample_match from sabnzbd.constants import series_match, date_match, year_match, sample_match
import sabnzbd.cfg as cfg import sabnzbd.cfg as cfg
from sabnzbd.codecs import titler from sabnzbd.codecs import titler
from sabnzbd.lang import T, Ta from sabnzbd.lang import Ta
RE_SAMPLE = re.compile(sample_match, re.I) RE_SAMPLE = re.compile(sample_match, re.I)
# Do not rename .vob files as they are usually DVD's # Do not rename .vob files as they are usually DVD's

4
main/sabnzbd/urlgrabber.py

@ -20,13 +20,11 @@ sabnzbd.urlgrabber - Queue for grabbing NZB files from websites
""" """
import os import os
import sys
import time import time
import re import re
import logging import logging
import Queue import Queue
import urllib, urllib2 import urllib, urllib2
import cookielib
import tempfile import tempfile
from threading import * from threading import *
@ -42,7 +40,7 @@ import sabnzbd.misc as misc
import sabnzbd.dirscanner as dirscanner import sabnzbd.dirscanner as dirscanner
import sabnzbd.nzbqueue as nzbqueue import sabnzbd.nzbqueue as nzbqueue
import sabnzbd.cfg as cfg import sabnzbd.cfg as cfg
from sabnzbd.lang import T, Ta from sabnzbd.lang import Ta
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Wrapper functions # Wrapper functions

2
main/sabnzbd/wizard.py

@ -21,14 +21,12 @@ sabnzbd.wizard - Wizard Webinterface
import os import os
import cherrypy import cherrypy
import logging
from Cheetah.Template import Template from Cheetah.Template import Template
import sabnzbd import sabnzbd
from sabnzbd.constants import * from sabnzbd.constants import *
from sabnzbd.lang import T, list_languages, reset_language from sabnzbd.lang import T, list_languages, reset_language
from sabnzbd.utils.servertests import test_nntp_server_dict from sabnzbd.utils.servertests import test_nntp_server_dict
from sabnzbd.misc import IntConv
import sabnzbd.interface import sabnzbd.interface
import sabnzbd.config as config import sabnzbd.config as config
import sabnzbd.cfg as cfg import sabnzbd.cfg as cfg

Loading…
Cancel
Save