mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 18:47:09 -07:00
Add ProcessResult to auto_process.common
This commit is contained in:
parent
1d46f716e1
commit
8c4353bc90
5 changed files with 111 additions and 44 deletions
|
@ -6,6 +6,7 @@ import requests
|
|||
|
||||
import core
|
||||
from core import logger
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.utils import convert_to_ascii, remote_dir, server_responding
|
||||
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
@ -28,7 +29,10 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
|
|||
url = "{0}{1}:{2}{3}/api".format(protocol, host, port, web_root)
|
||||
if not server_responding(url):
|
||||
logger.error("Server did not respond. Exiting", section)
|
||||
return [1, "{0}: Failed to post-process - {1} did not respond.".format(section, section)]
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - {0} did not respond.".format(section),
|
||||
status_code=1,
|
||||
)
|
||||
|
||||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||
clean_name, ext = os.path.splitext(input_name)
|
||||
|
@ -54,10 +58,16 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
|
|||
r = requests.post(url, params=params, stream=True, verify=False, timeout=(30, 300))
|
||||
except requests.ConnectionError:
|
||||
logger.error("Unable to open URL", section)
|
||||
return [1, "{0}: Failed to post-process - Unable to connect to {1}".format(section, section)]
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - Unable to connect to {0}".format(section),
|
||||
status_code=1
|
||||
)
|
||||
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 [1, "{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code)]
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code),
|
||||
status_code=1,
|
||||
)
|
||||
|
||||
result = r.content
|
||||
if not type(result) == list:
|
||||
|
@ -70,7 +80,13 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
|
|||
|
||||
if success:
|
||||
logger.postprocess("SUCCESS: This issue has been processed successfully", section)
|
||||
return [0, "{0}: Successfully post-processed {1}".format(section, input_name)]
|
||||
return ProcessResult(
|
||||
message="{0}: Successfully post-processed {1}".format(section, input_name),
|
||||
status_code=0,
|
||||
)
|
||||
else:
|
||||
logger.warning("The issue does not appear to have successfully processed. Please check your Logs", section)
|
||||
return [1, "{0}: Failed to post-process - Returned log from {1} was not as expected.".format(section, section)]
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - Returned log from {0} was not as expected.".format(section),
|
||||
status_code=1,
|
||||
)
|
||||
|
|
|
@ -3,6 +3,30 @@ import requests
|
|||
from core import logger
|
||||
|
||||
|
||||
class ProcessResult(object):
|
||||
def __init__(self, message, status_code):
|
||||
self.message = message
|
||||
self.status_code = status_code
|
||||
|
||||
def __iter__(self):
|
||||
return self.status_code, self.message
|
||||
|
||||
def __bool__(self):
|
||||
return not bool(self.status_code)
|
||||
|
||||
def __str__(self):
|
||||
return 'Processing {0}: {1}'.format(
|
||||
'succeeded' if bool(self) else 'failed',
|
||||
self.message
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return '<ProcessResult {0}: {1}>'.format(
|
||||
self.status_code,
|
||||
self.message,
|
||||
)
|
||||
|
||||
|
||||
def command_complete(url, params, headers, section):
|
||||
try:
|
||||
r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60))
|
||||
|
|
|
@ -7,6 +7,7 @@ import requests
|
|||
|
||||
import core
|
||||
from core import logger
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.utils import convert_to_ascii, server_responding
|
||||
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
@ -28,7 +29,10 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
|
|||
url = "{0}{1}:{2}{3}/api".format(protocol, host, port, web_root)
|
||||
if not server_responding(url):
|
||||
logger.error("Server did not respond. Exiting", section)
|
||||
return [1, "{0}: Failed to post-process - {1} did not respond.".format(section, section)]
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - {0} did not respond.".format(section),
|
||||
status_code=1,
|
||||
)
|
||||
|
||||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||
|
||||
|
@ -51,7 +55,10 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
|
|||
r = requests.get(url, params=params, verify=False, timeout=(30, 300))
|
||||
except requests.ConnectionError:
|
||||
logger.error("Unable to open URL")
|
||||
return [1, "{0}: Failed to post-process - Unable to connect to {1}".format(section, section)]
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - Unable to connect to {1}".format(section, section),
|
||||
status_code=1,
|
||||
)
|
||||
|
||||
result = r.json()
|
||||
logger.postprocess("{0}".format(result), section)
|
||||
|
@ -61,17 +68,32 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual',
|
|||
shutil.move(dir_name, os.path.join(library, input_name))
|
||||
except Exception:
|
||||
logger.error("Unable to move {0} to {1}".format(dir_name, os.path.join(library, input_name)), section)
|
||||
return [1, "{0}: Failed to post-process - Unable to move files".format(section)]
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - Unable to move files".format(section),
|
||||
status_code=1,
|
||||
)
|
||||
else:
|
||||
logger.error("No library specified to move files to. Please edit your configuration.", section)
|
||||
return [1, "{0}: Failed to post-process - No library defined in {1}".format(section, section)]
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - No library defined in {0}".format(section),
|
||||
status_code=1,
|
||||
)
|
||||
|
||||
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 [1, "{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code)]
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code),
|
||||
status_code=1,
|
||||
)
|
||||
elif result['success']:
|
||||
logger.postprocess("SUCCESS: Status for {0} has been set to {1} in Gamez".format(gamez_id, download_status), section)
|
||||
return [0, "{0}: Successfully post-processed {1}".format(section, input_name)]
|
||||
return ProcessResult(
|
||||
message="{0}: Successfully post-processed {1}".format(section, input_name),
|
||||
status_code=0,
|
||||
)
|
||||
else:
|
||||
logger.error("FAILED: Status for {0} has NOT been updated in Gamez".format(gamez_id), section)
|
||||
return [1, "{0}: Failed to post-process - Returned log from {1} was not as expected.".format(section, section)]
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - Returned log from {0} was not as expected.".format(section),
|
||||
status_code=1,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue