mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 02:26:53 -07:00
Fixed enable/disable check.
Added few more helper functions to our config class.
This commit is contained in:
parent
191be4ea57
commit
c9898e0e87
14 changed files with 53 additions and 49 deletions
|
@ -465,9 +465,12 @@ if __name__ == "__main__":
|
|||
if inputDirectory is None:
|
||||
for section, subsection in subsections.iteritems():
|
||||
for category in subsection:
|
||||
dirNames = get_dirnames(section, category)
|
||||
Logger.info("MAIN: TorrentToMedia running %s:%s as a manual run...", section, category)
|
||||
for dirName in dirNames:
|
||||
main(dirName, os.path.basename(dirName), category, inputHash, inputID)
|
||||
if config.isenabled(section, category):
|
||||
dirNames = get_dirnames(section, category)
|
||||
Logger.info("MAIN: TorrentToMedia running %s:%s as a manual run...", section, category)
|
||||
for dirName in dirNames:
|
||||
main(dirName, os.path.basename(dirName), category, inputHash, inputID)
|
||||
else:
|
||||
Logger.info("MAIN: nzbTo%s %s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...",section, section, category)
|
||||
else:
|
||||
main(inputDirectory, inputName, inputCategory, inputHash, inputID)
|
||||
|
|
|
@ -238,7 +238,7 @@ else:
|
|||
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||
for section, subsection in subsections.items():
|
||||
for category in subsection:
|
||||
if int(config()[section][category]['enabled']) == 1:
|
||||
if config.isenabled(section, category):
|
||||
dirNames = get_dirnames(section, category)
|
||||
for dirName in dirNames:
|
||||
Logger.info("MAIN: nzbToCouchPotato running %s:%s as a manual run...", section, subsection)
|
||||
|
|
|
@ -168,7 +168,7 @@ else:
|
|||
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||
for section, subsection in subsections.items():
|
||||
for category in subsection:
|
||||
if int(config()[section][category]['enabled']) == 1:
|
||||
if config.isenabled(section, category):
|
||||
dirNames = get_dirnames(section, category)
|
||||
for dirName in dirNames:
|
||||
Logger.info("MAIN: nzbToGamez running %s:%s as a manual run...", section, category)
|
||||
|
|
|
@ -178,7 +178,7 @@ else:
|
|||
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||
for section, subsection in subsections.items():
|
||||
for category in subsection:
|
||||
if int(config()[section][category]['enabled']) == 1:
|
||||
if config.isenabled(section, category):
|
||||
dirNames = get_dirnames(section, category)
|
||||
for dirName in dirNames:
|
||||
Logger.info("MAIN: nzbToHeadPhones running %s:%s as a manual run...", section, category)
|
||||
|
|
|
@ -448,7 +448,7 @@ else:
|
|||
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||
for section, subsection in subsections.items():
|
||||
for category in subsection:
|
||||
if int(config()[section][category]['enabled']) == 1:
|
||||
if config.isenabled(section, category):
|
||||
dirNames = get_dirnames(section, category)
|
||||
for dirName in dirNames:
|
||||
Logger.info("MAIN: nzbToMedia running %s:%s as a manual run...", section, category)
|
||||
|
|
|
@ -170,7 +170,7 @@ else:
|
|||
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||
for section, subsection in subsections.items():
|
||||
for category in subsection:
|
||||
if int(config()[section][category]['enabled']) == 1:
|
||||
if config.isenabled(section, category):
|
||||
dirNames = get_dirnames(section, category)
|
||||
for dirName in dirNames:
|
||||
Logger.info("MAIN: nzbToMylar running %s:%s as a manual run...", section, category)
|
||||
|
|
|
@ -202,7 +202,7 @@ else:
|
|||
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||
for section, subsection in subsections.items():
|
||||
for category in subsection:
|
||||
if int(config()[section][category]['enabled']) == 1:
|
||||
if config.isenabled(section, category):
|
||||
dirNames = get_dirnames(section, category)
|
||||
for dirName in dirNames:
|
||||
Logger.info("MAIN: nzbToNzbDrone running %s:%s as a manual run...", section, category)
|
||||
|
|
|
@ -235,7 +235,7 @@ else:
|
|||
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||
for section, subsection in subsections.items():
|
||||
for category in subsection:
|
||||
if int(config()[section][category]['enabled']) == 1:
|
||||
if config.isenabled(section,category):
|
||||
dirNames = get_dirnames(section, category)
|
||||
for dirName in dirNames:
|
||||
Logger.info("MAIN: nzbTo%s running %s:%s as a manual run...", section, section, category)
|
||||
|
|
|
@ -15,12 +15,8 @@ class autoProcessComics:
|
|||
return 1 # failure
|
||||
|
||||
# auto-detect correct section
|
||||
secCount, section = [x for x in enumerate(config.issubsection(inputCategory)) if int(config()[x[1]][inputCategory]['enabled']) == 1][0]
|
||||
if secCount > 1:
|
||||
Logger.error(
|
||||
"MAIN: You can't have multiple sub-sections with the same name enabled, fix your autoProcessMedia.cfg file.")
|
||||
return 1
|
||||
elif secCount == 0:
|
||||
section = config.issubsection(inputCategory, checkenabled=True)
|
||||
if len(section) == 0:
|
||||
Logger.error(
|
||||
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||
return 1
|
||||
|
|
|
@ -14,17 +14,12 @@ class autoProcessGames:
|
|||
return 1 # failure
|
||||
|
||||
# auto-detect correct section
|
||||
secCount, section = [x for x in enumerate(config.issubsection(inputCategory)) if int(config()[x[1]][inputCategory]['enabled']) == 1][0]
|
||||
if secCount > 1:
|
||||
Logger.error(
|
||||
"MAIN: You can't have multiple sub-sections with the same name enabled, fix your autoProcessMedia.cfg file.")
|
||||
return 1
|
||||
elif secCount == 0:
|
||||
section = config.issubsection(inputCategory, checkenabled=True)
|
||||
if len(section) == 0:
|
||||
Logger.error(
|
||||
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||
return 1
|
||||
|
||||
|
||||
socket.setdefaulttimeout(int(config.NZBTOMEDIA_TIMEOUT)) #initialize socket timeout.
|
||||
|
||||
Logger.info("Loading config from %s", config.CONFIG_FILE)
|
||||
|
|
|
@ -166,12 +166,8 @@ class autoProcessMovie:
|
|||
return 1 # failure
|
||||
|
||||
# auto-detect correct section
|
||||
secCount, section = [x for x in enumerate(config.issubsection(inputCategory)) if int(config()[x[1]][inputCategory]['enabled']) == 1][0]
|
||||
if secCount > 1:
|
||||
Logger.error(
|
||||
"MAIN: You can't have multiple sub-sections with the same name enabled, fix your autoProcessMedia.cfg file.")
|
||||
return 1
|
||||
elif secCount == 0:
|
||||
section = config.issubsection(inputCategory, checkenabled=True)
|
||||
if len(section) == 0:
|
||||
Logger.error(
|
||||
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||
return 1
|
||||
|
|
|
@ -15,12 +15,8 @@ class autoProcessMusic:
|
|||
return 1 # failure
|
||||
|
||||
# auto-detect correct section
|
||||
secCount, section = [x for x in enumerate(config.issubsection(inputCategory)) if int(config()[x[1]][inputCategory]['enabled']) == 1][0]
|
||||
if secCount > 1:
|
||||
Logger.error(
|
||||
"MAIN: You can't have multiple sub-sections with the same name enabled, fix your autoProcessMedia.cfg file.")
|
||||
return 1
|
||||
elif secCount == 0:
|
||||
section = config.issubsection(inputCategory,checkenabled=True)
|
||||
if len(section) == 0:
|
||||
Logger.error(
|
||||
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||
return 1
|
||||
|
|
|
@ -21,12 +21,8 @@ class autoProcessTV:
|
|||
return 1 # failure
|
||||
|
||||
# auto-detect correct section
|
||||
secCount, section = [x for x in enumerate(config.issubsection(inputCategory)) if int(config()[x[1]][inputCategory]['enabled']) == 1][0]
|
||||
if secCount > 1:
|
||||
Logger.error(
|
||||
"MAIN: You can't have multiple sub-sections with the same name enabled, fix your autoProcessMedia.cfg file.")
|
||||
return 1
|
||||
elif secCount == 0:
|
||||
section = config.issubsection(inputCategory, checkenabled=True)
|
||||
if len(section) == 0:
|
||||
Logger.error(
|
||||
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||
return 1
|
||||
|
|
|
@ -51,22 +51,28 @@ class config(object):
|
|||
return
|
||||
|
||||
@staticmethod
|
||||
def issubsection(subsection, sections=None):
|
||||
def issubsection(inputCategory, sections=None, checkenabled=False):
|
||||
# checks if the inputCategory belongs to the section
|
||||
# or returns sections with subsections matching the inputCategoryu
|
||||
if not sections:
|
||||
sections = config.__get_sections(subsection)
|
||||
sections = config.get_sections(inputCategory)
|
||||
|
||||
if not isinstance(sections, list):
|
||||
sections = [sections]
|
||||
|
||||
results = set()
|
||||
for section in sections:
|
||||
if config()[section].has_key(subsection):
|
||||
results.add(section)
|
||||
if config()[section].has_key(inputCategory):
|
||||
if checkenabled:
|
||||
if config.isenabled(section, inputCategory):
|
||||
results.add(section)
|
||||
else:
|
||||
results.add(section)
|
||||
return results if results.issubset(sections) else False
|
||||
|
||||
@staticmethod
|
||||
def __get_sections(subsections):
|
||||
# check and return categories if section does exist
|
||||
def get_sections(subsections):
|
||||
# finds all sections belonging to the subsection and returns them
|
||||
if not isinstance(subsections, list):
|
||||
subsections = [subsections]
|
||||
|
||||
|
@ -79,7 +85,7 @@ class config(object):
|
|||
|
||||
@staticmethod
|
||||
def get_subsections(sections):
|
||||
# check and return categories if section does exist
|
||||
# finds all subsections belonging to the section and returns them
|
||||
if not isinstance(sections, list):
|
||||
sections = [sections]
|
||||
|
||||
|
@ -92,6 +98,22 @@ class config(object):
|
|||
to_return.update({section: subsection})
|
||||
return to_return
|
||||
|
||||
@staticmethod
|
||||
def isenabled(section, inputCategory):
|
||||
# checks if the subsection is enabled/disabled
|
||||
if int(config()[section][inputCategory]['enabled']) == 1:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def search(key, section, subsection=None):
|
||||
# searches for data in sections and subsections and returns it
|
||||
if subsection:
|
||||
if key in config()[section][subsection].keys():
|
||||
return config()[section][subsection][key]
|
||||
else:
|
||||
if key in config()[section].keys():
|
||||
return config()[section][key]
|
||||
|
||||
@staticmethod
|
||||
def migrate():
|
||||
global config_new, config_old
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue