From 2950caad331f236f7f76b6a931b4047777f8673a Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Wed, 1 May 2013 13:35:26 +0930 Subject: [PATCH] add exception on logging close #83 --- TorrentToMedia.py | 23 ++++++++++------------- autoProcess/Transcoder.py | 4 ++-- autoProcess/autoProcessComics.py | 14 ++++---------- autoProcess/autoProcessGames.py | 4 ++-- autoProcess/autoProcessMovie.py | 30 +++++++++++++++--------------- autoProcess/autoProcessMusic.py | 4 ++-- autoProcess/autoProcessTV.py | 16 +++++----------- autoProcess/nzbToMediaUtil.py | 16 +++++++++------- extractor/extractor.py | 2 +- 9 files changed, 50 insertions(+), 63 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 84ce57e0..5e6c735e 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -90,16 +90,14 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): Logger.info("MAIN: Found video file %s in %s", fileExtension, filePath) try: copy_link(filePath, targetDirectory, useLink, outputDestination) - except Exception as e: - Logger.error("MAIN: Failed to link file: %s", file) - Logger.debug(e) + except: + Logger.exception("MAIN: Failed to link file: %s", file) elif fileExtension in metaContainer: Logger.info("MAIN: Found metadata file %s for file %s", fileExtension, filePath) try: copy_link(filePath, targetDirectory, useLink, outputDestination) - except Exception as e: - Logger.error("MAIN: Failed to link file: %s", file) - Logger.debug(e) + except: + Logger.exception("MAIN: Failed to link file: %s", file) elif fileExtension in compressedContainer: numCompressed = numCompressed + 1 if re.search(r'\d+', os.path.splitext(fileName)[1]) and numCompressed > 1: # find part numbers in second "extension" from right, if we have more than 1 compressed file. @@ -113,9 +111,8 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): try: extractor.extract(filePath, outputDestination) extractionSuccess = True # we use this variable to determine if we need to pause a torrent or not in uTorrent (dont need to pause archived content) - except Exception as e: - Logger.warn("MAIN: Extraction failed for: %s", file) - Logger.debug(e) + except: + Logger.exception("MAIN: Extraction failed for: %s", file) else: Logger.debug("MAIN: Ignoring unknown filetype %s for file %s", fileExtension, filePath) continue @@ -140,8 +137,8 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): try: Logger.debug("MAIN: Connecting to uTorrent: %s", uTorrentWEBui) utorrentClass = UTorrentClient(uTorrentWEBui, uTorrentUSR, uTorrentPWD) - except Exception as e: - Logger.error("MAIN: Failed to connect to uTorrent: %s", e) + except: + Logger.exception("MAIN: Failed to connect to uTorrent") # if we are using links with uTorrent it means we need to pause it in order to access the files if useLink != "no": @@ -256,8 +253,8 @@ if __name__ == "__main__": try: inputDirectory, inputName, inputCategory, inputHash, inputID = parse_args(clientAgent) - except Exception as e: - Logger.error("MAIN: There was a problem loading variables: %s", e) + except: + Logger.exception("MAIN: There was a problem loading variables") sys.exit(-1) main(inputDirectory, inputName, inputCategory, inputHash, inputID) diff --git a/autoProcess/Transcoder.py b/autoProcess/Transcoder.py index e23207e3..fd8e8f77 100644 --- a/autoProcess/Transcoder.py +++ b/autoProcess/Transcoder.py @@ -101,8 +101,8 @@ def Transcode_directory(dirName): result = 1 # set result to failed in case call fails. try: result = call(command) - except e: - Logger.error("Transcoding of video %s failed due to: ", filePath, str(e)) + except: + Logger.exception("Transcoding of video %s has failed", filePath) if result == 0: Logger.info("Transcoding of video %s to %s succeded", filePath, newfilePath) if duplicate == 0: # we get rid of the original file diff --git a/autoProcess/autoProcessComics.py b/autoProcess/autoProcessComics.py index 2ac8071c..866bda50 100644 --- a/autoProcess/autoProcessComics.py +++ b/autoProcess/autoProcessComics.py @@ -39,14 +39,8 @@ def processEpisode(dirName, nzbName=None, status=0): Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?") return 1 # failure - try: - fp = open(configFilename, "r") - config.readfp(fp) - fp.close() - except IOError, e: - Logger.error("Could not read configuration file: %s", str(e)) - return 1 # failure - + config.read(configFilename) + host = config.get("Mylar", "host") port = config.get("Mylar", "port") username = config.get("Mylar", "username") @@ -80,8 +74,8 @@ def processEpisode(dirName, nzbName=None, status=0): try: urlObj = myOpener.openit(url) - except IOError, e: - Logger.error("Unable to open URL: %s", str(e)) + except: + Logger.exception("Unable to open URL") return 1 # failure result = urlObj.readlines() diff --git a/autoProcess/autoProcessGames.py b/autoProcess/autoProcessGames.py index 836b02fe..f78d7932 100644 --- a/autoProcess/autoProcessGames.py +++ b/autoProcess/autoProcessGames.py @@ -80,8 +80,8 @@ def process(dirName, nzbName=None, status=0): try: urlObj = myOpener.openit(url) - except IOError, e: - Logger.error("Unable to open URL: %s", str(e)) + except: + Logger.exception("Unable to open URL") return 1 # failure result = json.load(urlObj) diff --git a/autoProcess/autoProcessMovie.py b/autoProcess/autoProcessMovie.py index f68a39d3..0f37755b 100644 --- a/autoProcess/autoProcessMovie.py +++ b/autoProcess/autoProcessMovie.py @@ -69,8 +69,8 @@ def get_movie_info(myOpener, baseURL, imdbid, download_id): try: urlObj = myOpener.openit(url) - except IOError, e: - Logger.error("Unable to open URL: %s", str(e)) + except: + Logger.exception("Unable to open URL") return "" movie_id = "" @@ -100,9 +100,9 @@ def get_movie_info(myOpener, baseURL, imdbid, download_id): break except: if not imdbid: - Logger.error("Could not parse database results to determine imdbid or movie id") + Logger.exception("Could not parse database results to determine imdbid or movie id") else: - Logger.error("Could not parse database results to determine movie id for imdbid: %s", imdbid) + Logger.exception("Could not parse database results to determine movie id for imdbid: %s", imdbid) return movie_id @@ -116,15 +116,15 @@ def get_status(myOpener, baseURL, movie_id, clientAgent, download_id): try: urlObj = myOpener.openit(url) - except IOError, e: - Logger.error("Unable to open URL: %s", str(e)) + except: + Logger.exception("Unable to open URL") return "", clientAgent, "none", "none" result = json.load(urlObj) try: movie_status = result["movie"]["status"]["identifier"] Logger.debug("This movie is marked as status %s in CouchPotatoServer", movie_status) - except e: # index out of range/doesn't exist? - Logger.error("Could not find a status for this movie due to: %s", str(e)) + except: # index out of range/doesn't exist? + Logger.exception("Could not find a status for this movie") movie_status = "" try: release_status = "none" @@ -180,7 +180,7 @@ def get_status(myOpener, baseURL, movie_id, clientAgent, download_id): Logger.info("Could not find a download_id in the database for this movie") release_status = "none" except: # index out of range/doesn't exist? - Logger.error("Could not find a download_id for this movie") + Logger.exception("Could not find a download_id for this movie") download_id = "none" return movie_status, clientAgent, download_id, release_status @@ -268,8 +268,8 @@ def process(dirName, nzbName=None, status=0, clientAgent = "manual", download_id try: urlObj = myOpener.openit(url) - except IOError, e: - Logger.error("Unable to open URL: %s", str(e)) + except: + Logger.exception("Unable to open URL") return 1 # failure result = json.load(urlObj) @@ -296,8 +296,8 @@ def process(dirName, nzbName=None, status=0, clientAgent = "manual", download_id try: urlObj = myOpener.openit(url) - except IOError, e: - Logger.error("Unable to open URL: %s", str(e)) + except: + Logger.exception("Unable to open URL") return 1 # failure result = urlObj.readlines() @@ -309,8 +309,8 @@ def process(dirName, nzbName=None, status=0, clientAgent = "manual", download_id Logger.info("Deleting failed files and folder %s", dirName) try: shutil.rmtree(dirName) - except e: - Logger.error("Unable to delete folder %s due to: %s", dirName, str(e)) + except: + Logger.exception("Unable to delete folder %s", dirName) return 0 # success if nzbName == "Manual Run": diff --git a/autoProcess/autoProcessMusic.py b/autoProcess/autoProcessMusic.py index 2049577b..534e18ca 100644 --- a/autoProcess/autoProcessMusic.py +++ b/autoProcess/autoProcessMusic.py @@ -85,8 +85,8 @@ def process(dirName, nzbName=None, status=0): try: urlObj = myOpener.openit(url) - except IOError, e: - Logger.error("Unable to open URL: %s", str(e)) + except: + Logger.exception("Unable to open URL") return 1 # failure result = urlObj.readlines() diff --git a/autoProcess/autoProcessTV.py b/autoProcess/autoProcessTV.py index 3b2c203f..d8c66047 100644 --- a/autoProcess/autoProcessTV.py +++ b/autoProcess/autoProcessTV.py @@ -54,8 +54,8 @@ def delete(dirName): Logger.info("Deleting failed files and folder %s", dirName) try: shutil.rmtree(dirName) - except e: - Logger.error("Unable to delete folder %s due to: %s", dirName, str(e)) + except: + Logger.exception("Unable to delete folder %s", dirName) def processEpisode(dirName, nzbName=None, failed=False): @@ -69,13 +69,7 @@ def processEpisode(dirName, nzbName=None, failed=False): Logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?") return 1 # failure - try: - fp = open(configFilename, "r") - config.readfp(fp) - fp.close() - except IOError, e: - Logger.error("Could not read configuration file: %s", str(e)) - return 1 # failure + config.read(configFilename) watch_dir = "" host = config.get("SickBeard", "host") @@ -174,8 +168,8 @@ def processEpisode(dirName, nzbName=None, failed=False): try: urlObj = myOpener.openit(url) - except IOError, e: - Logger.error("Unable to open URL: %s", str(e)) + except: + Logger.exception("Unable to open URL") return 1 # failure result = urlObj.readlines() diff --git a/autoProcess/nzbToMediaUtil.py b/autoProcess/nzbToMediaUtil.py index 39313d02..fa913695 100644 --- a/autoProcess/nzbToMediaUtil.py +++ b/autoProcess/nzbToMediaUtil.py @@ -34,8 +34,8 @@ def create_destination(outputDestination): try: Logger.info("CREATE DESTINATION: Creating destination folder: %s", outputDestination) os.makedirs(outputDestination) - except Exception, e: - Logger.error("CREATE DESTINATION: Not possible to create destination folder: %s. Exiting", e) + except: + Logger.exception("CREATE DESTINATION: Not possible to create destination folder. Exiting") sys.exit(-1) def category_search(inputDirectory, inputName, inputCategory, root, categories): @@ -155,10 +155,11 @@ def copy_link(filePath, targetDirectory, useLink, outputDestination): Logger.info("COPYLINK: Hard linking %s to %s", filePath, targetDirectory) linktastic.link(filePath, targetDirectory) except: + Logger.exception("COPYLINK") if os.path.isfile(targetDirectory): - Logger.info("COPYLINK: Something went wrong in linktastic.link, but the destination file was created") + Logger.warn("COPYLINK: Something went wrong in linktastic.link, but the destination file was created") else: - Logger.info("COPYLINK: Something went wrong in linktastic.link, copying instead") + Logger.warn("COPYLINK: Something went wrong in linktastic.link, copying instead") Logger.debug("COPYLINK: Copying %s to %s", filePath, targetDirectory) shutil.copy(filePath, targetDirectory) elif useLink == "sym": @@ -168,8 +169,9 @@ def copy_link(filePath, targetDirectory, useLink, outputDestination): Logger.info("COPYLINK: Sym linking %s to %s", targetDirectory, filePath) linktastic.symlink(targetDirectory, filePath) except: + Logger.exception("COPYLINK") if os.path.isfile(targetDirectory): - Logger.info("COPYLINK: Something went wrong in linktastic.link, but the destination file was created") + Logger.warn("COPYLINK: Something went wrong in linktastic.link, but the destination file was created") else: Logger.info("COPYLINK: Something went wrong in linktastic.link, copying instead") Logger.debug("COPYLINK: Copying %s to %s", filePath, targetDirectory) @@ -190,8 +192,8 @@ def flatten(outputDestination): target = os.path.join(outputDestination, filename) try: shutil.move(source, target) - except OSError: - Logger.error("FLATTEN: Could not flatten %s", source) + except: + Logger.exception("FLATTEN: Could not flatten %s", source) removeEmptyFolders(outputDestination) # Cleanup empty directories diff --git a/extractor/extractor.py b/extractor/extractor.py index eae4acf2..76a9eeb2 100644 --- a/extractor/extractor.py +++ b/extractor/extractor.py @@ -124,6 +124,6 @@ def extract(filePath, outputDestination): else: Logger.error("EXTRACTOR: Extraction failed for %s. 7zip result was %s", filePath, res) except: - Logger.error("EXTRACTOR: Extraction failed for %s. Could not call command %s", filePath, cmd) + Logger.exception("EXTRACTOR: Extraction failed for %s. Could not call command %s", filePath, cmd) os.chdir(pwd) # Go back to our Original Working Directory return True