mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 02:26:53 -07:00
Extract manual processing from nzbToMedia.main
-> core.processor.manual
This commit is contained in:
parent
58c998712f
commit
528cbd02cd
2 changed files with 74 additions and 46 deletions
72
core/processor/manual.py
Normal file
72
core/processor/manual.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
import os
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.processor import nzb
|
||||
from core.utils import (
|
||||
get_dirs,
|
||||
get_download_info,
|
||||
)
|
||||
|
||||
try:
|
||||
text_type = unicode
|
||||
except NameError:
|
||||
text_type = str
|
||||
|
||||
|
||||
def process():
|
||||
# Perform Manual Post-Processing
|
||||
logger.warning(
|
||||
'Invalid number of arguments received from client, Switching to manual run mode ...')
|
||||
|
||||
# Post-Processing Result
|
||||
result = ProcessResult(
|
||||
message='',
|
||||
status_code=0,
|
||||
)
|
||||
|
||||
for section, subsections in core.SECTIONS.items():
|
||||
for subsection in subsections:
|
||||
if not core.CFG[section][subsection].isenabled():
|
||||
continue
|
||||
for dir_name in get_dirs(section, subsection, link='move'):
|
||||
logger.info(
|
||||
'Starting manual run for {0}:{1} - Folder: {2}'.format(
|
||||
section, subsection, dir_name))
|
||||
logger.info(
|
||||
'Checking database for download info for {0} ...'.format(
|
||||
os.path.basename(dir_name)))
|
||||
|
||||
core.DOWNLOAD_INFO = get_download_info(
|
||||
os.path.basename(dir_name), 0)
|
||||
if core.DOWNLOAD_INFO:
|
||||
logger.info('Found download info for {0}, '
|
||||
'setting variables now ...'.format
|
||||
(os.path.basename(dir_name)))
|
||||
client_agent = text_type(
|
||||
core.DOWNLOAD_INFO[0]['client_agent']) or 'manual'
|
||||
download_id = text_type(
|
||||
core.DOWNLOAD_INFO[0]['input_id']) or ''
|
||||
else:
|
||||
logger.info('Unable to locate download info for {0}, '
|
||||
'continuing to try and process this release ...'.format
|
||||
(os.path.basename(dir_name)))
|
||||
client_agent = 'manual'
|
||||
download_id = ''
|
||||
|
||||
if client_agent and client_agent.lower() not in core.NZB_CLIENTS:
|
||||
continue
|
||||
|
||||
input_name = os.path.basename(dir_name)
|
||||
|
||||
results = nzb.process(dir_name, input_name, 0,
|
||||
client_agent=client_agent,
|
||||
download_id=download_id or None,
|
||||
input_category=subsection)
|
||||
if results.status_code != 0:
|
||||
logger.error(
|
||||
'A problem was reported when trying to perform a manual run for {0}:{1}.'.format
|
||||
(section, subsection))
|
||||
result = results
|
||||
return result
|
|
@ -733,18 +733,9 @@ cleanup.clean(cleanup.FOLDER_STRUCTURE)
|
|||
|
||||
import core
|
||||
from core import logger
|
||||
from core.processor import nzbget, sab
|
||||
from core.processor import nzbget, sab, manual
|
||||
from core.processor.nzb import process
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.utils import (
|
||||
get_dirs,
|
||||
get_download_info,
|
||||
)
|
||||
|
||||
try:
|
||||
text_type = unicode
|
||||
except NameError:
|
||||
text_type = str
|
||||
|
||||
|
||||
def main(args, section=None):
|
||||
|
@ -783,42 +774,7 @@ def main(args, section=None):
|
|||
elif core.NZB_NO_MANUAL:
|
||||
logger.warning('Invalid number of arguments received from client, and no_manual set')
|
||||
else:
|
||||
# Perform Manual Post-Processing
|
||||
logger.warning('Invalid number of arguments received from client, Switching to manual run mode ...')
|
||||
|
||||
for section, subsections in core.SECTIONS.items():
|
||||
for subsection in subsections:
|
||||
if not core.CFG[section][subsection].isenabled():
|
||||
continue
|
||||
for dir_name in get_dirs(section, subsection, link='move'):
|
||||
logger.info('Starting manual run for {0}:{1} - Folder: {2}'.format(section, subsection, dir_name))
|
||||
logger.info('Checking database for download info for {0} ...'.format(os.path.basename(dir_name)))
|
||||
|
||||
core.DOWNLOAD_INFO = get_download_info(os.path.basename(dir_name), 0)
|
||||
if core.DOWNLOAD_INFO:
|
||||
logger.info('Found download info for {0}, '
|
||||
'setting variables now ...'.format
|
||||
(os.path.basename(dir_name)))
|
||||
client_agent = text_type(core.DOWNLOAD_INFO[0]['client_agent']) or 'manual'
|
||||
download_id = text_type(core.DOWNLOAD_INFO[0]['input_id']) or ''
|
||||
else:
|
||||
logger.info('Unable to locate download info for {0}, '
|
||||
'continuing to try and process this release ...'.format
|
||||
(os.path.basename(dir_name)))
|
||||
client_agent = 'manual'
|
||||
download_id = ''
|
||||
|
||||
if client_agent and client_agent.lower() not in core.NZB_CLIENTS:
|
||||
continue
|
||||
|
||||
input_name = os.path.basename(dir_name)
|
||||
|
||||
results = process(dir_name, input_name, 0, client_agent=client_agent,
|
||||
download_id=download_id or None, input_category=subsection)
|
||||
if results.status_code != 0:
|
||||
logger.error('A problem was reported when trying to perform a manual run for {0}:{1}.'.format
|
||||
(section, subsection))
|
||||
result = results
|
||||
manual.process()
|
||||
|
||||
if result.status_code == 0:
|
||||
logger.info('The {0} script completed successfully.'.format(args[0]))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue