From a8d1cc4fe9f02005443d73ef0097c635713d1181 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 17:11:16 -0400 Subject: [PATCH 01/14] Add flake8 quality checks to tox.ini --- tox.ini | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tox.ini b/tox.ini index a18abb54..2684e857 100644 --- a/tox.ini +++ b/tox.ini @@ -29,6 +29,30 @@ deps = commands = {posargs:pytest --cov --cov-report=term-missing tests} +[flake8] +max-line-length = 79 +verbose = 2 +statistics = True +ignore = +; -- flake8 -- +; E501 line too long + E501 + +per-file-ignores = +; F401 imported but unused +; E402 module level import not at top of file + core/__init__.py: E402, F401 + core/utils/__init__.py: F401 + core/plugins/downloaders/configuration.py: F401 + core/plugins/downloaders/utils.py: F401 + +[testenv:check] +deps = + flake8 +skip_install = true +commands = + flake8 core tests setup.py + [coverage:run] omit = libs/* From 90090d7e02ed8b24306e219b38836f3456a1276a Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 12:36:23 -0400 Subject: [PATCH 02/14] Fix flake8 E117 over-indented --- core/auto_process/movies.py | 32 ++++++++++++++++---------------- core/version_check.py | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/auto_process/movies.py b/core/auto_process/movies.py index b7fe3a66..ff1222bf 100644 --- a/core/auto_process/movies.py +++ b/core/auto_process/movies.py @@ -373,22 +373,22 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual', except Exception: pass elif scan_id: - url = '{0}/{1}'.format(base_url, scan_id) - command_status = command_complete(url, params, headers, section) - if command_status: - logger.debug('The Scan command return status: {0}'.format(command_status), section) - if command_status in ['completed']: - logger.debug('The Scan command has completed successfully. Renaming was successful.', section) - return ProcessResult( - message='{0}: Successfully post-processed {1}'.format(section, input_name), - status_code=0, - ) - elif command_status in ['failed']: - logger.debug('The Scan command has failed. Renaming was not successful.', section) - # return ProcessResult( - # message='{0}: Failed to post-process {1}'.format(section, input_name), - # status_code=1, - # ) + url = '{0}/{1}'.format(base_url, scan_id) + command_status = command_complete(url, params, headers, section) + if command_status: + logger.debug('The Scan command return status: {0}'.format(command_status), section) + if command_status in ['completed']: + logger.debug('The Scan command has completed successfully. Renaming was successful.', section) + return ProcessResult( + message='{0}: Successfully post-processed {1}'.format(section, input_name), + status_code=0, + ) + elif command_status in ['failed']: + logger.debug('The Scan command has failed. Renaming was not successful.', section) + # return ProcessResult( + # message='{0}: Failed to post-process {1}'.format(section, input_name), + # status_code=1, + # ) if not os.path.isdir(dir_name): logger.postprocess('SUCCESS: Input Directory [{0}] has been processed and removed'.format( diff --git a/core/version_check.py b/core/version_check.py index 53945e1f..d865b9f3 100644 --- a/core/version_check.py +++ b/core/version_check.py @@ -199,8 +199,8 @@ class GitUpdateManager(UpdateManager): logger.log(u'{cmd} : returned successful'.format(cmd=cmd), logger.DEBUG) exit_status = 0 elif core.LOG_GIT and exit_status in (1, 128): - logger.log(u'{cmd} returned : {output}'.format - (cmd=cmd, output=output), logger.DEBUG) + logger.log(u'{cmd} returned : {output}'.format + (cmd=cmd, output=output), logger.DEBUG) else: if core.LOG_GIT: logger.log(u'{cmd} returned : {output}, treat as error for now'.format From 87e813f06280c5b46a15f367f5e148a2181c0227 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 12:04:50 -0400 Subject: [PATCH 03/14] Fix flake8 E126 continuation line over-indented for hanging indent --- core/forks.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/forks.py b/core/forks.py index be81a965..897a1fd9 100644 --- a/core/forks.py +++ b/core/forks.py @@ -42,7 +42,8 @@ def auto_fork(section, input_category): logger.info('Attempting to verify {category} fork'.format (category=input_category)) url = '{protocol}{host}:{port}{root}/api/rootfolder'.format( - protocol=protocol, host=host, port=port, root=web_root) + protocol=protocol, host=host, port=port, root=web_root + ) headers = {'X-Api-Key': apikey} try: r = requests.get(url, headers=headers, stream=True, verify=False) @@ -65,10 +66,12 @@ def auto_fork(section, input_category): if apikey: url = '{protocol}{host}:{port}{root}/api/{apikey}/?cmd=help&subject=postprocess'.format( - protocol=protocol, host=host, port=port, root=web_root, apikey=apikey) + protocol=protocol, host=host, port=port, root=web_root, apikey=apikey + ) else: url = '{protocol}{host}:{port}{root}/home/postprocess/'.format( - protocol=protocol, host=host, port=port, root=web_root) + protocol=protocol, host=host, port=port, root=web_root + ) # attempting to auto-detect fork try: From 07ad515b5066c6bbc53f639d4679647b01c02790 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 12:18:31 -0400 Subject: [PATCH 04/14] Fix flake8 E226 missing whitespace around arithmetic operator --- core/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/__init__.py b/core/__init__.py index 56f08bce..0a224f94 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -870,7 +870,7 @@ def configure_utility_locations(): else: if SYS_PATH: - os.environ['PATH'] += ':'+SYS_PATH + os.environ['PATH'] += ':' + SYS_PATH try: SEVENZIP = subprocess.Popen(['which', '7z'], stdout=subprocess.PIPE).communicate()[0].strip().decode() except Exception: From 8a22f20a8b189e149a858547a97a807c1e1bf828 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 13:10:20 -0400 Subject: [PATCH 05/14] Fix flake8 E241 multiple spaces after ':' --- core/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/__init__.py b/core/__init__.py index 0a224f94..40b9d54f 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -108,7 +108,7 @@ FORKS = { FORK_SICKCHILL: {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None, 'force_next': None}, FORK_SICKBEARD_API: {'path': None, 'failed': None, 'process_method': None, 'force_replace': None, 'return_data': None, 'type': None, 'delete': None, 'force_next': None}, FORK_MEDUSA: {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None, 'ignore_subs': None}, - FORK_MEDUSA_API: {'path': None, 'failed': None, 'process_method': None, 'force_replace': None, 'return_data': None, 'type': None, 'delete_files': None, 'is_priority': None}, + FORK_MEDUSA_API: {'path': None, 'failed': None, 'process_method': None, 'force_replace': None, 'return_data': None, 'type': None, 'delete_files': None, 'is_priority': None}, FORK_SICKGEAR: {'dir': None, 'failed': None, 'process_method': None, 'force': None}, FORK_STHENO: {"proc_dir": None, "failed": None, "process_method": None, "force": None, "delete_on": None, "ignore_subs": None} } From 5f633b931aaa0508dae655872446429ce0531ac3 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 12:27:39 -0400 Subject: [PATCH 06/14] Fix flake8 E261 at least two spaces before inline comment --- core/auto_process/movies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/auto_process/movies.py b/core/auto_process/movies.py index ff1222bf..76d49b78 100644 --- a/core/auto_process/movies.py +++ b/core/auto_process/movies.py @@ -256,7 +256,7 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual', return ProcessResult( message='{0}: Sending failed download back to {0}'.format(section), status_code=1, # Return as failed to flag this in the downloader. - ) # Return failed flag, but log the event as successful. + ) # Return failed flag, but log the event as successful. if delete_failed and os.path.isdir(dir_name) and not os.path.dirname(dir_name) == dir_name: logger.postprocess('Deleting failed files and folder {0}'.format(dir_name), section) From a571fc31224ef0a86fa54c110c32bafc3517d96f Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 12:42:46 -0400 Subject: [PATCH 07/14] Fix flake8 E265 block comment should start with '# ' --- core/utils/identification.py | 8 ++++---- core/utils/naming.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/utils/identification.py b/core/utils/identification.py index 7a48ec87..5aada2c1 100644 --- a/core/utils/identification.py +++ b/core/utils/identification.py @@ -90,13 +90,13 @@ def find_imdbid(dir_name, input_name, omdb_api_key): def category_search(input_directory, input_name, input_category, root, categories): tordir = False - #try: + # try: # input_name = input_name.encode(core.SYS_ENCODING) - #except Exception: + # except Exception: # pass - #try: + # try: # input_directory = input_directory.encode(core.SYS_ENCODING) - #except Exception: + # except Exception: # pass if input_directory is None: # =Nothing to process here. diff --git a/core/utils/naming.py b/core/utils/naming.py index 8b3e6971..ab8d9174 100644 --- a/core/utils/naming.py +++ b/core/utils/naming.py @@ -20,9 +20,9 @@ def sanitize_name(name): # remove leading/trailing periods and spaces name = name.strip(' .') - #try: + # try: # name = name.encode(core.SYS_ENCODING) - #except Exception: + # except Exception: # pass return name From 032f7456f9656072a510eacbe86f41014fba3984 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 12:52:41 -0400 Subject: [PATCH 08/14] Fix flake8 E302 expected 2 blank lines, found 1 --- tests/test_initialize.py | 8 ++++++++ tests/test_transcoder.py | 1 + 2 files changed, 9 insertions(+) diff --git a/tests/test_initialize.py b/tests/test_initialize.py index 612261d3..ecc11331 100755 --- a/tests/test_initialize.py +++ b/tests/test_initialize.py @@ -8,28 +8,35 @@ def test_eol(): import eol eol.check() + def test_cleanup(): import cleanup cleanup.clean(cleanup.FOLDER_STRUCTURE) + def test_import_core(): import core from core import logger, main_db + def test_import_core_auto_process(): from core.auto_process import comics, games, movies, music, tv from core.auto_process.common import ProcessResult + def test_import_core_plugins(): from core.plugins.downloaders.nzb.utils import get_nzoid from core.plugins.plex import plex_update + def test_import_core_user_scripts(): from core.user_scripts import external_script + def test_import_six(): from six import text_type + def test_import_core_utils(): from core.utils import ( char_replace, clean_dir, convert_to_ascii, @@ -44,5 +51,6 @@ def test_initial(): core.initialize() del core.MYAPP + def test_core_parameters(): assert core.CHECK_MEDIA == 1 diff --git a/tests/test_transcoder.py b/tests/test_transcoder.py index 929e7f23..15b8f4aa 100755 --- a/tests/test_transcoder.py +++ b/tests/test_transcoder.py @@ -10,5 +10,6 @@ import requests import core from core import logger, transcoder + def test_transcoder_check(): assert transcoder.is_video_good(core.TEST_FILE, 0) == True From 8e6e2d16470c698929f1dfad70fc557989e8a389 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 12:28:36 -0400 Subject: [PATCH 09/14] Fix flake8 E305 expected 2 blank lines after class or function definition, found 1 --- tests/test_initialize.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_initialize.py b/tests/test_initialize.py index ecc11331..90759dbd 100755 --- a/tests/test_initialize.py +++ b/tests/test_initialize.py @@ -44,6 +44,7 @@ def test_import_core_utils(): update_download_info_status, replace_links, ) + import core from core import logger, main_db From d20879843064f44acac0451b2fde991e8e8d0d55 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 12:50:11 -0400 Subject: [PATCH 10/14] Fix flake8 E402 module level import not at top of file --- tests/test_initialize.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_initialize.py b/tests/test_initialize.py index 90759dbd..ea25826e 100755 --- a/tests/test_initialize.py +++ b/tests/test_initialize.py @@ -4,6 +4,10 @@ import datetime import os import sys +import core +from core import logger, main_db + + def test_eol(): import eol eol.check() @@ -45,9 +49,6 @@ def test_import_core_utils(): ) -import core -from core import logger, main_db - def test_initial(): core.initialize() del core.MYAPP From faa378f7875f7f1cd20d99f6edd72a90efb888cd Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 12:30:35 -0400 Subject: [PATCH 11/14] Fix flake8 E712 comparison to True should be 'if cond is True:' or 'if cond:' --- tests/test_transcoder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_transcoder.py b/tests/test_transcoder.py index 15b8f4aa..c027aee8 100755 --- a/tests/test_transcoder.py +++ b/tests/test_transcoder.py @@ -12,4 +12,4 @@ from core import logger, transcoder def test_transcoder_check(): - assert transcoder.is_video_good(core.TEST_FILE, 0) == True + assert transcoder.is_video_good(core.TEST_FILE, 0) is True From 644a11118c7d05e606234a1ca7ec6169b81c46f5 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 13:07:24 -0400 Subject: [PATCH 12/14] Fix flake8 F401 imported but unused --- core/auto_process/books.py | 3 --- core/utils/identification.py | 1 - core/utils/naming.py | 1 - tests/test_initialize.py | 23 ++++++----------------- tests/test_transcoder.py | 8 +------- 5 files changed, 7 insertions(+), 29 deletions(-) diff --git a/core/auto_process/books.py b/core/auto_process/books.py index c029d06f..7d843f5e 100644 --- a/core/auto_process/books.py +++ b/core/auto_process/books.py @@ -1,8 +1,5 @@ # coding=utf-8 -import os -import shutil - import requests import core diff --git a/core/utils/identification.py b/core/utils/identification.py index 5aada2c1..9029f7e4 100644 --- a/core/utils/identification.py +++ b/core/utils/identification.py @@ -5,7 +5,6 @@ import guessit import requests from six import text_type -import core from core import logger from core.utils.naming import sanitize_name diff --git a/core/utils/naming.py b/core/utils/naming.py index ab8d9174..b54e3258 100644 --- a/core/utils/naming.py +++ b/core/utils/naming.py @@ -1,5 +1,4 @@ import re -import core def sanitize_name(name): diff --git a/tests/test_initialize.py b/tests/test_initialize.py index ea25826e..dffcfe76 100755 --- a/tests/test_initialize.py +++ b/tests/test_initialize.py @@ -1,11 +1,7 @@ #! /usr/bin/env python from __future__ import print_function -import datetime -import os -import sys import core -from core import logger, main_db def test_eol(): @@ -19,34 +15,27 @@ def test_cleanup(): def test_import_core(): - import core - from core import logger, main_db + pass def test_import_core_auto_process(): - from core.auto_process import comics, games, movies, music, tv - from core.auto_process.common import ProcessResult + pass def test_import_core_plugins(): - from core.plugins.downloaders.nzb.utils import get_nzoid - from core.plugins.plex import plex_update + pass def test_import_core_user_scripts(): - from core.user_scripts import external_script + pass def test_import_six(): - from six import text_type + pass def test_import_core_utils(): - from core.utils import ( - char_replace, clean_dir, convert_to_ascii, - extract_files, get_dirs, get_download_info, - update_download_info_status, replace_links, - ) + pass def test_initial(): diff --git a/tests/test_transcoder.py b/tests/test_transcoder.py index c027aee8..148156b0 100755 --- a/tests/test_transcoder.py +++ b/tests/test_transcoder.py @@ -1,14 +1,8 @@ #! /usr/bin/env python from __future__ import print_function -import datetime -import os -import sys -import json -import time -import requests import core -from core import logger, transcoder +from core import transcoder def test_transcoder_check(): From 0350521b874c7d38340a8f19dbb1b19e53cbcaf6 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 12:37:23 -0400 Subject: [PATCH 13/14] Fix flake8 W291 trailing whitespace --- core/scene_exceptions.py | 2 +- core/transcoder.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/scene_exceptions.py b/core/scene_exceptions.py index f2c53c45..42473ab8 100644 --- a/core/scene_exceptions.py +++ b/core/scene_exceptions.py @@ -171,7 +171,7 @@ def par2(dirname): cmd = '' for item in command: cmd = '{cmd} {item}'.format(cmd=cmd, item=item) - logger.debug('calling command:{0}'.format(cmd), 'PAR2') + logger.debug('calling command:{0}'.format(cmd), 'PAR2') try: proc = subprocess.Popen(command, stdout=bitbucket, stderr=bitbucket) proc.communicate() diff --git a/core/transcoder.py b/core/transcoder.py index c53a1211..edb98761 100644 --- a/core/transcoder.py +++ b/core/transcoder.py @@ -828,7 +828,7 @@ def transcode_directory(dir_name): if not os.listdir(text_type(new_dir)): # this is an empty directory and we didn't transcode into it. os.rmdir(new_dir) new_dir = dir_name - if not core.PROCESSOUTPUT and core.DUPLICATE: # We postprocess the original files to CP/SB + if not core.PROCESSOUTPUT and core.DUPLICATE: # We postprocess the original files to CP/SB new_dir = dir_name bitbucket.close() return final_result, new_dir diff --git a/setup.py b/setup.py index b2f78439..86d82b89 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( version='12.0.10', license='GPLv3', description='Efficient on demand post processing', - long_description=""" + long_description=""" nzbToMedia ========== From 697df555ec36367f718eec568ed9fd8976239f96 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 5 Apr 2019 12:44:44 -0400 Subject: [PATCH 14/14] Fix flake8 W293 blank line contains whitespace --- core/auto_process/books.py | 2 +- core/logger.py | 2 +- setup.py | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/auto_process/books.py b/core/auto_process/books.py index 7d843f5e..8ba74a43 100644 --- a/core/auto_process/books.py +++ b/core/auto_process/books.py @@ -49,7 +49,7 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual', ) logger.postprocess('{0}'.format(r.text), section) - + if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error('Server returned status {0}'.format(r.status_code), section) return ProcessResult( diff --git a/core/logger.py b/core/logger.py index 3305a96e..d73b501b 100644 --- a/core/logger.py +++ b/core/logger.py @@ -132,7 +132,7 @@ class NTMRotatingLogHandler(object): """ Returns a numbered log file name depending on i. If i==0 it just uses logName, if not it appends it to the extension (blah.log.3 for i == 3) - + i: Log number to ues """ diff --git a/setup.py b/setup.py index 86d82b89..fed3a4be 100644 --- a/setup.py +++ b/setup.py @@ -24,18 +24,18 @@ setup( long_description=""" nzbToMedia ========== - + Efficient on demand post processing ----------------------------------- - + A PVR app needs to know when a download is ready for post-processing. There are two methods: - + 1. On-demand post-processing script (e.g. sabToSickBeard.py or nzbToMedia.py): A script in the downloader runs once at the end of the download job and notifies the PVR app that the download is complete. - + 2. Continuous folder scanning: The PVR app frequently polls download folder(s) for completed downloads. - + On-demand is superior, for several reasons: - + 1. The PVR app is notified only once, exactly when the download is ready for post-processing 2. The PVR app does not have to wait for the next poll interval before it starts processing 3. Continuous polling is not as efficient and is more stressful on low performance hardware @@ -46,7 +46,7 @@ setup( 8. On-demand scripts can be tweaked to allow for delays with slow hardware nzbToMedia is an on-demand post-processing script and was created out of a demand for more efficient post-processing on low-performance hardware. Many features have been added so higher performance hardware can benefit too. - + Many issues that users have with folder scanning can be fixed by switching to on-demand. A whole class of support issues can be eliminated by using nzbToMedia. """, author='Clinton Hall',