From de89fb2ce0a3791742767f7de5b33d797f81b52a Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 17 Jul 2014 10:27:55 +0930 Subject: [PATCH] add printed return message. Fixes #493 Fixes #495 Fixes#496 --- TorrentToMedia.py | 20 +++++------ nzbToMedia.py | 26 +++++++++------ nzbtomedia/autoProcess/autoProcessComics.py | 10 +++--- nzbtomedia/autoProcess/autoProcessGames.py | 12 +++---- nzbtomedia/autoProcess/autoProcessMovie.py | 37 +++++++++++---------- nzbtomedia/autoProcess/autoProcessMusic.py | 14 ++++---- nzbtomedia/autoProcess/autoProcessTV.py | 16 ++++----- 7 files changed, 71 insertions(+), 64 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 7ab5b551..b82e3f31 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -56,7 +56,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, logger.error( 'Category:[%s] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.' % ( inputCategory)) - return -1 + return [-1, ""] else: usercat = "ALL" @@ -64,7 +64,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, logger.error( 'Category:[%s] is not unique, %s are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' % ( usercat, section.keys())) - return -1 + return [-1, ""] if section: sectionName = section.keys()[0] @@ -72,7 +72,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, else: logger.error("Unable to locate a section with subsection:%s enabled in your autoProcessMedia.cfg, exiting!" % ( inputCategory)) - return -1 + return [-1, ""] try: Torrent_NoLink = int(section[usercat]["Torrent_NoLink"]) @@ -105,7 +105,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, logger.error( 'The output directory:[%s] is the Download Directory. Edit outputDirectory in autoProcessMedia.cfg. Exiting' % ( inputDirectory)) - return -1 + return [-1, ""] logger.debug("Scanning files in directory: %s" % (inputDirectory)) @@ -187,7 +187,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, logger.info("Calling %s:%s to post-process:%s" % (sectionName, usercat, inputName)) - result = 0 + result = [ 0, "" ] if sectionName == 'UserScript': result = external_script(outputDestination, inputName, inputCategory, section[usercat]) @@ -205,7 +205,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, elif sectionName == 'Gamez': result = nzbtomedia.autoProcessGames().process(sectionName,outputDestination, inputName, status, clientAgent, inputCategory) - if result != 0: + if result[0] != 0: if clientAgent != 'manual': logger.error( "A problem was reported in the autoProcess* script. If torrent was paused we will resume seeding") @@ -240,7 +240,7 @@ def main(args): logger.debug("Options passed into TorrentToMedia: %s" % (args)) # Post-Processing Result - result = 0 + result = [ 0, "" ] try: inputDirectory, inputName, inputCategory, inputHash, inputID = nzbtomedia.parse_args(clientAgent, args) @@ -288,17 +288,17 @@ def main(args): results = processTorrent(dirName, os.path.basename(dirName), subsection, inputHash, inputID, clientAgent) - if results != 0: + if results[0] != 0: logger.error("A problem was reported when trying to perform a manual run for %s:%s." % ( section, subsection)) result = results - if result == 0: + if result[0] == 0: logger.info("The %s script completed successfully." % (args[0])) else: logger.error("A problem was reported in the %s script." % (args[0])) del nzbtomedia.MYAPP - return result + return result[0] if __name__ == "__main__": diff --git a/nzbToMedia.py b/nzbToMedia.py index 74f236ce..025fb845 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -499,7 +499,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down logger.error( 'The input directory:[%s] is the Default Download Directory. Please configure category directories to prevent processing of other media.' % ( inputDirectory)) - return -1 + return [-1, ""] if clientAgent != 'manual' and not nzbtomedia.DOWNLOADINFO: logger.debug('Adding NZB download info for directory %s to database' % (inputDirectory)) @@ -530,7 +530,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down logger.error( 'Category:[%s] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.' % ( inputCategory)) - return -1 + return [-1, ""] else: usercat = "ALL" @@ -538,7 +538,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down logger.error( 'Category:[%s] is not unique, %s are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' % ( inputCategory, section.keys())) - return -1 + return [-1, ""] if section: sectionName = section.keys()[0] @@ -546,7 +546,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down else: logger.error("Unable to locate a section with subsection:%s enabled in your autoProcessMedia.cfg, exiting!" % ( inputCategory)) - return -1 + return [-1, ""] try: extract = int(section[usercat]['extract']) @@ -557,7 +557,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down if int(section[usercat]['remote_path']) and not nzbtomedia.REMOTEPATHS: logger.error('Remote Path is enabled for %s:%s but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!' % ( sectionName, inputCategory)) - return -1 + return [-1, ""] except: logger.error('Remote Path %s is not valid for %s:%s Please set this to either 0 to disable or 1 to enable!' % ( section[usercat]['remote_path'], sectionName, inputCategory)) @@ -586,9 +586,9 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down elif sectionName == 'UserScript': result = external_script(inputDirectory, inputName, inputCategory, section[usercat]) else: - result = -1 + result = [-1, ""] - if result == 0: + if result[0] == 0: if clientAgent != 'manual': # update download status in our DB update_downloadInfoStatus(inputName, 1) @@ -614,7 +614,7 @@ def main(args, section=None): logger.debug("Options passed into nzbToMedia: %s" % args) # Post-Processing Result - result = 0 + result = [0, ""] status = 0 # NZBGet @@ -729,23 +729,27 @@ def main(args, section=None): results = process(dirName, os.path.basename(dirName), 0, clientAgent=clientAgent, download_id=download_id, inputCategory=subsection) - if results != 0: + if results[0] != 0: logger.error("A problem was reported when trying to perform a manual run for %s:%s." % ( section, subsection)) result = results - if result == 0: + if result[0] == 0: logger.info("The %s script completed successfully." % args[0]) + if result[1]: + print result[1] # For SABnzbd Status display. if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 del nzbtomedia.MYAPP return (nzbtomedia.NZBGET_POSTPROCESS_SUCCESS) else: logger.error("A problem was reported in the %s script." % args[0]) + if result[1]: + print result[1] # For SABnzbd Status display. if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 del nzbtomedia.MYAPP return (nzbtomedia.NZBGET_POSTPROCESS_ERROR) del nzbtomedia.MYAPP - return (result) + return (result[0]) if __name__ == '__main__': diff --git a/nzbtomedia/autoProcess/autoProcessComics.py b/nzbtomedia/autoProcess/autoProcessComics.py index 628b5670..5bb09eb3 100644 --- a/nzbtomedia/autoProcess/autoProcessComics.py +++ b/nzbtomedia/autoProcess/autoProcessComics.py @@ -11,7 +11,7 @@ class autoProcessComics: def processEpisode(self, section, dirName, inputName=None, status=0, clientAgent='manual', inputCategory=None): if int(status) != 0: logger.warning("FAILED DOWNLOAD DETECTED, nothing to process.",section) - return 0 + return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section) ] host = nzbtomedia.CFG[section][inputCategory]["host"] port = nzbtomedia.CFG[section][inputCategory]["port"] @@ -58,18 +58,18 @@ class autoProcessComics: r = requests.get(url, auth=(username, password), params=params, stream=True, verify=False) except requests.ConnectionError: logger.error("Unable to open URL", section) - return 1 # failure + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] for line in r.iter_lines(): if line: logger.postprocess("%s" % (line), section) if ("Post Processing SUCCESSFUL!" or "Post Processing SUCCESSFULL!")in line: success = True if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return 1 + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] if success: logger.postprocess("SUCCESS: This issue has been processed successfully",section) - return 0 + return [0, "%s: Successfully post-processed %s" % (section, inputName) ] else: logger.warning("The issue does not appear to have successfully processed. Please check your Logs",section) - return 1 # failure + return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section) ] diff --git a/nzbtomedia/autoProcess/autoProcessGames.py b/nzbtomedia/autoProcess/autoProcessGames.py index 6f429165..7678124b 100644 --- a/nzbtomedia/autoProcess/autoProcessGames.py +++ b/nzbtomedia/autoProcess/autoProcessGames.py @@ -54,7 +54,7 @@ class autoProcessGames: r = requests.get(url, params=params, verify=False) except requests.ConnectionError: logger.error("Unable to open URL") - return 1 # failure + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] result = r.json() logger.postprocess("%s" % (result),section) @@ -64,17 +64,17 @@ class autoProcessGames: shutil.move(dirName, os.path.join(library, inputName)) except: logger.error("Unable to move %s to %s" % (dirName, os.path.join(library, inputName)), section) - return 1 + return [1, "%s: Failed to post-process - Unable to move files" % (section) ] else: logger.error("No library specified to move files to. Please edit your configuration.", section) - return 1 + return [1, "%s: Failed to post-process - No library defined in %s" % (section, section) ] if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return 1 + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] elif result['success']: logger.postprocess("SUCCESS: Status for %s has been set to %s in Gamez" % (gamezID, downloadStatus),section) - return 0 # Success + return [0, "%s: Successfully post-processed %s" % (section, inputName) ] else: logger.error("FAILED: Status for %s has NOT been updated in Gamez" % (gamezID),section) - return 1 # failure + return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section) ] diff --git a/nzbtomedia/autoProcess/autoProcessMovie.py b/nzbtomedia/autoProcess/autoProcessMovie.py index dc22377c..3a09762a 100644 --- a/nzbtomedia/autoProcess/autoProcessMovie.py +++ b/nzbtomedia/autoProcess/autoProcessMovie.py @@ -185,7 +185,7 @@ class autoProcessMovie: status = 1 elif clientAgent == "manual": logger.warning("No media files found in directory %s to manually process." % (dirName), section) - return 0 # Success (as far as this script is concerned) + return [0, ""] # Success (as far as this script is concerned) else: logger.warning("No media files found in directory %s. Processing this as a failed download" % (dirName), section) status = 1 @@ -223,18 +223,18 @@ class autoProcessMovie: r = requests.get(url, params=params, verify=False) except requests.ConnectionError: logger.error("Unable to open URL", section) - return 1 # failure + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] result = r.json() if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return 1 + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] elif result['success']: logger.postprocess("SUCCESS: Finished %s scan for folder %s" % (method, dirName), section) else: logger.error("FAILED: %s scan was unable to finish for folder %s. exiting!" % (method, dirName), section) - return 1 # failure + return [1, "%s: Failed to post-process - Server did not return success" % (section) ] else: logger.postprocess("FAILED DOWNLOAD DETECTED FOR %s" % (inputName), section) @@ -246,7 +246,7 @@ class autoProcessMovie: if not download_id: logger.error("Could not find a downloaded movie in the database matching %s, exiting!" % inputName, section) - return 1 # failure + return [1, "%s: Failed to post-process - Failed download not found in %s" % (section, section) ] logger.postprocess("Setting failed release %s to ignored ..." % (inputName), section) @@ -259,14 +259,17 @@ class autoProcessMovie: r = requests.get(url, params=params, verify=False) except requests.ConnectionError: logger.error("Unable to open URL %s" % (url), section) - return 1 # failure + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] result = r.json() - if result['success']: + if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: + logger.error("Server returned status %s" % (str(r.status_code)), section) + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] + elif result['success']: logger.postprocess("SUCCESS: %s has been set to ignored ..." % (inputName), section) else: logger.warning("FAILED: Unable to set %s to ignored!" % (inputName), section) - return 1 + return [1, "%s: Failed to post-process - Unable to set %s to ignored" % (section, inputName) ] logger.postprocess("Trying to snatch the next highest ranked release.", section) @@ -277,18 +280,18 @@ class autoProcessMovie: r = requests.get(url, params={'media_id': media_id}) except requests.ConnectionError: logger.error("Unable to open URL %s" % (url), section) - return 1 # failure + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] result = r.json() if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return 1 + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] elif result['success']: logger.postprocess("SUCCESS: Snatched the next highest release ...", section) - return 0 + return [0, "%s: Successfully snatched next highest release" % (section) ] else: logger.postprocess("SUCCESS: Unable to find a new release to snatch now. CP will keep searching!", section) - return 0 # + return [0, "%s: No new release found now. %s will keep searching" % (section, section) ] # Added a releease that was not in the wanted list so confirm rename successful by finding this movie media.list. if not release: @@ -303,24 +306,24 @@ class autoProcessMovie: try: if release_id is None and release_status_old is None: # we didn't have a release before, but now we do. logger.postprocess("SUCCESS: Movie %s has now been added to CouchPotato" % (imdbid), section) - return 0 # success + return [0, "%s: Successfully post-processed %s" % (section, inputName) ] release_status_new = release[release_id]['status'] if release_status_new != release_status_old: logger.postprocess("SUCCESS: Release %s has now been marked with a status of [%s]" % ( inputName, str(release_status_new).upper()), section) - return 0 # success + return [0, "%s: Successfully post-processed %s" % (section, inputName) ] except: pass if not os.path.isdir(dirName): logger.postprocess("SUCCESS: Input Directory [%s] has been processed and removed" % ( dirName), section) - return 0 + return [0, "%s: Successfully post-processed %s" % (section, inputName) ] elif not listMediaFiles(dirName, media=True, audio=False, meta=False, archives=True): logger.postprocess("SUCCESS: Input Directory [%s] has no remaining media files. This has been fully processed." % ( dirName), section) - return 0 + return [0, "%s: Successfully post-processed %s" % (section, inputName) ] # pause and let CouchPotatoServer catch its breath time.sleep(10 * wait_for) @@ -329,4 +332,4 @@ class autoProcessMovie: logger.warning( "%s does not appear to have changed status after %s minutes, Please check your logs." % (inputName, wait_for), section) - return 1 # failure + return [1, "%s: Failed to post-process - No change in status" % (section) ] diff --git a/nzbtomedia/autoProcess/autoProcessMusic.py b/nzbtomedia/autoProcess/autoProcessMusic.py index 40dad8fc..c625c453 100644 --- a/nzbtomedia/autoProcess/autoProcessMusic.py +++ b/nzbtomedia/autoProcess/autoProcessMusic.py @@ -102,22 +102,22 @@ class autoProcessMusic: r = requests.get(url, params=params, verify=False) except requests.ConnectionError: logger.error("Unable to open URL %s" % (url) ,section) - return 1 # failure + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] logger.debug("Result: %s" % (r.text),section) if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return 1 + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] elif r.text == "OK": logger.postprocess("SUCCESS: Post-Processing started for %s in folder %s ..." % (inputName, dirName),section) else: logger.error("FAILED: Post-Processing has NOT started for %s in folder %s. exiting!" % (inputName, dirName),section) - return 1 # failure + return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section) ] else: logger.warning("FAILED DOWNLOAD DETECTED", section) - return 0 # Success (as far as this script is concerned) + return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section) ] # we will now wait for this album to be processed before returning to TorrentToMedia and unpausing. timeout = time.time() + 60 * wait_for @@ -125,12 +125,12 @@ class autoProcessMusic: current_status = self.get_status(url, apikey, dirName) if current_status is not None and current_status != release_status: # Something has changed. CPS must have processed this movie. logger.postprocess("SUCCESS: This release is now marked as status [%s]" % (current_status),section) - return 0 + return [0, "%s: Successfully post-processed %s" % (section, inputName) ] if not os.path.isdir(dirName): logger.postprocess("SUCCESS: The input directory %s has been removed Processing must have finished." % (dirName),section) - return 0 + return [0, "%s: Successfully post-processed %s" % (section, inputName) ] time.sleep(10 * wait_for) # The status hasn't changed. uTorrent can resume seeding now. logger.warning("The music album does not appear to have changed status after %s minutes. Please check your Logs" % (wait_for),section) - return 1 # failure + return [1, "%s: Failed to post-process - No change in wanted status" % (section) ] diff --git a/nzbtomedia/autoProcess/autoProcessTV.py b/nzbtomedia/autoProcess/autoProcessTV.py index 6f221ce0..7da5cbcc 100644 --- a/nzbtomedia/autoProcess/autoProcessTV.py +++ b/nzbtomedia/autoProcess/autoProcessTV.py @@ -147,7 +147,7 @@ class autoProcessTV: flatten(dirName) elif clientAgent == "manual": logger.warning("No media files found in directory %s to manually process." % (dirName), section) - return 0 # Success (as far as this script is concerned) + return [0, ""] # Success (as far as this script is concerned) else: logger.warning("No media files found in directory %s. Processing this as a failed download" % (dirName), section) status = 1 @@ -192,7 +192,7 @@ class autoProcessTV: if delete_failed and os.path.isdir(dirName) and not os.path.dirname(dirName) == dirName: logger.postprocess("Deleting failed files and folder %s" % (dirName), section) rmDir(dirName) - return 0 # Success (as far as this script is concerned) + return [1, "%s: Failed to post-process. %s does not support failed downloads" % (section, section) ] # Return as failed to flag this in the downloader. if status == 0 and nzbtomedia.TRANSCODE == 1: # only transcode successful downlaods result, newDirName = transcoder.Transcode_directory(dirName) @@ -234,11 +234,11 @@ class autoProcessTV: r = requests.post(url, data=data, headers=headers, stream=True, verify=False) except requests.ConnectionError: logger.error("Unable to open URL: %s" % (url), section) - return 1 # failure + return [1, "%s: Failed to post-process - Unable to connect to %s" % (section, section) ] if not r.status_code in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error("Server returned status %s" % (str(r.status_code)), section) - return 1 + return [1, "%s: Failed to post-process - Server returned status %s" % (section, str(r.status_code)) ] Success = False Started = False @@ -255,7 +255,7 @@ class autoProcessTV: rmDir(dirName) if Success: - return 0 + return [0, "%s: Successfully post-processed %s" % (section, inputName) ] elif section == "NzbDrone" and Started: n = 0 current_numMissing = start_numMissing @@ -277,12 +277,12 @@ class autoProcessTV: logger.debug( "The number of missing episodes changes from %s to %s and then remained the same for %s minutes. Consider this successful" % (str(start_numMissing), str(current_numMissing), str(wait_for)), section) - return 0 + return [0, "%s: Successfully post-processed %s" % (section, inputName) ] else: # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resume seeding now. logger.warning( "The number of missing episodes: %s does not appear to have changed status after %s minutes, Please check your logs." % (str(start_numMissing), str(wait_for)), section) - return 1 + return [1, "%s: Failed to post-process - No change in wanted status" % (section) ] else: - return 1 # We did not receive Success confirmation. + return [1, "%s: Failed to post-process - Returned log from %s was not as expected." % (section, section) ] # We did not receive Success confirmation.