Merge pull request #1514 from clinton-hall/feature/cleanup

Code cleanup
This commit is contained in:
Labrys of Knossos 2019-01-06 12:10:24 -05:00 committed by GitHub
commit 22b9a484ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 42 additions and 44 deletions

View file

@ -1,5 +1,5 @@
[bumpversion]
current_version = 12.0.4
current_version = 12.0.5
commit = True
tag = False

View file

@ -1,4 +1,4 @@
nzbToMedia v12.0.4
nzbToMedia v12.0.5
==================
Provides an [efficient](https://github.com/clinton-hall/nzbToMedia/wiki/Efficient-on-demand-post-processing) way to handle postprocessing for [CouchPotatoServer](https://couchpota.to/ "CouchPotatoServer") and [SickBeard](http://sickbeard.com/ "SickBeard") (and its [forks](https://github.com/clinton-hall/nzbToMedia/wiki/Failed-Download-Handling-%28FDH%29#sick-beard-and-its-forks))

View file

@ -2,7 +2,7 @@
# coding=utf-8
import cleanup
cleanup.clean('core', 'libs')
cleanup.clean(cleanup.FOLDER_STRUCTURE)
import datetime
import os

View file

@ -52,7 +52,7 @@ from core.utils import (
resume_torrent, remove_dir, remove_read_only, sanitize_name, update_download_info_status,
)
__version__ = '12.0.4'
__version__ = '12.0.5'
# Client Agents
NZB_CLIENTS = ['sabnzbd', 'nzbget', 'manual']
@ -63,7 +63,6 @@ SABNZB_NO_OF_ARGUMENTS = 8
SABNZB_0717_NO_OF_ARGUMENTS = 9
# sickbeard fork/branch constants
FORKS = {}
FORK_DEFAULT = 'default'
FORK_FAILED = 'failed'
FORK_FAILED_TORRENT = 'failed-torrent'
@ -73,15 +72,18 @@ FORK_SICKBEARD_API = 'SickBeard-api'
FORK_MEDUSA = 'Medusa'
FORK_SICKGEAR = 'SickGear'
FORK_STHENO = 'Stheno'
FORKS[FORK_DEFAULT] = {'dir': None}
FORKS[FORK_FAILED] = {'dirName': None, 'failed': None}
FORKS[FORK_FAILED_TORRENT] = {'dir': None, 'failed': None, 'process_method': None}
FORKS[FORK_SICKRAGE] = {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None}
FORKS[FORK_SICKCHILL] = {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None, 'force_next': None}
FORKS[FORK_SICKBEARD_API] = {'path': None, 'failed': None, 'process_method': None, 'force_replace': None, 'return_data': None, 'type': None, 'delete': None, 'force_next': None}
FORKS[FORK_MEDUSA] = {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None, 'ignore_subs': None}
FORKS[FORK_SICKGEAR] = {'dir': None, 'failed': None, 'process_method': None, 'force': None}
FORKS[FORK_STHENO] = {"proc_dir": None, "failed": None, "process_method": None, "force": None, "delete_on": None, "ignore_subs": None}
FORKS = {
FORK_DEFAULT: {'dir': None},
FORK_FAILED: {'dirName': None, 'failed': None},
FORK_FAILED_TORRENT: {'dir': None, 'failed': None, 'process_method': None},
FORK_SICKRAGE: {'proc_dir': None, 'failed': None, 'process_method': None, 'force': None, 'delete_on': None},
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_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}
}
ALL_FORKS = {k: None for k in set(list(itertools.chain.from_iterable([FORKS[x].keys() for x in FORKS.keys()])))}
# NZBGet Exit Codes
@ -743,7 +745,6 @@ def initialize(section=None):
if codec in codec_alias:
extra = [item for item in codec_alias[codec] if item not in ACODEC3_ALLOW]
ACODEC3_ALLOW.extend(extra)
codec_alias = {} # clear memory
PASSWORDSFILE = CFG['passwords']['PassWordFile']

View file

@ -163,17 +163,18 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
status_code=0,
)
params = {}
params = {
'media_folder': remote_dir(dir_name) if remote_path else dir_name,
}
if download_id and release_id:
params['downloader'] = downloader or client_agent
params['download_id'] = download_id
params['media_folder'] = remote_dir(dir_name) if remote_path else dir_name
if section == 'CouchPotato':
if method == 'manage':
command = 'manage.update'
params = {}
params.clear()
else:
command = 'renamer.scan'
@ -220,7 +221,6 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
res = json.loads(r.content)
scan_id = int(res['id'])
logger.debug('Scan started with id: {0}'.format(scan_id), section)
started = True
except Exception as e:
logger.warning('No scan id was returned due to: {0}'.format(e), section)
scan_id = None

View file

@ -117,18 +117,12 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
status_code=1,
)
success = False
queued = False
started = False
try:
res = json.loads(r.content)
scan_id = int(res['id'])
logger.debug('Scan started with id: {0}'.format(scan_id), section)
started = True
except Exception as e:
logger.warning('No scan id was returned due to: {0}'.format(e), section)
scan_id = None
started = False
return ProcessResult(
message='{0}: Failed to post-process - Unable to start scan'.format(section),
status_code=1,

View file

@ -20,8 +20,16 @@ def auto_fork(section, input_category):
apikey = cfg.get('apikey')
ssl = int(cfg.get('ssl', 0))
web_root = cfg.get('web_root', '')
replace = {'sickrage': 'SickRage', 'sickchill': 'SickChill', 'sickgear': 'SickGear', 'medusa': 'Medusa', 'sickbeard-api': 'SickBeard-api', 'stheno': 'Stheno'}
f1 = replace[cfg.get('fork', 'auto')] if cfg.get('fork', 'auto') in replace else cfg.get('fork', 'auto')
replace = {
'medusa': 'Medusa',
'sickbeard-api': 'SickBeard-api',
'sickgear': 'SickGear',
'sickchill': 'SickChill',
'sickrage': 'SickRage',
'stheno': 'Stheno',
}
_val = cfg.get('fork', 'auto')
f1 = replace.get(_val, _val)
try:
fork = f1, core.FORKS[f1]
except KeyError:
@ -79,7 +87,6 @@ def auto_fork(section, input_category):
r = []
if r and r.ok:
if apikey:
optional_parameters = []
try:
json_data = r.json()
except ValueError:

View file

@ -202,17 +202,17 @@ class DBConnection(object):
def table_info(self, table_name):
# FIXME ? binding is not supported here, but I cannot find a way to escape a string manually
cursor = self.connection.execute('PRAGMA table_info({0})'.format(table_name))
columns = {}
for column in cursor:
columns[column['name']] = {'type': column['type']}
return columns
return {
column['name']: {'type': column['type']}
for column in cursor
}
# http://stackoverflow.com/questions/3300464/how-can-i-get-dict-from-sqlite-query
def _dict_factory(self, cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
return {
col[0]: row[idx]
for idx, col in enumerate(cursor.description)
}
def sanity_check_database(connection, sanity_check):

View file

@ -148,7 +148,6 @@ def rename_script(dirname):
def par2(dirname):
newlist = []
sofar = 0
parfile = ''
objects = []

View file

@ -80,10 +80,7 @@ def get_video_details(videofile, img=None, bitbucket=None):
file = videofile
if not core.FFPROBE:
return video_details, result
if 'avprobe' in core.FFPROBE:
print_format = '-of'
else:
print_format = '-print_format'
print_format = '-of' if 'avprobe' in core.FFPROBE else '-print_format'
try:
if img:
videofile = '-'

View file

@ -624,7 +624,7 @@
from __future__ import print_function
import cleanup
cleanup.clean('core', 'libs')
cleanup.clean(cleanup.FOLDER_STRUCTURE)
import datetime
import os

View file

@ -18,7 +18,7 @@ def read(*names, **kwargs):
setup(
name='nzbToMedia',
version='12.0.4',
version='12.0.5',
license='GPLv3',
description='Efficient on demand post processing',
long_description="""