From db5ff8c7e1433976f0429600e2d26e1af94b5910 Mon Sep 17 00:00:00 2001 From: Safihre Date: Sun, 14 Jun 2020 10:21:22 +0200 Subject: [PATCH] Code-formatting: optimize imports --- SABnzbd.py | 50 ++++++++++----------- sabnzbd/__init__.py | 25 +++++------ sabnzbd/api.py | 48 ++++++++++----------- sabnzbd/articlecache.py | 5 +-- sabnzbd/assembler.py | 14 +++--- sabnzbd/bpsmeter.py | 4 +- sabnzbd/cfg.py | 21 +++++---- sabnzbd/config.py | 10 +++-- sabnzbd/database.py | 12 +++--- sabnzbd/decoder.py | 8 ++-- sabnzbd/directunpacker.py | 14 +++--- sabnzbd/dirscanner.py | 10 ++--- sabnzbd/downloader.py | 21 +++++---- sabnzbd/emailer.py | 10 ++--- sabnzbd/encoding.py | 2 +- sabnzbd/filesystem.py | 10 ++--- sabnzbd/getipaddress.py | 6 +-- sabnzbd/interface.py | 79 +++++++++++++++++----------------- sabnzbd/lang.py | 4 +- sabnzbd/misc.py | 20 ++++----- sabnzbd/newsunpack.py | 16 +++---- sabnzbd/newswrapper.py | 10 ++--- sabnzbd/notifier.py | 8 ++-- sabnzbd/nzbparser.py | 6 +-- sabnzbd/nzbqueue.py | 29 ++++++------- sabnzbd/nzbstuff.py | 46 ++++++++++---------- sabnzbd/osxmenu.py | 30 ++++++------- sabnzbd/panic.py | 4 +- sabnzbd/par2file.py | 5 ++- sabnzbd/postproc.py | 72 +++++++++++++++---------------- sabnzbd/powersup.py | 3 +- sabnzbd/rating.py | 12 +++--- sabnzbd/rss.py | 16 +++---- sabnzbd/sabtray.py | 6 +-- sabnzbd/sabtraylinux.py | 3 +- sabnzbd/scheduler.py | 15 +++---- sabnzbd/sorting.py | 6 +-- sabnzbd/urlgrabber.py | 19 ++++---- sabnzbd/utils/certgen.py | 7 +-- sabnzbd/utils/checkdir.py | 2 +- sabnzbd/utils/diskspeed.py | 2 +- sabnzbd/utils/getperformance.py | 3 +- sabnzbd/utils/happyeyeballs.py | 4 +- sabnzbd/utils/internetspeed.py | 2 +- sabnzbd/utils/pathbrowser.py | 1 + sabnzbd/utils/servertests.py | 6 +-- sabnzbd/utils/systrayiconthread.py | 3 +- sabnzbd/zconfig.py | 2 +- tests/conftest.py | 2 - tests/sabnews.py | 7 +-- tests/test_filesystem.py | 6 +-- tests/test_functional_downloads.py | 1 - tests/test_functional_misc.py | 2 - tests/test_postproc.py | 3 +- tests/test_urlgrabber.py | 6 +-- tests/test_utils/test_happyeyeballs.py | 1 + tests/test_utils/test_sleepless.py | 5 ++- tests/test_win_utils.py | 1 + tests/testhelper.py | 4 +- tools/extract_pot.py | 2 +- tools/make_mo.py | 4 +- 61 files changed, 377 insertions(+), 378 deletions(-) diff --git a/SABnzbd.py b/SABnzbd.py index 3241500..3bb3648 100755 --- a/SABnzbd.py +++ b/SABnzbd.py @@ -15,36 +15,36 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -import sys - -if sys.hexversion < 0x03050000: - print("Sorry, requires Python 3.5 or above") - print("You can read more at: https://sabnzbd.org/python3") - sys.exit(1) - +import getopt import logging import logging.handlers -import traceback -import getopt +import platform +import re import signal import socket -import platform -import subprocess import ssl +import subprocess +import sys import time -import re +import traceback + +if sys.hexversion < 0x03050000: + print("Sorry, requires Python 3.5 or above") + print("You can read more at: https://sabnzbd.org/python3") + sys.exit(1) try: import Cheetah if Cheetah.Version[0] != "3": raise ValueError - import feedparser - import configobj + import cherrypy - import portend - import cryptography import chardet + import configobj + import cryptography + import feedparser + import portend except ValueError: print("Sorry, requires Python module Cheetah 3 or higher.") sys.exit(1) @@ -56,10 +56,17 @@ except ImportError as e: sys.exit(1) import sabnzbd -import sabnzbd.lang +import sabnzbd.cfg +import sabnzbd.config as config +import sabnzbd.downloader import sabnzbd.interface -from sabnzbd.constants import * +import sabnzbd.lang import sabnzbd.newsunpack +import sabnzbd.notifier as notifier +import sabnzbd.scheduler as scheduler +import sabnzbd.zconfig +from sabnzbd.constants import * +from sabnzbd.filesystem import get_ext, real_path, long_path, globber_full, remove_file from sabnzbd.misc import ( check_latest_version, exit_sab, @@ -72,14 +79,7 @@ from sabnzbd.misc import ( get_from_url, upload_file_to_sabnzbd, ) -from sabnzbd.filesystem import get_ext, real_path, long_path, globber_full, remove_file from sabnzbd.panic import panic_tmpl, panic_port, panic_host, panic, launch_a_browser -import sabnzbd.scheduler as scheduler -import sabnzbd.config as config -import sabnzbd.cfg -import sabnzbd.downloader -import sabnzbd.notifier as notifier -import sabnzbd.zconfig try: import win32api diff --git a/sabnzbd/__init__.py b/sabnzbd/__init__.py index 4a2d19d..0a2bf3a 100644 --- a/sabnzbd/__init__.py +++ b/sabnzbd/__init__.py @@ -15,24 +15,25 @@ # 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 -import logging import datetime -import tempfile -import pickle import gzip -import subprocess -import time -import socket -import cherrypy -import sys +import logging +import os +import pickle import re +import socket import ssl +import subprocess +import sys +import tempfile +import time from threading import Lock, Thread +import cherrypy + +# Imported to be referenced from other files directly +from sabnzbd.version import __version__, __baseline__ + ############################################################################## # Determine platform flags ############################################################################## diff --git a/sabnzbd/api.py b/sabnzbd/api.py index 9ec5cb9..4a366d5 100644 --- a/sabnzbd/api.py +++ b/sabnzbd/api.py @@ -19,15 +19,13 @@ sabnzbd.api - api """ -import os -import logging -import re import datetime -import time import json -import cherrypy import locale - +import logging +import os +import re +import time from threading import Thread try: @@ -36,7 +34,17 @@ try: except ImportError: pass +import cherrypy + import sabnzbd +import sabnzbd.cfg as cfg +import sabnzbd.config as config +import sabnzbd.emailer +import sabnzbd.notifier +import sabnzbd.rss +import sabnzbd.scheduler as scheduler +from sabnzbd.articlecache import ArticleCache +from sabnzbd.bpsmeter import BPSMeter from sabnzbd.constants import ( VALID_ARCHIVES, VALID_NZB_FILES, @@ -50,14 +58,11 @@ from sabnzbd.constants import ( MEBI, GIGI, ) -import sabnzbd.config as config -import sabnzbd.cfg as cfg +from sabnzbd.database import build_history_info, unpack_history_info, HistoryDB from sabnzbd.downloader import Downloader -from sabnzbd.nzbqueue import NzbQueue -import sabnzbd.scheduler as scheduler -from sabnzbd.skintext import SKIN_TEXT -from sabnzbd.utils.pathbrowser import folders_at_path -from sabnzbd.utils.getperformance import getcpu +from sabnzbd.encoding import xml_name +from sabnzbd.filesystem import diskspace, get_ext, globber_full, clip_path, remove_all +from sabnzbd.getipaddress import localipv4, publicipv4, ipv6, addresslookup from sabnzbd.misc import ( loadavg, to_units, @@ -68,19 +73,14 @@ from sabnzbd.misc import ( calc_age, opts_to_pp, ) -from sabnzbd.filesystem import diskspace, get_ext, globber_full, clip_path, remove_all -from sabnzbd.encoding import xml_name +from sabnzbd.newsunpack import userxbit +from sabnzbd.nzbqueue import NzbQueue from sabnzbd.postproc import PostProcessor -from sabnzbd.articlecache import ArticleCache -from sabnzbd.utils.servertests import test_nntp_server_dict -from sabnzbd.bpsmeter import BPSMeter from sabnzbd.rating import Rating -from sabnzbd.getipaddress import localipv4, publicipv4, ipv6, addresslookup -from sabnzbd.newsunpack import userxbit -from sabnzbd.database import build_history_info, unpack_history_info, HistoryDB -import sabnzbd.notifier -import sabnzbd.rss -import sabnzbd.emailer +from sabnzbd.skintext import SKIN_TEXT +from sabnzbd.utils.getperformance import getcpu +from sabnzbd.utils.pathbrowser import folders_at_path +from sabnzbd.utils.servertests import test_nntp_server_dict ############################################################################## # API error messages diff --git a/sabnzbd/articlecache.py b/sabnzbd/articlecache.py index d79ad08..85ebfcf 100644 --- a/sabnzbd/articlecache.py +++ b/sabnzbd/articlecache.py @@ -19,13 +19,12 @@ sabnzbd.articlecache - Article cache handling """ -import logging -import threading import struct +import threading import sabnzbd -from sabnzbd.decorators import synchronized from sabnzbd.constants import GIGI, ANFO, MEBI, LIMIT_DECODE_QUEUE, MIN_DECODE_QUEUE +from sabnzbd.decorators import synchronized # Operations on lists and dicts are atomic, but for # the bytes counter we do need a lock diff --git a/sabnzbd/assembler.py b/sabnzbd/assembler.py index fdcf247..58b104b 100644 --- a/sabnzbd/assembler.py +++ b/sabnzbd/assembler.py @@ -19,24 +19,24 @@ sabnzbd.assembler - threaded assembly/decoding of files """ +import hashlib +import logging import os import queue -import logging import re from threading import Thread from time import sleep -import hashlib import sabnzbd -from sabnzbd.misc import get_all_passwords -from sabnzbd.filesystem import set_permissions, clip_path, has_win_device, diskspace, get_filename, get_ext -from sabnzbd.constants import Status, GIGI, MAX_ASSEMBLER_QUEUE import sabnzbd.cfg as cfg -from sabnzbd.articlecache import ArticleCache -from sabnzbd.postproc import PostProcessor import sabnzbd.downloader import sabnzbd.par2file as par2file import sabnzbd.utils.rarfile as rarfile +from sabnzbd.articlecache import ArticleCache +from sabnzbd.constants import Status, GIGI, MAX_ASSEMBLER_QUEUE +from sabnzbd.filesystem import set_permissions, clip_path, has_win_device, diskspace, get_filename, get_ext +from sabnzbd.misc import get_all_passwords +from sabnzbd.postproc import PostProcessor from sabnzbd.rating import Rating diff --git a/sabnzbd/bpsmeter.py b/sabnzbd/bpsmeter.py index 5dd10e9..af452bd 100644 --- a/sabnzbd/bpsmeter.py +++ b/sabnzbd/bpsmeter.py @@ -19,13 +19,13 @@ sabnzbd.bpsmeter - bpsmeter """ -import time import logging import re +import time import sabnzbd -from sabnzbd.constants import BYTES_FILE_NAME, KIBI import sabnzbd.cfg as cfg +from sabnzbd.constants import BYTES_FILE_NAME, KIBI DAY = float(24 * 60 * 60) WEEK = DAY * 7 diff --git a/sabnzbd/cfg.py b/sabnzbd/cfg.py index 65d35fa..d1f0f9c 100644 --- a/sabnzbd/cfg.py +++ b/sabnzbd/cfg.py @@ -21,17 +21,6 @@ sabnzbd.cfg - Configuration Parameters import re import sabnzbd -from sabnzbd.constants import ( - DEF_HOST, - DEF_PORT, - DEF_STDINTF, - DEF_ADMIN_DIR, - DEF_DOWNLOAD_DIR, - DEF_NZBBACK_DIR, - DEF_SCANRATE, - DEF_COMPLETE_DIR, -) - from sabnzbd.config import ( OptionBool, OptionNumber, @@ -46,6 +35,16 @@ from sabnzbd.config import ( create_api_key, validate_notempty, ) +from sabnzbd.constants import ( + DEF_HOST, + DEF_PORT, + DEF_STDINTF, + DEF_ADMIN_DIR, + DEF_DOWNLOAD_DIR, + DEF_NZBBACK_DIR, + DEF_SCANRATE, + DEF_COMPLETE_DIR, +) ############################################################################## # Email validation support diff --git a/sabnzbd/config.py b/sabnzbd/config.py index 311472f..2cdd236 100644 --- a/sabnzbd/config.py +++ b/sabnzbd/config.py @@ -19,18 +19,20 @@ sabnzbd.config - Configuration Support """ +import logging import os import re -import logging -import threading import shutil +import threading import uuid from urllib.parse import urlparse + +import configobj + import sabnzbd.misc -from sabnzbd.filesystem import clip_path, real_path, create_real_path, renamer, remove_file, is_writable from sabnzbd.constants import CONFIG_VERSION, NORMAL_PRIORITY, DEFAULT_PRIORITY, MAX_WIN_DFOLDER -import configobj from sabnzbd.decorators import synchronized +from sabnzbd.filesystem import clip_path, real_path, create_real_path, renamer, remove_file, is_writable CONFIG_LOCK = threading.Lock() SAVE_CONFIG_LOCK = threading.Lock() diff --git a/sabnzbd/database.py b/sabnzbd/database.py index 0ab0ac2..84d7928 100644 --- a/sabnzbd/database.py +++ b/sabnzbd/database.py @@ -19,22 +19,22 @@ sabnzbd.database - Database Support """ -import os -import time -import zlib import logging +import os +import sqlite3 import sys import threading -import sqlite3 +import time +import zlib import sabnzbd import sabnzbd.cfg -from sabnzbd.constants import DB_HISTORY_NAME, STAGES, Status from sabnzbd.bpsmeter import this_week, this_month +from sabnzbd.constants import DB_HISTORY_NAME, STAGES, Status from sabnzbd.decorators import synchronized from sabnzbd.encoding import ubtou, utob -from sabnzbd.misc import int_conv, caller_name, opts_to_pp from sabnzbd.filesystem import remove_file +from sabnzbd.misc import int_conv, caller_name, opts_to_pp DB_LOCK = threading.RLock() diff --git a/sabnzbd/decoder.py b/sabnzbd/decoder.py index 7c53bd9..0d6b270 100644 --- a/sabnzbd/decoder.py +++ b/sabnzbd/decoder.py @@ -19,18 +19,18 @@ sabnzbd.decoder - article decoder """ -import logging import hashlib +import logging import queue from threading import Thread import sabnzbd -from sabnzbd.constants import SABYENC_VERSION_REQUIRED +import sabnzbd.cfg as cfg from sabnzbd.articlecache import ArticleCache +from sabnzbd.constants import SABYENC_VERSION_REQUIRED from sabnzbd.downloader import Downloader -from sabnzbd.nzbqueue import NzbQueue -import sabnzbd.cfg as cfg from sabnzbd.misc import match_str +from sabnzbd.nzbqueue import NzbQueue # Check for correct SABYenc version SABYENC_VERSION = None diff --git a/sabnzbd/directunpacker.py b/sabnzbd/directunpacker.py index e98b71a..f076681 100644 --- a/sabnzbd/directunpacker.py +++ b/sabnzbd/directunpacker.py @@ -19,24 +19,24 @@ sabnzbd.directunpacker """ +import logging import os import re -import time -import threading import subprocess -import logging +import threading +import time from subprocess import Popen import sabnzbd import sabnzbd.cfg as cfg -from sabnzbd.misc import int_conv, format_time_string -from sabnzbd.filesystem import clip_path, long_path, remove_all, real_path, remove_file -from sabnzbd.encoding import platform_btou from sabnzbd.decorators import synchronized +from sabnzbd.encoding import platform_btou +from sabnzbd.filesystem import clip_path, long_path, remove_all, real_path, remove_file +from sabnzbd.misc import int_conv, format_time_string from sabnzbd.newsunpack import build_command, EXTRACTFROM_RE, EXTRACTED_RE, rar_volumelist from sabnzbd.postproc import prepare_extraction_path -from sabnzbd.utils.rarfile import RarFile from sabnzbd.utils.diskspeed import diskspeedmeasure +from sabnzbd.utils.rarfile import RarFile # Need a lock to make sure start and stop is handled correctly # Otherwise we could stop while the thread was still starting diff --git a/sabnzbd/dirscanner.py b/sabnzbd/dirscanner.py index 3e55be1..b11fac0 100644 --- a/sabnzbd/dirscanner.py +++ b/sabnzbd/dirscanner.py @@ -19,16 +19,16 @@ sabnzbd.dirscanner - Scanner for Watched Folder """ -import os -import time import logging +import os import threading +import time import sabnzbd -from sabnzbd.constants import SCAN_FILE_NAME, VALID_ARCHIVES, VALID_NZB_FILES -import sabnzbd.filesystem as filesystem -import sabnzbd.config as config import sabnzbd.cfg as cfg +import sabnzbd.config as config +import sabnzbd.filesystem as filesystem +from sabnzbd.constants import SCAN_FILE_NAME, VALID_ARCHIVES, VALID_NZB_FILES def compare_stat_tuple(tup1, tup2): diff --git a/sabnzbd/downloader.py b/sabnzbd/downloader.py index ff61787..0cc869c 100644 --- a/sabnzbd/downloader.py +++ b/sabnzbd/downloader.py @@ -19,27 +19,26 @@ sabnzbd.downloader - download engine """ -import time -import select import logging -from threading import Thread, RLock -from nntplib import NNTPPermanentError -import socket import random +import select +import socket import sys +import time +from nntplib import NNTPPermanentError +from threading import Thread, RLock import sabnzbd -from sabnzbd.decorators import synchronized, NzbQueueLocker, DOWNLOADER_CV -from sabnzbd.newswrapper import NewsWrapper, request_server_info -import sabnzbd.notifier as notifier -import sabnzbd.config as config import sabnzbd.cfg as cfg -from sabnzbd.bpsmeter import BPSMeter +import sabnzbd.config as config +import sabnzbd.notifier as notifier import sabnzbd.scheduler +from sabnzbd.bpsmeter import BPSMeter +from sabnzbd.decorators import synchronized, NzbQueueLocker, DOWNLOADER_CV from sabnzbd.misc import from_units, nntp_to_msg, int_conv +from sabnzbd.newswrapper import NewsWrapper, request_server_info from sabnzbd.utils.happyeyeballs import happyeyeballs - # Timeout penalty in minutes for each cause _PENALTY_UNKNOWN = 3 # Unknown cause _PENALTY_502 = 5 # Unknown 502 diff --git a/sabnzbd/emailer.py b/sabnzbd/emailer.py index 1a92861..e958bf0 100644 --- a/sabnzbd/emailer.py +++ b/sabnzbd/emailer.py @@ -19,20 +19,20 @@ sabnzbd.emailer - Send notification emails """ -import smtplib +import glob import logging import re +import smtplib import time -import glob +from email.message import EmailMessage from Cheetah.Template import Template -from email.message import EmailMessage -from sabnzbd.constants import * import sabnzbd +import sabnzbd.cfg as cfg +from sabnzbd.constants import * from sabnzbd.misc import to_units, split_host, time_format from sabnzbd.notifier import check_cat -import sabnzbd.cfg as cfg RE_HEADER = re.compile(r"^([^:]+):(.*)") diff --git a/sabnzbd/encoding.py b/sabnzbd/encoding.py index df31003..77363ad 100644 --- a/sabnzbd/encoding.py +++ b/sabnzbd/encoding.py @@ -20,9 +20,9 @@ sabnzbd.encoding - Unicode/byte translation functions """ import locale -import chardet from xml.sax.saxutils import escape +import chardet CODEPAGE = locale.getpreferredencoding() diff --git a/sabnzbd/filesystem.py b/sabnzbd/filesystem.py index 2043171..8e8c423 100644 --- a/sabnzbd/filesystem.py +++ b/sabnzbd/filesystem.py @@ -19,20 +19,20 @@ sabnzbd.misc - filesystem operations """ -import os -import sys +import fnmatch import logging +import os import re import shutil +import stat +import sys import threading import time -import fnmatch -import stat import zipfile import sabnzbd -from sabnzbd.decorators import synchronized from sabnzbd.constants import FUTURE_Q_FOLDER, JOB_ADMIN, GIGI +from sabnzbd.decorators import synchronized from sabnzbd.encoding import correct_unknown_encoding from sabnzbd.utils import rarfile diff --git a/sabnzbd/getipaddress.py b/sabnzbd/getipaddress.py index 6a148f9..f877496 100644 --- a/sabnzbd/getipaddress.py +++ b/sabnzbd/getipaddress.py @@ -19,11 +19,11 @@ sabnzbd.getipaddress """ -import socket -import multiprocessing.pool import functools -import urllib.request +import multiprocessing.pool +import socket import urllib.error +import urllib.request import sabnzbd import sabnzbd.cfg diff --git a/sabnzbd/interface.py b/sabnzbd/interface.py index 169d2fe..70f9f52 100644 --- a/sabnzbd/interface.py +++ b/sabnzbd/interface.py @@ -19,26 +19,54 @@ sabnzbd.interface - webinterface """ -import os -import time -from datetime import datetime -import cherrypy +import functools +import hashlib import logging -import urllib.request, urllib.parse, urllib.error +import os import re -import hashlib import socket import ssl -import functools -from threading import Thread +import time +import urllib.error +import urllib.parse +import urllib.request +from datetime import datetime from random import randint +from threading import Thread from xml.sax.saxutils import escape +import cherrypy +from Cheetah.Template import Template + import sabnzbd +import sabnzbd.cfg as cfg +import sabnzbd.config as config +import sabnzbd.newsunpack +import sabnzbd.notifier as notifier import sabnzbd.rss import sabnzbd.scheduler as scheduler - -from Cheetah.Template import Template +from sabnzbd.api import ( + list_scripts, + list_cats, + del_from_section, + api_handler, + build_queue, + build_status, + retry_job, + build_header, + build_history, + format_bytes, + del_hist_job, + Ttemplate, + build_queue_header, +) +from sabnzbd.bpsmeter import BPSMeter +from sabnzbd.constants import MEBI, DEF_SKIN_COLORS, DEF_STDCONFIG, DEF_MAIN_TMPL, DEFAULT_PRIORITY, CHEETAH_DIRECTIVES +from sabnzbd.decoder import SABYENC_ENABLED +from sabnzbd.downloader import Downloader +from sabnzbd.encoding import xml_name, utob +from sabnzbd.filesystem import real_path, long_path, globber, globber_full, remove_all, clip_path, same_file +from sabnzbd.lang import list_languages from sabnzbd.misc import ( to_units, from_units, @@ -50,42 +78,13 @@ from sabnzbd.misc import ( probablyipv6, opts_to_pp, ) -from sabnzbd.filesystem import real_path, long_path, globber, globber_full, remove_all, clip_path, same_file from sabnzbd.newswrapper import GetServerParms -from sabnzbd.bpsmeter import BPSMeter -from sabnzbd.encoding import xml_name, utob -import sabnzbd.config as config -import sabnzbd.cfg as cfg -import sabnzbd.notifier as notifier -import sabnzbd.newsunpack -from sabnzbd.downloader import Downloader from sabnzbd.nzbqueue import NzbQueue -from sabnzbd.utils.servertests import test_nntp_server_dict -from sabnzbd.decoder import SABYENC_ENABLED from sabnzbd.utils.diskspeed import diskspeedmeasure from sabnzbd.utils.getperformance import getpystone from sabnzbd.utils.internetspeed import internetspeed +from sabnzbd.utils.servertests import test_nntp_server_dict -from sabnzbd.constants import MEBI, DEF_SKIN_COLORS, DEF_STDCONFIG, DEF_MAIN_TMPL, DEFAULT_PRIORITY, CHEETAH_DIRECTIVES - -from sabnzbd.lang import list_languages - -from sabnzbd.api import ( - list_scripts, - list_cats, - del_from_section, - api_handler, - build_queue, - build_status, - retry_job, - build_header, - build_history, - format_bytes, - report, - del_hist_job, - Ttemplate, - build_queue_header, -) ############################################################################## # Global constants diff --git a/sabnzbd/lang.py b/sabnzbd/lang.py index aac3296..263cbba 100644 --- a/sabnzbd/lang.py +++ b/sabnzbd/lang.py @@ -32,11 +32,11 @@ sabnzbd.lang - Language support # T() Unicode translation # TT() Dummy translation, use to mark table entries for POT scanning -import gettext import builtins +import gettext import glob -import os import locale +import os __all__ = ["set_locale_info", "set_language", "list_languages"] diff --git a/sabnzbd/misc.py b/sabnzbd/misc.py index ca76667..e040c56 100644 --- a/sabnzbd/misc.py +++ b/sabnzbd/misc.py @@ -18,23 +18,23 @@ """ sabnzbd.misc - misc classes """ -import os -import sys +import ctypes +import datetime +import inspect import logging -import urllib.request -import urllib.parse +import os import re -import subprocess import socket +import subprocess +import sys import time -import datetime -import inspect -import ctypes +import urllib.parse +import urllib.request import sabnzbd -from sabnzbd.constants import DEFAULT_PRIORITY, MEBI, DEF_ARTICLE_CACHE_DEFAULT, DEF_ARTICLE_CACHE_MAX -import sabnzbd.config as config import sabnzbd.cfg as cfg +import sabnzbd.config as config +from sabnzbd.constants import DEFAULT_PRIORITY, MEBI, DEF_ARTICLE_CACHE_DEFAULT, DEF_ARTICLE_CACHE_MAX from sabnzbd.encoding import ubtou, platform_btou TAB_UNITS = ("", "K", "M", "G", "T", "P") diff --git a/sabnzbd/newsunpack.py b/sabnzbd/newsunpack.py index 100a2dd..80ad7d8 100644 --- a/sabnzbd/newsunpack.py +++ b/sabnzbd/newsunpack.py @@ -19,21 +19,22 @@ sabnzbd.newsunpack """ +import functools +import logging import os -import sys import re +import shutil import subprocess -import logging +import sys import time import zlib -import shutil -import functools from subprocess import Popen import sabnzbd -from sabnzbd.encoding import platform_btou, correct_unknown_encoding, ubtou +import sabnzbd.cfg as cfg import sabnzbd.utils.rarfile as rarfile -from sabnzbd.misc import format_time_string, find_on_path, int_conv, get_all_passwords, calc_age, cmp, caller_name +from sabnzbd.constants import Status +from sabnzbd.encoding import platform_btou, correct_unknown_encoding, ubtou from sabnzbd.filesystem import ( make_script_path, real_path, @@ -48,9 +49,8 @@ from sabnzbd.filesystem import ( get_ext, get_filename, ) +from sabnzbd.misc import format_time_string, find_on_path, int_conv, get_all_passwords, calc_age, cmp, caller_name from sabnzbd.sorting import SeriesSorter -import sabnzbd.cfg as cfg -from sabnzbd.constants import Status if sabnzbd.WIN32: try: diff --git a/sabnzbd/newswrapper.py b/sabnzbd/newswrapper.py index fcbe707..b39b7e1 100644 --- a/sabnzbd/newswrapper.py +++ b/sabnzbd/newswrapper.py @@ -20,17 +20,17 @@ sabnzbd.newswrapper """ import errno -import socket -from threading import Thread -from nntplib import NNTPPermanentError -import time import logging +import socket import ssl +import time +from nntplib import NNTPPermanentError +from threading import Thread import sabnzbd +import sabnzbd.cfg from sabnzbd.constants import * from sabnzbd.encoding import utob -import sabnzbd.cfg from sabnzbd.misc import nntp_to_msg, probablyipv4, probablyipv6 # Set pre-defined socket timeout diff --git a/sabnzbd/notifier.py b/sabnzbd/notifier.py index d259250..8caab03 100644 --- a/sabnzbd/notifier.py +++ b/sabnzbd/notifier.py @@ -21,11 +21,13 @@ sabnzbd.notifier - Send notifications to any notification services """ -import os.path -import logging -import urllib.request, urllib.error, urllib.parse import http.client import json +import logging +import os.path +import urllib.error +import urllib.parse +import urllib.request from threading import Thread import sabnzbd diff --git a/sabnzbd/nzbparser.py b/sabnzbd/nzbparser.py index ef44499..ffcc76e 100644 --- a/sabnzbd/nzbparser.py +++ b/sabnzbd/nzbparser.py @@ -19,12 +19,12 @@ sabnzbd.nzbparser - Parse and import NZB files """ import bz2 +import datetime import gzip -import time -import logging import hashlib +import logging +import time import xml.etree.ElementTree -import datetime import sabnzbd from sabnzbd import filesystem, nzbstuff diff --git a/sabnzbd/nzbqueue.py b/sabnzbd/nzbqueue.py index 19dbde1..847544e 100644 --- a/sabnzbd/nzbqueue.py +++ b/sabnzbd/nzbqueue.py @@ -19,20 +19,19 @@ sabnzbd.nzbqueue - nzb queue """ -import os -import logging -import time import datetime import functools +import logging +import os +import time import sabnzbd -from sabnzbd.nzbstuff import NzbObject -from sabnzbd.misc import exit_sab, cat_to_opts, int_conv, caller_name, cmp, safe_lower -from sabnzbd.filesystem import get_admin_path, remove_all, globber_full, remove_file -from sabnzbd.nzbparser import process_single_nzb -from sabnzbd.panic import panic_queue +import sabnzbd.cfg as cfg import sabnzbd.database as database -from sabnzbd.decorators import NzbQueueLocker +import sabnzbd.downloader +import sabnzbd.notifier as notifier +from sabnzbd.assembler import Assembler, file_has_articles +from sabnzbd.bpsmeter import BPSMeter from sabnzbd.constants import ( QUEUE_FILE_NAME, QUEUE_VERSION, @@ -50,12 +49,12 @@ from sabnzbd.constants import ( QNFO, DIRECT_WRITE_TRIGGER, ) - -import sabnzbd.cfg as cfg -import sabnzbd.downloader -from sabnzbd.assembler import Assembler, file_has_articles -import sabnzbd.notifier as notifier -from sabnzbd.bpsmeter import BPSMeter +from sabnzbd.decorators import NzbQueueLocker +from sabnzbd.filesystem import get_admin_path, remove_all, globber_full, remove_file +from sabnzbd.misc import exit_sab, cat_to_opts, int_conv, caller_name, cmp, safe_lower +from sabnzbd.nzbparser import process_single_nzb +from sabnzbd.nzbstuff import NzbObject +from sabnzbd.panic import panic_queue class NzbQueue: diff --git a/sabnzbd/nzbstuff.py b/sabnzbd/nzbstuff.py index 0745d30..390dcda 100644 --- a/sabnzbd/nzbstuff.py +++ b/sabnzbd/nzbstuff.py @@ -19,17 +19,21 @@ sabnzbd.nzbstuff - misc """ +import datetime +import difflib +import functools +import logging import os -import time import re -import logging -import datetime import threading -import functools -import difflib +import time # SABnzbd modules import sabnzbd +import sabnzbd.cfg as cfg +import sabnzbd.config as config +import sabnzbd.nzbparser +from sabnzbd.articlecache import ArticleCache from sabnzbd.constants import ( GIGI, ATTRIB_FILE, @@ -48,18 +52,8 @@ from sabnzbd.constants import ( Status, PNFO, ) -from sabnzbd.misc import ( - to_units, - cat_to_opts, - cat_convert, - int_conv, - format_time_string, - calc_age, - cmp, - caller_name, - opts_to_pp, - pp_to_opts, -) +from sabnzbd.database import HistoryDB +from sabnzbd.decorators import synchronized from sabnzbd.filesystem import ( sanitize_foldername, get_unique_path, @@ -79,12 +73,18 @@ from sabnzbd.filesystem import ( get_filepath, listdir_full, ) -from sabnzbd.decorators import synchronized -import sabnzbd.config as config -import sabnzbd.cfg as cfg -import sabnzbd.nzbparser -from sabnzbd.database import HistoryDB -from sabnzbd.articlecache import ArticleCache +from sabnzbd.misc import ( + to_units, + cat_to_opts, + cat_convert, + int_conv, + format_time_string, + calc_age, + cmp, + caller_name, + opts_to_pp, + pp_to_opts, +) from sabnzbd.rating import Rating # Name patterns diff --git a/sabnzbd/osxmenu.py b/sabnzbd/osxmenu.py index b7a4640..d288064 100644 --- a/sabnzbd/osxmenu.py +++ b/sabnzbd/osxmenu.py @@ -19,33 +19,29 @@ sabnzbd.osxmenu - OSX Top Menu """ -import objc -from Foundation import * -from AppKit import * -from PyObjCTools import AppHelper -from objc import YES, NO - +import logging import os import sys import time -import logging import cherrypy +from AppKit import * +from Foundation import * +from objc import YES, NO + import sabnzbd import sabnzbd.cfg - -from sabnzbd.filesystem import diskspace -from sabnzbd.misc import to_units -from sabnzbd.constants import VALID_ARCHIVES, VALID_NZB_FILES, MEBI, Status -from sabnzbd.panic import launch_a_browser -import sabnzbd.notifier as notifier - -from sabnzbd.api import fast_queue -from sabnzbd.nzbqueue import NzbQueue import sabnzbd.config as config -import sabnzbd.scheduler as scheduler import sabnzbd.downloader +import sabnzbd.notifier as notifier +import sabnzbd.scheduler as scheduler +from sabnzbd.api import fast_queue from sabnzbd.bpsmeter import BPSMeter +from sabnzbd.constants import VALID_ARCHIVES, VALID_NZB_FILES, MEBI, Status +from sabnzbd.filesystem import diskspace +from sabnzbd.misc import to_units +from sabnzbd.nzbqueue import NzbQueue +from sabnzbd.panic import launch_a_browser status_icons = { "idle": "icons/sabnzbd_osx_idle.tiff", diff --git a/sabnzbd/panic.py b/sabnzbd/panic.py index 51eea09..9073ee7 100644 --- a/sabnzbd/panic.py +++ b/sabnzbd/panic.py @@ -19,10 +19,10 @@ sabnzbd.panic - Send panic message to the browser """ -import os +import ctypes import logging +import os import tempfile -import ctypes try: import webbrowser diff --git a/sabnzbd/par2file.py b/sabnzbd/par2file.py index 3766e11..c3b0ec2 100644 --- a/sabnzbd/par2file.py +++ b/sabnzbd/par2file.py @@ -18,11 +18,12 @@ """ sabnzbd.par2file - All par2-related functionality """ -import os +import hashlib import logging +import os import re -import hashlib import struct + from sabnzbd.encoding import correct_unknown_encoding PROBABLY_PAR2_RE = re.compile(r"(.*)\.vol(\d*)[\+\-](\d*)\.par2", re.I) diff --git a/sabnzbd/postproc.py b/sabnzbd/postproc.py index 51f414f..4856e5c 100644 --- a/sabnzbd/postproc.py +++ b/sabnzbd/postproc.py @@ -19,25 +19,36 @@ sabnzbd.postproc - threaded post-processing of jobs """ -import os -import logging -import sabnzbd import functools -import time -import re +import logging +import os import queue +import re +import time +from threading import Thread -from sabnzbd.newsunpack import ( - unpack_magic, - par2_repair, - external_processing, - sfv_check, - build_filelists, - rar_sort, - is_sfv_file, +import sabnzbd +import sabnzbd.cfg as cfg +import sabnzbd.config as config +import sabnzbd.database as database +import sabnzbd.downloader +import sabnzbd.emailer as emailer +import sabnzbd.encoding as encoding +import sabnzbd.notifier as notifier +import sabnzbd.nzbqueue +import sabnzbd.utils.checkdir +import sabnzbd.utils.rarfile as rarfile +import sabnzbd.utils.rarvolinfo as rarvolinfo +from sabnzbd.constants import ( + REPAIR_PRIORITY, + TOP_PRIORITY, + POSTPROC_QUEUE_FILE_NAME, + POSTPROC_QUEUE_VERSION, + sample_match, + JOB_ADMIN, + Status, + VERIFIED_FILE, ) -from threading import Thread -from sabnzbd.misc import on_cleanup_list from sabnzbd.filesystem import ( real_path, get_unique_path, @@ -62,30 +73,19 @@ from sabnzbd.filesystem import ( get_ext, get_filename, ) -from sabnzbd.sorting 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.misc import on_cleanup_list +from sabnzbd.newsunpack import ( + unpack_magic, + par2_repair, + external_processing, + sfv_check, + build_filelists, + rar_sort, + is_sfv_file, ) from sabnzbd.nzbparser import process_single_nzb from sabnzbd.rating import Rating -import sabnzbd.emailer as emailer -import sabnzbd.downloader -import sabnzbd.config as config -import sabnzbd.cfg as cfg -import sabnzbd.encoding as encoding -import sabnzbd.nzbqueue -import sabnzbd.database as database -import sabnzbd.notifier as notifier -import sabnzbd.utils.rarfile as rarfile -import sabnzbd.utils.rarvolinfo as rarvolinfo -import sabnzbd.utils.checkdir +from sabnzbd.sorting import Sorter MAX_FAST_JOB_COUNT = 3 diff --git a/sabnzbd/powersup.py b/sabnzbd/powersup.py index 4228519..6c4112e 100644 --- a/sabnzbd/powersup.py +++ b/sabnzbd/powersup.py @@ -19,12 +19,11 @@ sabnzbd.powersup - System power management support """ +import logging import os import subprocess -import logging import time - ############################################################################## # Power management for Windows ############################################################################## diff --git a/sabnzbd/rating.py b/sabnzbd/rating.py index 67b80fe..4ff1af8 100644 --- a/sabnzbd/rating.py +++ b/sabnzbd/rating.py @@ -19,17 +19,19 @@ sabnzbd.rating - Rating support functions """ +import collections +import copy import http.client -import urllib.parse -import time import logging -import copy import queue -import collections +import time +import urllib.parse from threading import RLock, Thread + import sabnzbd -from sabnzbd.decorators import synchronized import sabnzbd.cfg as cfg +from sabnzbd.decorators import synchronized + # A queue which ignores duplicates but maintains ordering class OrderedSetQueue(queue.Queue): diff --git a/sabnzbd/rss.py b/sabnzbd/rss.py index 7d4e110..d85a9ea 100644 --- a/sabnzbd/rss.py +++ b/sabnzbd/rss.py @@ -19,21 +19,21 @@ sabnzbd.rss - rss client functionality """ -import re -import logging -import time import datetime +import logging +import re import threading +import time + +import feedparser import sabnzbd +import sabnzbd.cfg as cfg +import sabnzbd.config as config +import sabnzbd.emailer as emailer from sabnzbd.constants import RSS_FILE_NAME, DEFAULT_PRIORITY, NORMAL_PRIORITY, DUP_PRIORITY from sabnzbd.decorators import synchronized -import sabnzbd.config as config -import sabnzbd.cfg as cfg from sabnzbd.misc import cat_convert, wildcard_to_re, cat_to_opts, match_str, from_units, int_conv, get_base_url -import sabnzbd.emailer as emailer - -import feedparser __RSS = None # Global pointer to RSS-scanner instance diff --git a/sabnzbd/sabtray.py b/sabnzbd/sabtray.py index dec0bd4..65670ec 100644 --- a/sabnzbd/sabtray.py +++ b/sabnzbd/sabtray.py @@ -19,17 +19,17 @@ sabtray.py - Systray icon for SABnzbd on Windows, contributed by Jan Schejbal """ -import os import logging +import os from time import sleep import sabnzbd -from sabnzbd.panic import launch_a_browser import sabnzbd.api as api +import sabnzbd.cfg as cfg import sabnzbd.scheduler as scheduler from sabnzbd.downloader import Downloader -import sabnzbd.cfg as cfg from sabnzbd.misc import to_units +from sabnzbd.panic import launch_a_browser # contains the tray icon, which demands its own thread from sabnzbd.utils.systrayiconthread import SysTrayIconThread diff --git a/sabnzbd/sabtraylinux.py b/sabnzbd/sabtraylinux.py index 8a967c5..b17fd2c 100644 --- a/sabnzbd/sabtraylinux.py +++ b/sabnzbd/sabtraylinux.py @@ -19,9 +19,10 @@ sabnzbd.sabtraylinux - System tray icon for Linux, inspired from the Windows one """ +import logging + import gi from gi.repository import Gtk, GLib -import logging try: gi.require_version("XApp", "1.0") diff --git a/sabnzbd/scheduler.py b/sabnzbd/scheduler.py index 8e0c299..74ffaa7 100644 --- a/sabnzbd/scheduler.py +++ b/sabnzbd/scheduler.py @@ -19,20 +19,19 @@ sabnzbd.scheduler - Event Scheduler """ -import random import logging +import random import time -import sabnzbd.utils.kronos as kronos -import sabnzbd.rss as rss -import sabnzbd.downloader +import sabnzbd.cfg as cfg +import sabnzbd.config as config import sabnzbd.dirscanner +import sabnzbd.downloader import sabnzbd.misc -import sabnzbd.config as config -import sabnzbd.cfg as cfg -from sabnzbd.postproc import PostProcessor +import sabnzbd.rss as rss +import sabnzbd.utils.kronos as kronos from sabnzbd.constants import LOW_PRIORITY, NORMAL_PRIORITY, HIGH_PRIORITY - +from sabnzbd.postproc import PostProcessor __SCHED = None # Global pointer to Scheduler instance diff --git a/sabnzbd/sorting.py b/sabnzbd/sorting.py index a0cf583..a1eb776 100644 --- a/sabnzbd/sorting.py +++ b/sabnzbd/sorting.py @@ -22,11 +22,13 @@ Date Sorting - Sorting downloads by a custom date matching Generic Sorting - Sorting large files by a custom matching """ -import os import logging +import os import re import sabnzbd +import sabnzbd.cfg as cfg +from sabnzbd.constants import series_match, date_match, year_match, sample_match from sabnzbd.filesystem import ( move_to_path, cleanup_empty_directories, @@ -37,8 +39,6 @@ from sabnzbd.filesystem import ( sanitize_foldername, clip_path, ) -from sabnzbd.constants import series_match, date_match, year_match, sample_match -import sabnzbd.cfg as cfg RE_SAMPLE = re.compile(sample_match, re.I) # Do not rename .vob files as they are usually DVD's diff --git a/sabnzbd/urlgrabber.py b/sabnzbd/urlgrabber.py index 468b35b..13aabe6 100644 --- a/sabnzbd/urlgrabber.py +++ b/sabnzbd/urlgrabber.py @@ -19,29 +19,28 @@ sabnzbd.urlgrabber - Queue for grabbing NZB files from websites """ +import base64 +import logging import os +import queue import sys import time -import logging -import queue -import urllib.request import urllib.error import urllib.parse +import urllib.request from http.client import IncompleteRead from threading import Thread -import base64 import sabnzbd -from sabnzbd.constants import DEF_TIMEOUT, FUTURE_Q_FOLDER, VALID_NZB_FILES, Status, VALID_ARCHIVES -import sabnzbd.misc as misc -import sabnzbd.filesystem -from sabnzbd.nzbqueue import NzbQueue -from sabnzbd.postproc import PostProcessor import sabnzbd.cfg as cfg import sabnzbd.emailer as emailer +import sabnzbd.filesystem +import sabnzbd.misc as misc import sabnzbd.notifier as notifier +from sabnzbd.constants import DEF_TIMEOUT, FUTURE_Q_FOLDER, VALID_NZB_FILES, Status, VALID_ARCHIVES from sabnzbd.encoding import ubtou, utob - +from sabnzbd.nzbqueue import NzbQueue +from sabnzbd.postproc import PostProcessor _RARTING_FIELDS = ( "x-rating-id", diff --git a/sabnzbd/utils/certgen.py b/sabnzbd/utils/certgen.py index 86002fe..bf79725 100644 --- a/sabnzbd/utils/certgen.py +++ b/sabnzbd/utils/certgen.py @@ -5,13 +5,14 @@ Adapted from the docs of cryptography Creates a key and self-signed certificate for local use """ +import datetime +import socket + +from cryptography import x509 from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization, hashes from cryptography.hazmat.primitives.asymmetric import rsa -from cryptography import x509 from cryptography.x509.oid import NameOID -import datetime -import socket from sabnzbd.getipaddress import localipv4 diff --git a/sabnzbd/utils/checkdir.py b/sabnzbd/utils/checkdir.py index 41566f3..4a5d415 100644 --- a/sabnzbd/utils/checkdir.py +++ b/sabnzbd/utils/checkdir.py @@ -4,8 +4,8 @@ Functions to check if the path filesystem uses FAT """ -import sys import os +import sys debug = False diff --git a/sabnzbd/utils/diskspeed.py b/sabnzbd/utils/diskspeed.py index 0eb6a7c..4179ac6 100644 --- a/sabnzbd/utils/diskspeed.py +++ b/sabnzbd/utils/diskspeed.py @@ -1,8 +1,8 @@ #!/usr/bin/env python -import time import os import sys +import time _DUMP_DATA_SIZE = 10 * 1024 * 1024 _DUMP_DATA = os.urandom(_DUMP_DATA_SIZE) diff --git a/sabnzbd/utils/getperformance.py b/sabnzbd/utils/getperformance.py index 583ae2e..70090e2 100644 --- a/sabnzbd/utils/getperformance.py +++ b/sabnzbd/utils/getperformance.py @@ -1,6 +1,7 @@ +import locale import platform import subprocess -import locale + from .pystone import pystones diff --git a/sabnzbd/utils/happyeyeballs.py b/sabnzbd/utils/happyeyeballs.py index 2482543..d194394 100644 --- a/sabnzbd/utils/happyeyeballs.py +++ b/sabnzbd/utils/happyeyeballs.py @@ -18,12 +18,12 @@ logger.setLevel(logging.DEBUG) print happyeyeballs('newszilla.xs4all.nl', port=119) """ +import logging +import queue import socket import ssl import threading import time -import logging -import queue DEBUG = False diff --git a/sabnzbd/utils/internetspeed.py b/sabnzbd/utils/internetspeed.py index 0200ad9..1393c99 100755 --- a/sabnzbd/utils/internetspeed.py +++ b/sabnzbd/utils/internetspeed.py @@ -6,8 +6,8 @@ Method: get one or more files, and measure how long it takes Reports in MB/s (so mega BYTES per seconds), not to be confused with Mbps """ -import time import logging +import time import urllib.request SizeUrlList = [ diff --git a/sabnzbd/utils/pathbrowser.py b/sabnzbd/utils/pathbrowser.py index a629f6b..f061169 100644 --- a/sabnzbd/utils/pathbrowser.py +++ b/sabnzbd/utils/pathbrowser.py @@ -19,6 +19,7 @@ # along with Sick Beard. If not, see . import os + import sabnzbd if os.name == "nt": diff --git a/sabnzbd/utils/servertests.py b/sabnzbd/utils/servertests.py index fb70d41..edc2f77 100644 --- a/sabnzbd/utils/servertests.py +++ b/sabnzbd/utils/servertests.py @@ -19,14 +19,14 @@ sabnzbd.utils.servertests - Debugging server connections. Currently only NNTP server tests are done. """ +import select import socket import sys -import select -from sabnzbd.newswrapper import NewsWrapper -from sabnzbd.downloader import Server, clues_login, clues_too_many, nntp_to_msg from sabnzbd.config import get_servers +from sabnzbd.downloader import Server, clues_login, clues_too_many, nntp_to_msg from sabnzbd.misc import int_conv +from sabnzbd.newswrapper import NewsWrapper def test_nntp_server_dict(kwargs): diff --git a/sabnzbd/utils/systrayiconthread.py b/sabnzbd/utils/systrayiconthread.py index 83a8873..a4c41c4 100644 --- a/sabnzbd/utils/systrayiconthread.py +++ b/sabnzbd/utils/systrayiconthread.py @@ -7,11 +7,12 @@ # override click to perform actions when left-clicking the icon import os + import pywintypes +import timer import win32api import win32con import win32gui_struct -import timer try: import winxpgui as win32gui diff --git a/sabnzbd/zconfig.py b/sabnzbd/zconfig.py index d45b285..fb4f6f4 100644 --- a/sabnzbd/zconfig.py +++ b/sabnzbd/zconfig.py @@ -19,8 +19,8 @@ sabnzbd.zconfig - bonjour/zeroconfig support """ -import os import logging +import os _HOST_PORT = (None, None) diff --git a/tests/conftest.py b/tests/conftest.py index 43e293f..bf57a3d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,8 +20,6 @@ tests.conftest - Setup pytest fixtures These have to be separate otherwise SABnzbd is started multiple times! """ import shutil -import subprocess -import sys from tests.testhelper import * diff --git a/tests/sabnews.py b/tests/sabnews.py index 13df410..e19765e 100644 --- a/tests/sabnews.py +++ b/tests/sabnews.py @@ -22,13 +22,14 @@ Run sabnews.py -h for parameters! """ +import argparse +import asyncio +import logging import os import re import time + import sabyenc3 -import argparse -import asyncio -import logging logging.getLogger().setLevel(logging.INFO) diff --git a/tests/test_filesystem.py b/tests/test_filesystem.py index 5745b3c..a0508cb 100644 --- a/tests/test_filesystem.py +++ b/tests/test_filesystem.py @@ -18,16 +18,14 @@ """ tests.test_filesystem - Testing functions in filesystem.py """ -import os import stat + import pyfakefs.fake_filesystem_unittest as ffs -import sabnzbd.filesystem as filesystem import sabnzbd.cfg - +import sabnzbd.filesystem as filesystem from tests.testhelper import * - # Set the global uid for fake filesystems to a non-root user; # by default this depends on the user running pytest. global_uid = 1000 diff --git a/tests/test_functional_downloads.py b/tests/test_functional_downloads.py index 4aad798..a57e29f 100644 --- a/tests/test_functional_downloads.py +++ b/tests/test_functional_downloads.py @@ -19,7 +19,6 @@ tests.test_functional_downloads - Test the downloading flow """ -import random from selenium.common.exceptions import NoSuchElementException from tests.testhelper import * diff --git a/tests/test_functional_misc.py b/tests/test_functional_misc.py index 796e1f7..1782c2e 100644 --- a/tests/test_functional_misc.py +++ b/tests/test_functional_misc.py @@ -19,8 +19,6 @@ tests.test_functional_misc - Functional tests of various functions """ import shutil -import subprocess -import sys import sabnzbd.encoding from tests.testhelper import * diff --git a/tests/test_postproc.py b/tests/test_postproc.py index 9685389..837c583 100644 --- a/tests/test_postproc.py +++ b/tests/test_postproc.py @@ -8,11 +8,12 @@ tests.test_postproc- Tests of various functions in newspack, among which rar_renamer() """ -import pytest import shutil from distutils.dir_util import copy_tree from unittest import mock +import pytest + from sabnzbd.postproc import * diff --git a/tests/test_urlgrabber.py b/tests/test_urlgrabber.py index 32cadef..925f464 100644 --- a/tests/test_urlgrabber.py +++ b/tests/test_urlgrabber.py @@ -18,15 +18,15 @@ """ tests.test_urlgrabber - Testing functions in urlgrabber.py """ +import json import urllib.error import urllib.parse + import pytest_httpbin -import json import sabnzbd.urlgrabber as urlgrabber -from sabnzbd.cfg import selftest_host import sabnzbd.version - +from sabnzbd.cfg import selftest_host from tests.testhelper import * diff --git a/tests/test_utils/test_happyeyeballs.py b/tests/test_utils/test_happyeyeballs.py index 19384c7..bd5da50 100644 --- a/tests/test_utils/test_happyeyeballs.py +++ b/tests/test_utils/test_happyeyeballs.py @@ -20,6 +20,7 @@ tests.test_utils.test_happyeyeballs - Testing SABnzbd happyeyeballs """ from flaky import flaky + from sabnzbd.utils.happyeyeballs import happyeyeballs diff --git a/tests/test_utils/test_sleepless.py b/tests/test_utils/test_sleepless.py index 08b5304..4d101a0 100644 --- a/tests/test_utils/test_sleepless.py +++ b/tests/test_utils/test_sleepless.py @@ -19,10 +19,11 @@ tests.test_sleepless - Test sleepless for macOS """ +import subprocess import sys -import pytest import time -import subprocess + +import pytest if not sys.platform.startswith("darwin"): pytest.skip("Skipping macOS-only tests", allow_module_level=True) diff --git a/tests/test_win_utils.py b/tests/test_win_utils.py index be1fecc..5688587 100644 --- a/tests/test_win_utils.py +++ b/tests/test_win_utils.py @@ -20,6 +20,7 @@ tests.test_win_utils - Testing Windows utils """ import sys + import pytest if not sys.platform.startswith("win"): diff --git a/tests/testhelper.py b/tests/testhelper.py index b93a628..69438d5 100644 --- a/tests/testhelper.py +++ b/tests/testhelper.py @@ -28,16 +28,16 @@ from http.client import RemoteDisconnected import pytest import requests -import tests.sabnews from selenium import webdriver +from selenium.common.exceptions import WebDriverException from selenium.webdriver.chrome.options import Options as ChromeOptions from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait -from selenium.common.exceptions import WebDriverException from urllib3.exceptions import ProtocolError import sabnzbd import sabnzbd.cfg as cfg +import tests.sabnews SAB_HOST = "localhost" SAB_PORT = 8081 diff --git a/tools/extract_pot.py b/tools/extract_pot.py index 1bc1e84..9a88a17 100755 --- a/tools/extract_pot.py +++ b/tools/extract_pot.py @@ -20,8 +20,8 @@ extract_pot - Extract translatable strings from all PY files """ import os -import sys import re +import sys # Import version.py without the sabnzbd overhead with open("sabnzbd/version.py") as version_file: diff --git a/tools/make_mo.py b/tools/make_mo.py index 0023aef..ab1573e 100755 --- a/tools/make_mo.py +++ b/tools/make_mo.py @@ -20,12 +20,12 @@ make_mo - Compile PO files to MO files """ +import gettext import glob import os import re -import sys -import gettext import subprocess +import sys PO_DIR = "po/main" POE_DIR = "po/email"