mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 12:59:36 -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:
|
if inputDirectory is None:
|
||||||
for section, subsection in subsections.iteritems():
|
for section, subsection in subsections.iteritems():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
|
if config.isenabled(section, category):
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
Logger.info("MAIN: TorrentToMedia running %s:%s as a manual run...", section, category)
|
Logger.info("MAIN: TorrentToMedia running %s:%s as a manual run...", section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
main(dirName, os.path.basename(dirName), category, inputHash, inputID)
|
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:
|
else:
|
||||||
main(inputDirectory, inputName, inputCategory, inputHash, inputID)
|
main(inputDirectory, inputName, inputCategory, inputHash, inputID)
|
||||||
|
|
|
@ -238,7 +238,7 @@ else:
|
||||||
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||||
for section, subsection in subsections.items():
|
for section, subsection in subsections.items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if int(config()[section][category]['enabled']) == 1:
|
if config.isenabled(section, category):
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
Logger.info("MAIN: nzbToCouchPotato running %s:%s as a manual run...", section, subsection)
|
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.")
|
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||||
for section, subsection in subsections.items():
|
for section, subsection in subsections.items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if int(config()[section][category]['enabled']) == 1:
|
if config.isenabled(section, category):
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
Logger.info("MAIN: nzbToGamez running %s:%s as a manual run...", section, category)
|
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.")
|
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||||
for section, subsection in subsections.items():
|
for section, subsection in subsections.items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if int(config()[section][category]['enabled']) == 1:
|
if config.isenabled(section, category):
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
Logger.info("MAIN: nzbToHeadPhones running %s:%s as a manual run...", section, category)
|
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.")
|
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||||
for section, subsection in subsections.items():
|
for section, subsection in subsections.items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if int(config()[section][category]['enabled']) == 1:
|
if config.isenabled(section, category):
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
Logger.info("MAIN: nzbToMedia running %s:%s as a manual run...", section, category)
|
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.")
|
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||||
for section, subsection in subsections.items():
|
for section, subsection in subsections.items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if int(config()[section][category]['enabled']) == 1:
|
if config.isenabled(section, category):
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
Logger.info("MAIN: nzbToMylar running %s:%s as a manual run...", section, category)
|
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.")
|
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||||
for section, subsection in subsections.items():
|
for section, subsection in subsections.items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if int(config()[section][category]['enabled']) == 1:
|
if config.isenabled(section, category):
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
Logger.info("MAIN: nzbToNzbDrone running %s:%s as a manual run...", section, category)
|
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.")
|
Logger.warn("MAIN: Invalid number of arguments received from client.")
|
||||||
for section, subsection in subsections.items():
|
for section, subsection in subsections.items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if int(config()[section][category]['enabled']) == 1:
|
if config.isenabled(section,category):
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
Logger.info("MAIN: nzbTo%s running %s:%s as a manual run...", section, section, category)
|
Logger.info("MAIN: nzbTo%s running %s:%s as a manual run...", section, section, category)
|
||||||
|
|
|
@ -15,12 +15,8 @@ class autoProcessComics:
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
# auto-detect correct section
|
# auto-detect correct section
|
||||||
secCount, section = [x for x in enumerate(config.issubsection(inputCategory)) if int(config()[x[1]][inputCategory]['enabled']) == 1][0]
|
section = config.issubsection(inputCategory, checkenabled=True)
|
||||||
if secCount > 1:
|
if len(section) == 0:
|
||||||
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:
|
|
||||||
Logger.error(
|
Logger.error(
|
||||||
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -14,17 +14,12 @@ class autoProcessGames:
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
# auto-detect correct section
|
# auto-detect correct section
|
||||||
secCount, section = [x for x in enumerate(config.issubsection(inputCategory)) if int(config()[x[1]][inputCategory]['enabled']) == 1][0]
|
section = config.issubsection(inputCategory, checkenabled=True)
|
||||||
if secCount > 1:
|
if len(section) == 0:
|
||||||
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:
|
|
||||||
Logger.error(
|
Logger.error(
|
||||||
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
socket.setdefaulttimeout(int(config.NZBTOMEDIA_TIMEOUT)) #initialize socket timeout.
|
socket.setdefaulttimeout(int(config.NZBTOMEDIA_TIMEOUT)) #initialize socket timeout.
|
||||||
|
|
||||||
Logger.info("Loading config from %s", config.CONFIG_FILE)
|
Logger.info("Loading config from %s", config.CONFIG_FILE)
|
||||||
|
|
|
@ -166,12 +166,8 @@ class autoProcessMovie:
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
# auto-detect correct section
|
# auto-detect correct section
|
||||||
secCount, section = [x for x in enumerate(config.issubsection(inputCategory)) if int(config()[x[1]][inputCategory]['enabled']) == 1][0]
|
section = config.issubsection(inputCategory, checkenabled=True)
|
||||||
if secCount > 1:
|
if len(section) == 0:
|
||||||
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:
|
|
||||||
Logger.error(
|
Logger.error(
|
||||||
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -15,12 +15,8 @@ class autoProcessMusic:
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
# auto-detect correct section
|
# auto-detect correct section
|
||||||
secCount, section = [x for x in enumerate(config.issubsection(inputCategory)) if int(config()[x[1]][inputCategory]['enabled']) == 1][0]
|
section = config.issubsection(inputCategory,checkenabled=True)
|
||||||
if secCount > 1:
|
if len(section) == 0:
|
||||||
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:
|
|
||||||
Logger.error(
|
Logger.error(
|
||||||
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -21,12 +21,8 @@ class autoProcessTV:
|
||||||
return 1 # failure
|
return 1 # failure
|
||||||
|
|
||||||
# auto-detect correct section
|
# auto-detect correct section
|
||||||
secCount, section = [x for x in enumerate(config.issubsection(inputCategory)) if int(config()[x[1]][inputCategory]['enabled']) == 1][0]
|
section = config.issubsection(inputCategory, checkenabled=True)
|
||||||
if secCount > 1:
|
if len(section) == 0:
|
||||||
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:
|
|
||||||
Logger.error(
|
Logger.error(
|
||||||
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
"MAIN: We were unable to find a processor for category %s that was enabled, please check your autoProcessMedia.cfg file.", inputCategory)
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -51,22 +51,28 @@ class config(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
@staticmethod
|
@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:
|
if not sections:
|
||||||
sections = config.__get_sections(subsection)
|
sections = config.get_sections(inputCategory)
|
||||||
|
|
||||||
if not isinstance(sections, list):
|
if not isinstance(sections, list):
|
||||||
sections = [sections]
|
sections = [sections]
|
||||||
|
|
||||||
results = set()
|
results = set()
|
||||||
for section in sections:
|
for section in sections:
|
||||||
if config()[section].has_key(subsection):
|
if config()[section].has_key(inputCategory):
|
||||||
|
if checkenabled:
|
||||||
|
if config.isenabled(section, inputCategory):
|
||||||
|
results.add(section)
|
||||||
|
else:
|
||||||
results.add(section)
|
results.add(section)
|
||||||
return results if results.issubset(sections) else False
|
return results if results.issubset(sections) else False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_sections(subsections):
|
def get_sections(subsections):
|
||||||
# check and return categories if section does exist
|
# finds all sections belonging to the subsection and returns them
|
||||||
if not isinstance(subsections, list):
|
if not isinstance(subsections, list):
|
||||||
subsections = [subsections]
|
subsections = [subsections]
|
||||||
|
|
||||||
|
@ -79,7 +85,7 @@ class config(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_subsections(sections):
|
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):
|
if not isinstance(sections, list):
|
||||||
sections = [sections]
|
sections = [sections]
|
||||||
|
|
||||||
|
@ -92,6 +98,22 @@ class config(object):
|
||||||
to_return.update({section: subsection})
|
to_return.update({section: subsection})
|
||||||
return to_return
|
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
|
@staticmethod
|
||||||
def migrate():
|
def migrate():
|
||||||
global config_new, config_old
|
global config_new, config_old
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue