mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 21:33:13 -07:00
Merge pull request #1594 from clinton-hall/quality/flake8
Quality/flake8
This commit is contained in:
commit
627b453d3b
14 changed files with 89 additions and 73 deletions
|
@ -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}
|
||||
}
|
||||
|
@ -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:
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
# coding=utf-8
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import requests
|
||||
|
||||
import core
|
||||
|
@ -52,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(
|
||||
|
|
|
@ -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)
|
||||
|
@ -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(
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
"""
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -90,13 +89,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.
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import re
|
||||
import core
|
||||
|
||||
|
||||
def sanitize_name(name):
|
||||
|
@ -20,9 +19,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
|
||||
|
|
|
@ -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
|
||||
|
|
16
setup.py
16
setup.py
|
@ -21,21 +21,21 @@ setup(
|
|||
version='12.0.10',
|
||||
license='GPLv3',
|
||||
description='Efficient on demand post processing',
|
||||
long_description="""
|
||||
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',
|
||||
|
|
|
@ -1,48 +1,47 @@
|
|||
#! /usr/bin/env python
|
||||
from __future__ import print_function
|
||||
import datetime
|
||||
import os
|
||||
import sys
|
||||
|
||||
import core
|
||||
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
import core
|
||||
from core import logger, main_db
|
||||
|
||||
def test_initial():
|
||||
core.initialize()
|
||||
del core.MYAPP
|
||||
|
||||
|
||||
def test_core_parameters():
|
||||
assert core.CHECK_MEDIA == 1
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
#! /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():
|
||||
assert transcoder.is_video_good(core.TEST_FILE, 0) == True
|
||||
assert transcoder.is_video_good(core.TEST_FILE, 0) is True
|
||||
|
|
24
tox.ini
24
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/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue