add exception on logging close #83

This commit is contained in:
clinton-hall 2013-05-01 13:35:26 +09:30
parent b363473463
commit 2950caad33
9 changed files with 50 additions and 63 deletions

View file

@ -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)

View file

@ -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

View file

@ -39,13 +39,7 @@ 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")
@ -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()

View file

@ -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)

View file

@ -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":

View file

@ -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()

View file

@ -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()

View file

@ -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

View file

@ -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