mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 13:53:15 -07:00
better exception handling.
This commit is contained in:
parent
1e3764635c
commit
49842ac52a
1 changed files with 11 additions and 12 deletions
|
@ -484,8 +484,7 @@ def getDirs(section, subsection):
|
||||||
for mediafile in [ os.path.join(path, o) for o in os.listdir(path) if
|
for mediafile in [ os.path.join(path, o) for o in os.listdir(path) if
|
||||||
os.path.isfile(os.path.join(path, o)) ]:
|
os.path.isfile(os.path.join(path, o)) ]:
|
||||||
try:
|
try:
|
||||||
encoded, mediafile2 = CharReplace(mediafile)
|
logger.debug("Found file %s in root directory %s." % (os.path.split(mediafile)[1], path))
|
||||||
logger.debug("Found file %s in root directory %s." % (os.path.split(mediafile2)[1], path))
|
|
||||||
newPath = None
|
newPath = None
|
||||||
fileExt = os.path.splitext(mediafile)[1]
|
fileExt = os.path.splitext(mediafile)[1]
|
||||||
try:
|
try:
|
||||||
|
@ -509,14 +508,14 @@ def getDirs(section, subsection):
|
||||||
title = f['title']
|
title = f['title']
|
||||||
|
|
||||||
if not title:
|
if not title:
|
||||||
title = os.path.splitext(os.path.basename(mediafile2))[0]
|
title = os.path.splitext(os.path.basename(mediafile))[0]
|
||||||
|
|
||||||
newPath = os.path.join(path, sanitizeName(title))
|
newPath = os.path.join(path, sanitizeName(title))
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.error("Exception parsing name for media file: %s: %s" % (os.path.split(mediafile2)[1], e))
|
logger.error("Exception parsing name for media file: %s: %s" % (os.path.split(mediafile2)[1], e))
|
||||||
|
|
||||||
if not newPath:
|
if not newPath:
|
||||||
title = os.path.splitext(os.path.basename(mediafile2))[0]
|
title = os.path.splitext(os.path.basename(mediafile))[0]
|
||||||
newPath = os.path.join(path, sanitizeName(title))
|
newPath = os.path.join(path, sanitizeName(title))
|
||||||
|
|
||||||
# Just fail-safe incase we already have afile with this clean-name (was actually a bug from earlier code, but let's be safe).
|
# Just fail-safe incase we already have afile with this clean-name (was actually a bug from earlier code, but let's be safe).
|
||||||
|
@ -529,9 +528,9 @@ def getDirs(section, subsection):
|
||||||
makeDir(newPath)
|
makeDir(newPath)
|
||||||
|
|
||||||
# link file to its new path
|
# link file to its new path
|
||||||
copy_link(mediafile, os.path.join(newPath, sanitizeName(os.path.split(mediafile2)[1])), 'hard')
|
copy_link(mediafile, os.path.join(newPath, sanitizeName(os.path.split(mediafile)[1])), 'hard')
|
||||||
except:
|
except Exception as e:
|
||||||
logger.error("Failed to move %s to its own directory" % (os.path.split(mediafile2)[1]))
|
logger.error("Failed to move %s to its own directory: %s" % (os.path.split(mediafile)[1], e))
|
||||||
|
|
||||||
removeEmptyFolders(path, removeRoot=False)
|
removeEmptyFolders(path, removeRoot=False)
|
||||||
|
|
||||||
|
@ -546,15 +545,15 @@ def getDirs(section, subsection):
|
||||||
to_return.extend(processDir(watch_dir))
|
to_return.extend(processDir(watch_dir))
|
||||||
elif os.path.exists(nzbtomedia.CFG[section][subsection]["watch_dir"]):
|
elif os.path.exists(nzbtomedia.CFG[section][subsection]["watch_dir"]):
|
||||||
to_return.extend(processDir(nzbtomedia.CFG[section][subsection]["watch_dir"]))
|
to_return.extend(processDir(nzbtomedia.CFG[section][subsection]["watch_dir"]))
|
||||||
except:
|
except Exception as e:
|
||||||
logger.error("Failed to add directories from %s for post-processing." % (nzbtomedia.CFG[section][subsection]["watch_dir"]))
|
logger.error("Failed to add directories from %s for post-processing: %s" % (nzbtomedia.CFG[section][subsection]["watch_dir"], e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
outputDirectory = os.path.join(nzbtomedia.OUTPUTDIRECTORY, subsection)
|
outputDirectory = os.path.join(nzbtomedia.OUTPUTDIRECTORY, subsection)
|
||||||
if os.path.exists(outputDirectory):
|
if os.path.exists(outputDirectory):
|
||||||
to_return.extend(processDir(outputDirectory))
|
to_return.extend(processDir(outputDirectory))
|
||||||
except:
|
except Exception as e:
|
||||||
logger.error("Failed to add directories from %s for post-processing." % (nzbtomedia.OUTPUTDIRECTORY))
|
logger.error("Failed to add directories from %s for post-processing: %s" % (nzbtomedia.OUTPUTDIRECTORY, e))
|
||||||
|
|
||||||
if not to_return:
|
if not to_return:
|
||||||
logger.debug("No directories identified in %s:%s for post-processing" % (section,subsection))
|
logger.debug("No directories identified in %s:%s for post-processing" % (section,subsection))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue