From a81464502e9bde5b468a76d0b09415852d25437d Mon Sep 17 00:00:00 2001 From: echel0n Date: Fri, 25 Apr 2014 10:19:43 -0700 Subject: [PATCH] Fixes issue with KeyErrors recently being returned --- TorrentToMedia.py | 5 +---- nzbtomedia/autoProcess/autoProcessTV.py | 1 + nzbtomedia/nzbToMediaConfig.py | 16 ++++++++++++---- tests/general.py | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index cbd9ae98..fc5bc042 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -174,10 +174,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, if sectionName == 'CouchPotato': result = nzbtomedia.autoProcessMovie().process(sectionName,outputDestination, inputName, status, clientAgent, inputHash, inputCategory) - elif sectionName == 'SickBeard': - result = nzbtomedia.autoProcessTV().processEpisode(sectionName,outputDestination, inputName, status, clientAgent, - inputCategory) - elif sectionName == 'NzbDrone': + elif sectionName in ['SickBeard','NzbDrone']: result = nzbtomedia.autoProcessTV().processEpisode(sectionName,outputDestination, inputName, status, clientAgent, inputCategory) elif sectionName == 'HeadPhones': diff --git a/nzbtomedia/autoProcess/autoProcessTV.py b/nzbtomedia/autoProcess/autoProcessTV.py index c973171d..d9f12d6f 100644 --- a/nzbtomedia/autoProcess/autoProcessTV.py +++ b/nzbtomedia/autoProcess/autoProcessTV.py @@ -153,4 +153,5 @@ class autoProcessTV: if status != 0 and delete_failed and not os.path.dirname(dirName) == dirName: logger.postprocess("Deleting failed files and folder %s" % (dirName),section) rmDir(dirName) + return 0 # Success diff --git a/nzbtomedia/nzbToMediaConfig.py b/nzbtomedia/nzbToMediaConfig.py index 9cff604d..ce162dfb 100644 --- a/nzbtomedia/nzbToMediaConfig.py +++ b/nzbtomedia/nzbToMediaConfig.py @@ -23,8 +23,10 @@ class Section(configobj.Section): if not int(subsections['enabled']) == 1: del to_return[section_name] - if len(to_return[section_name]) == 0: - del to_return[section_name] + # cleanout empty sections and subsections + for key in [k for (k, v) in to_return.items() if not v]: + del to_return[key] + return to_return def findsection(section, key): @@ -32,6 +34,11 @@ class Section(configobj.Section): for subsection in to_return: if key not in to_return[subsection]: del to_return[subsection] + + # cleanout empty sections and subsections + for key in [k for (k, v) in to_return.items() if not v]: + del to_return[key] + return to_return def __getitem__(self, key): @@ -54,8 +61,9 @@ class Section(configobj.Section): if section not in key: del to_return[section] - if len(subsections) == 0: - del to_return[section] + # cleanout empty sections and subsections + for key in [k for (k, v) in to_return.items() if not v]: + del to_return[key] return to_return diff --git a/tests/general.py b/tests/general.py index 580e2190..4ff867f2 100644 --- a/tests/general.py +++ b/tests/general.py @@ -8,6 +8,6 @@ from nzbtomedia.nzbToMediaUtil import get_downloadInfo # Initialize the config nzbtomedia.initialize() -test = nzbtomedia.CFG['HeadPhones']['music'] +test = nzbtomedia.CFG['SickBeard','NzbDrone']['tv'] section = nzbtomedia.CFG.findsection('tv').isenabled() print section \ No newline at end of file