mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 13:23:18 -07:00
Re-coded config class to better handle multiple subsection conditionals.
This commit is contained in:
parent
8425e0f377
commit
57019ec21b
12 changed files with 95 additions and 113 deletions
|
@ -14,7 +14,8 @@ from nzbtomedia.autoProcess.autoProcessMovie import autoProcessMovie
|
||||||
from nzbtomedia.autoProcess.autoProcessMusic import autoProcessMusic
|
from nzbtomedia.autoProcess.autoProcessMusic import autoProcessMusic
|
||||||
from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
|
from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
|
||||||
from nzbtomedia.extractor import extractor
|
from nzbtomedia.extractor import extractor
|
||||||
from nzbtomedia.nzbToMediaUtil import category_search, safeName, is_sample, copy_link, parse_args, flatten, get_dirnames
|
from nzbtomedia.nzbToMediaUtil import category_search, safeName, is_sample, copy_link, parse_args, flatten, get_dirnames, \
|
||||||
|
remove_read_only
|
||||||
from nzbtomedia.synchronousdeluge.client import DelugeClient
|
from nzbtomedia.synchronousdeluge.client import DelugeClient
|
||||||
from nzbtomedia.utorrent.client import UTorrentClient
|
from nzbtomedia.utorrent.client import UTorrentClient
|
||||||
from nzbtomedia.transmissionrpc.client import Client as TransmissionClient
|
from nzbtomedia.transmissionrpc.client import Client as TransmissionClient
|
||||||
|
@ -46,7 +47,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
|
||||||
outputDestination = os.path.normpath(os.path.join(nzbtomedia.OUTPUTDIRECTORY, inputCategory, safeName(inputName)))
|
outputDestination = os.path.normpath(os.path.join(nzbtomedia.OUTPUTDIRECTORY, inputCategory, safeName(inputName)))
|
||||||
logger.postprocess("Output directory set to: %s", outputDestination)
|
logger.postprocess("Output directory set to: %s", outputDestination)
|
||||||
|
|
||||||
if nzbtomedia.CFG["SickBeard"].issubsection(inputCategory):
|
if nzbtomedia.CFG["SickBeard"][inputCategory]:
|
||||||
Torrent_NoLink = int(nzbtomedia.CFG["SickBeard"][inputCategory]["Torrent_NoLink"]) # 0
|
Torrent_NoLink = int(nzbtomedia.CFG["SickBeard"][inputCategory]["Torrent_NoLink"]) # 0
|
||||||
if Torrent_NoLink == 1:
|
if Torrent_NoLink == 1:
|
||||||
logger.postprocess("Calling autoProcessTV to post-process: %s",inputName)
|
logger.postprocess("Calling autoProcessTV to post-process: %s",inputName)
|
||||||
|
@ -71,7 +72,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
|
||||||
|
|
||||||
logger.debug("Scanning files in directory: %s", inputDirectory)
|
logger.debug("Scanning files in directory: %s", inputDirectory)
|
||||||
|
|
||||||
if nzbtomedia.CFG["HeadPhones"].issubsection(inputCategory):
|
if nzbtomedia.CFG["HeadPhones"][inputCategory]:
|
||||||
nzbtomedia.NOFLATTEN.extend(nzbtomedia.CFG["HeadPhones"].sections) # Make sure we preserve folder structure for HeadPhones.
|
nzbtomedia.NOFLATTEN.extend(nzbtomedia.CFG["HeadPhones"].sections) # Make sure we preserve folder structure for HeadPhones.
|
||||||
|
|
||||||
outputDestinationMaster = outputDestination # Save the original, so we can change this within the loop below, and reset afterwards.
|
outputDestinationMaster = outputDestination # Save the original, so we can change this within the loop below, and reset afterwards.
|
||||||
|
@ -118,12 +119,12 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
|
||||||
continue # This file has not been recently moved or created, skip it
|
continue # This file has not been recently moved or created, skip it
|
||||||
|
|
||||||
if fileExtension in nzbtomedia.MEDIACONTAINER and is_sample(filePath, inputName, nzbtomedia.MINSAMPLESIZE,
|
if fileExtension in nzbtomedia.MEDIACONTAINER and is_sample(filePath, inputName, nzbtomedia.MINSAMPLESIZE,
|
||||||
nzbtomedia.SAMPLEIDS) and not nzbtomedia.CFG["HeadPhones"].issubsection(inputCategory): # Ignore samples
|
nzbtomedia.SAMPLEIDS) and not nzbtomedia.CFG["HeadPhones"][inputCategory]: # Ignore samples
|
||||||
logger.postprocess("Ignoring sample file: %s ", filePath)
|
logger.postprocess("Ignoring sample file: %s ", filePath)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if fileExtension in nzbtomedia.COMPRESSEDCONTAINER:
|
if fileExtension in nzbtomedia.COMPRESSEDCONTAINER:
|
||||||
if (nzbtomedia.CFG["SickBeard"].issubsection(inputCategory) and nzbtomedia.CFG["SickBeard"][inputCategory]["nzbExtractionBy"] == "Destination"):
|
if (nzbtomedia.CFG["SickBeard"][inputCategory] and nzbtomedia.CFG["SickBeard"][inputCategory]["nzbExtractionBy"] == "Destination"):
|
||||||
# find part numbers in second "extension" from right, if we have more than 1 compressed file in the same directory.
|
# find part numbers in second "extension" from right, if we have more than 1 compressed file in the same directory.
|
||||||
if re.search(r'\d+', os.path.splitext(fileName)[1]) and os.path.dirname(filePath) in extracted_folder and not any(item in os.path.splitext(fileName)[1] for item in ['.720p','.1080p','.x264']):
|
if re.search(r'\d+', os.path.splitext(fileName)[1]) and os.path.dirname(filePath) in extracted_folder and not any(item in os.path.splitext(fileName)[1] for item in ['.720p','.1080p','.x264']):
|
||||||
part = int(re.search(r'\d+', os.path.splitext(fileName)[1]).group())
|
part = int(re.search(r'\d+', os.path.splitext(fileName)[1]).group())
|
||||||
|
@ -155,7 +156,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
|
||||||
remove_read_only(outputDestination)
|
remove_read_only(outputDestination)
|
||||||
|
|
||||||
# Now check if video files exist in destination:
|
# Now check if video files exist in destination:
|
||||||
if nzbtomedia.CFG["SickBeard","NzbDrone", "CouchPotato"].issubsection(inputCategory):
|
if nzbtomedia.CFG["SickBeard","NzbDrone", "CouchPotato"][inputCategory]:
|
||||||
for dirpath, dirnames, filenames in os.walk(outputDestination):
|
for dirpath, dirnames, filenames in os.walk(outputDestination):
|
||||||
for file in filenames:
|
for file in filenames:
|
||||||
filePath = os.path.join(dirpath, file)
|
filePath = os.path.join(dirpath, file)
|
||||||
|
@ -168,7 +169,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
|
||||||
if video > int(0): # Check that media files exist
|
if video > int(0): # Check that media files exist
|
||||||
logger.debug("Found %s media files", str(video))
|
logger.debug("Found %s media files", str(video))
|
||||||
status = int(0)
|
status = int(0)
|
||||||
elif not (nzbtomedia.CFG["SickBeard"].issubsection(inputCategory) and nzbtomedia.CFG["SickBeard"][inputCategory]["nzbExtractionBy"] == "Destination") and archive > int(0):
|
elif not (nzbtomedia.CFG["SickBeard"][inputCategory] and nzbtomedia.CFG["SickBeard"][inputCategory]["nzbExtractionBy"] == "Destination") and archive > int(0):
|
||||||
logger.debug("Found %s archive files to be extracted by SickBeard", str(archive))
|
logger.debug("Found %s archive files to be extracted by SickBeard", str(archive))
|
||||||
status = int(0)
|
status = int(0)
|
||||||
else:
|
else:
|
||||||
|
@ -177,7 +178,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
|
||||||
if (inputCategory in nzbtomedia.USER_SCRIPT_CATEGORIES and not "NONE" in nzbtomedia.USER_SCRIPT_CATEGORIES) or ("ALL" in nzbtomedia.USER_SCRIPT_CATEGORIES and not inputCategory in processCategories):
|
if (inputCategory in nzbtomedia.USER_SCRIPT_CATEGORIES and not "NONE" in nzbtomedia.USER_SCRIPT_CATEGORIES) or ("ALL" in nzbtomedia.USER_SCRIPT_CATEGORIES and not inputCategory in processCategories):
|
||||||
logger.postprocess("Processing user script %s.", user_script)
|
logger.postprocess("Processing user script %s.", user_script)
|
||||||
result = external_script(outputDestination,inputName,inputCategory)
|
result = external_script(outputDestination,inputName,inputCategory)
|
||||||
elif status == int(0) or (nzbtomedia.CFG['HeadPhones','Mylar','Gamez'].issubsection(inputCategory)): # if movies linked/extracted or for other categories.
|
elif status == int(0) or (nzbtomedia.CFG['HeadPhones','Mylar','Gamez'][inputCategory]): # if movies linked/extracted or for other categories.
|
||||||
logger.debug("Calling autoProcess script for successful download.")
|
logger.debug("Calling autoProcess script for successful download.")
|
||||||
status = int(0) # hp, my, gz don't support failed.
|
status = int(0) # hp, my, gz don't support failed.
|
||||||
else:
|
else:
|
||||||
|
@ -185,23 +186,23 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
result = 0
|
result = 0
|
||||||
if nzbtomedia.CFG['CouchPotato'].issubsection(inputCategory):
|
if nzbtomedia.CFG['CouchPotato'][inputCategory]:
|
||||||
logger.postprocess("Calling CouchPotato:" + inputCategory + " to post-process: %s", inputName)
|
logger.postprocess("Calling CouchPotato:" + inputCategory + " to post-process: %s", inputName)
|
||||||
download_id = inputHash
|
download_id = inputHash
|
||||||
result = autoProcessMovie().process(outputDestination, inputName, status, nzbtomedia.CLIENTAGENT, download_id, inputCategory)
|
result = autoProcessMovie().process(outputDestination, inputName, status, nzbtomedia.CLIENTAGENT, download_id, inputCategory)
|
||||||
elif nzbtomedia.CFG['SickBeard'].issubsection(inputCategory):
|
elif nzbtomedia.CFG['SickBeard'][inputCategory]:
|
||||||
logger.postprocess("Calling Sick-Beard:" + inputCategory + " to post-process: %s", inputName)
|
logger.postprocess("Calling Sick-Beard:" + inputCategory + " to post-process: %s", inputName)
|
||||||
result = autoProcessTV().processEpisode(outputDestination, inputName, status, nzbtomedia.CLIENTAGENT, inputCategory)
|
result = autoProcessTV().processEpisode(outputDestination, inputName, status, nzbtomedia.CLIENTAGENT, inputCategory)
|
||||||
elif nzbtomedia.CFG['NzbDrone'].issubsection(inputCategory):
|
elif nzbtomedia.CFG['NzbDrone'][inputCategory]:
|
||||||
logger.postprocess("Calling NzbDrone:" + inputCategory + " to post-process: %s", inputName)
|
logger.postprocess("Calling NzbDrone:" + inputCategory + " to post-process: %s", inputName)
|
||||||
result = autoProcessTV().processEpisode(outputDestination, inputName, status, nzbtomedia.CLIENTAGENT, inputCategory)
|
result = autoProcessTV().processEpisode(outputDestination, inputName, status, nzbtomedia.CLIENTAGENT, inputCategory)
|
||||||
elif nzbtomedia.CFG['HeadPhones'].issubsection(inputCategory):
|
elif nzbtomedia.CFG['HeadPhones'][inputCategory]:
|
||||||
logger.postprocess("Calling HeadPhones:" + inputCategory + " to post-process: %s", inputName)
|
logger.postprocess("Calling HeadPhones:" + inputCategory + " to post-process: %s", inputName)
|
||||||
result = autoProcessMusic().process(inputDirectory, inputName, status, nzbtomedia.CLIENTAGENT, inputCategory)
|
result = autoProcessMusic().process(inputDirectory, inputName, status, nzbtomedia.CLIENTAGENT, inputCategory)
|
||||||
elif nzbtomedia.CFG['Mylar'].issubsection(inputCategory):
|
elif nzbtomedia.CFG['Mylar'][inputCategory]:
|
||||||
logger.postprocess("Calling Mylar:" + inputCategory + " to post-process: %s", inputName)
|
logger.postprocess("Calling Mylar:" + inputCategory + " to post-process: %s", inputName)
|
||||||
result = autoProcessComics().processEpisode(outputDestination, inputName, status, nzbtomedia.CLIENTAGENT, inputCategory)
|
result = autoProcessComics().processEpisode(outputDestination, inputName, status, nzbtomedia.CLIENTAGENT, inputCategory)
|
||||||
elif nzbtomedia.CFG['Gamez'].issubsection(inputCategory):
|
elif nzbtomedia.CFG['Gamez'][inputCategory]:
|
||||||
logger.postprocess("Calling Gamez:" + inputCategory + " to post-process: %s", inputName)
|
logger.postprocess("Calling Gamez:" + inputCategory + " to post-process: %s", inputName)
|
||||||
result = autoProcessGames().process(outputDestination, inputName, status, nzbtomedia.CLIENTAGENT, inputCategory)
|
result = autoProcessGames().process(outputDestination, inputName, status, nzbtomedia.CLIENTAGENT, inputCategory)
|
||||||
|
|
||||||
|
@ -401,7 +402,7 @@ if __name__ == "__main__":
|
||||||
if inputDirectory is None:
|
if inputDirectory is None:
|
||||||
for section, subsection in nzbtomedia.SUBSECTIONS.items():
|
for section, subsection in nzbtomedia.SUBSECTIONS.items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if nzbtomedia.CFG[section].isenabled(category):
|
if nzbtomedia.CFG[section][category].isenabled():
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
logger.postprocess("Running %s:%s as a manual run for folder %s ...", section, category, dirName)
|
logger.postprocess("Running %s:%s as a manual run for folder %s ...", section, category, dirName)
|
||||||
|
|
|
@ -216,7 +216,7 @@ else:
|
||||||
logger.warning("Invalid number of arguments received from client.")
|
logger.warning("Invalid number of arguments received from client.")
|
||||||
for section, subsection in nzbtomedia.SUBSECTIONS['CouchPotato'].items():
|
for section, subsection in nzbtomedia.SUBSECTIONS['CouchPotato'].items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if nzbtomedia.CFG[section].isenabled(category):
|
if nzbtomedia.CFG[section][category].isenabled():
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
logger.postprocess("Running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
logger.postprocess("Running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
||||||
|
|
|
@ -148,7 +148,7 @@ else:
|
||||||
logger.warning("Invalid number of arguments received from client.")
|
logger.warning("Invalid number of arguments received from client.")
|
||||||
for section, subsection in nzbtomedia.SUBSECTIONS['Gamez'].items():
|
for section, subsection in nzbtomedia.SUBSECTIONS['Gamez'].items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if nzbtomedia.CFG[section].isenabled(category):
|
if nzbtomedia.CFG[section][category].isenabled():
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
logger.postprocess("Running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
logger.postprocess("Running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
||||||
|
|
|
@ -158,7 +158,7 @@ else:
|
||||||
logger.warning("Invalid number of arguments received from client.")
|
logger.warning("Invalid number of arguments received from client.")
|
||||||
for section, subsection in nzbtomedia.SUBSECTIONS['HeadPhones'].items():
|
for section, subsection in nzbtomedia.SUBSECTIONS['HeadPhones'].items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if nzbtomedia.CFG[section].isenabled(category):
|
if nzbtomedia.CFG[section][category].isenabled():
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
logger.postprocess("nzbToHeadPhones running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
logger.postprocess("nzbToHeadPhones running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
||||||
|
|
|
@ -313,19 +313,19 @@ from nzbtomedia import logger
|
||||||
# post-processing
|
# post-processing
|
||||||
def process(nzbDir, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None):
|
def process(nzbDir, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None):
|
||||||
|
|
||||||
if nzbtomedia.CFG["CouchPotato"].issubsection(inputCategory):
|
if nzbtomedia.CFG["CouchPotato"][inputCategory]:
|
||||||
logger.postprocess("Calling CouchPotatoServer to post-process: %s", logger.MESSAGE), inputName
|
logger.postprocess("Calling CouchPotatoServer to post-process: %s", logger.MESSAGE), inputName
|
||||||
return autoProcessMovie().process(nzbDir, inputName, status, clientAgent, download_id, inputCategory)
|
return autoProcessMovie().process(nzbDir, inputName, status, clientAgent, download_id, inputCategory)
|
||||||
elif nzbtomedia.CFG["SickBeard", "NzbDrone"].issubsection(inputCategory):
|
elif nzbtomedia.CFG["SickBeard", "NzbDrone"][inputCategory]:
|
||||||
logger.postprocess("Calling Sick-Beard to post-process: %s",logger.MESSAGE), inputName
|
logger.postprocess("Calling Sick-Beard to post-process: %s",logger.MESSAGE), inputName
|
||||||
return autoProcessTV().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
|
return autoProcessTV().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||||
elif nzbtomedia.CFG["HeadPhones"].issubsection(inputCategory):
|
elif nzbtomedia.CFG["HeadPhones"][inputCategory]:
|
||||||
logger.postprocess("Calling HeadPhones to post-process: %s", logger.MESSAGE), inputName
|
logger.postprocess("Calling HeadPhones to post-process: %s", logger.MESSAGE), inputName
|
||||||
return autoProcessMusic().process(nzbDir, inputName, status, clientAgent, inputCategory)
|
return autoProcessMusic().process(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||||
elif nzbtomedia.CFG["Mylar"].issubsection(inputCategory):
|
elif nzbtomedia.CFG["Mylar"][inputCategory]:
|
||||||
logger.postprocess("Calling Mylar to post-process: %s",logger.MESSAGE), inputName
|
logger.postprocess("Calling Mylar to post-process: %s",logger.MESSAGE), inputName
|
||||||
return autoProcessComics().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
|
return autoProcessComics().processEpisode(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||||
elif nzbtomedia.CFG["Gamez"].issubsection(inputCategory):
|
elif nzbtomedia.CFG["Gamez"][inputCategory]:
|
||||||
logger.postprocess("Calling Gamez to post-process: %s",logger.MESSAGE), inputName
|
logger.postprocess("Calling Gamez to post-process: %s",logger.MESSAGE), inputName
|
||||||
return autoProcessGames().process(nzbDir, inputName, status, clientAgent, inputCategory)
|
return autoProcessGames().process(nzbDir, inputName, status, clientAgent, inputCategory)
|
||||||
else:
|
else:
|
||||||
|
@ -427,7 +427,7 @@ else:
|
||||||
logger.warning("Invalid number of arguments received from client.")
|
logger.warning("Invalid number of arguments received from client.")
|
||||||
for section, subsection in nzbtomedia.SUBSECTIONS.items():
|
for section, subsection in nzbtomedia.SUBSECTIONS.items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if nzbtomedia.CFG[section].isenabled(category):
|
if nzbtomedia.CFG[section][category].isenabled():
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
logger.postprocess("nzbToMedia running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
logger.postprocess("nzbToMedia running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
||||||
|
|
|
@ -153,9 +153,9 @@ else:
|
||||||
result = 0
|
result = 0
|
||||||
|
|
||||||
logger.warning("Invalid number of arguments received from client.")
|
logger.warning("Invalid number of arguments received from client.")
|
||||||
for section, subsection in nzbtomedia.SUBSECTIONS['Mylar'].items():
|
section = "Mylar"
|
||||||
for category in subsection:
|
for category in nzbtomedia.SUBSECTIONS[section]:
|
||||||
if nzbtomedia.CFG[section].isenabled(category):
|
if nzbtomedia.SUBSECTIONS[section][category].isenabled():
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
logger.postprocess("nzbToMylar running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
logger.postprocess("nzbToMylar running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
||||||
|
|
|
@ -185,7 +185,7 @@ else:
|
||||||
logger.warning("Invalid number of arguments received from client.")
|
logger.warning("Invalid number of arguments received from client.")
|
||||||
for section, subsection in nzbtomedia.SUBSECTIONS['NzbDrone'].items():
|
for section, subsection in nzbtomedia.SUBSECTIONS['NzbDrone'].items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if nzbtomedia.CFG[section].isenabled(category):
|
if nzbtomedia.CFG[section][category].isenabled():
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
logger.postprocess("nzbToNzbDrone running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
logger.postprocess("nzbToNzbDrone running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
||||||
|
|
|
@ -218,7 +218,7 @@ else:
|
||||||
logger.warning("Invalid number of arguments received from client.")
|
logger.warning("Invalid number of arguments received from client.")
|
||||||
for section, subsection in nzbtomedia.SUBSECTIONS['SickBeard'].items():
|
for section, subsection in nzbtomedia.SUBSECTIONS['SickBeard'].items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if nzbtomedia.CFG[section].isenabled(category):
|
if nzbtomedia.CFG[section][category].isenabled():
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
logger.postprocess("nzbToSickBeard running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
logger.postprocess("nzbToSickBeard running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
||||||
|
|
|
@ -114,7 +114,6 @@ def initialize():
|
||||||
# init logging
|
# init logging
|
||||||
logger.ntm_log_instance.initLogging()
|
logger.ntm_log_instance.initLogging()
|
||||||
|
|
||||||
|
|
||||||
# run migrate to convert old cfg to new style cfg plus fix any cfg missing values/options.
|
# run migrate to convert old cfg to new style cfg plus fix any cfg missing values/options.
|
||||||
if not config.migrate():
|
if not config.migrate():
|
||||||
logger.error("Unable to load config from %s", CONFIG_FILE)
|
logger.error("Unable to load config from %s", CONFIG_FILE)
|
||||||
|
@ -123,7 +122,9 @@ def initialize():
|
||||||
if os.environ.has_key('NZBOP_SCRIPTDIR'):
|
if os.environ.has_key('NZBOP_SCRIPTDIR'):
|
||||||
config.addnzbget()
|
config.addnzbget()
|
||||||
|
|
||||||
|
# load newly migrated config
|
||||||
logger.info("Loading config from %s", CONFIG_FILE)
|
logger.info("Loading config from %s", CONFIG_FILE)
|
||||||
|
CFG = config()
|
||||||
|
|
||||||
# check for newer version
|
# check for newer version
|
||||||
versionCheck.CheckVersion().find_installed_version()
|
versionCheck.CheckVersion().find_installed_version()
|
||||||
|
@ -159,8 +160,8 @@ def initialize():
|
||||||
SAMPLEIDS = (CFG["Extensions"]["SampleIDs"]) # sample,-s.
|
SAMPLEIDS = (CFG["Extensions"]["SampleIDs"]) # sample,-s.
|
||||||
|
|
||||||
SECTIONS = ("CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez")
|
SECTIONS = ("CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez")
|
||||||
SUBSECTIONS = CFG[SECTIONS].subsections
|
SUBSECTIONS = CFG[SECTIONS]
|
||||||
CATEGORIES += CFG[SECTIONS].sections
|
CATEGORIES += SUBSECTIONS.sections
|
||||||
|
|
||||||
USER_SCRIPT_CATEGORIES = CFG["UserScript"]["user_script_categories"] # NONE
|
USER_SCRIPT_CATEGORIES = CFG["UserScript"]["user_script_categories"] # NONE
|
||||||
|
|
||||||
|
|
|
@ -5,67 +5,61 @@ import lib.configobj
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
class Sections(dict):
|
class Sections(dict):
|
||||||
def issubsection(sections, subsection, checkenabled=True):
|
def isenabled(sections):
|
||||||
# checks sections for subsection, returns true/false in {}
|
# checks if subsection enabled, returns true/false if subsection specified otherwise returns true/false in {}
|
||||||
to_return = False
|
to_return = False
|
||||||
for section in sections.values():
|
for section, subsection in sections.items():
|
||||||
to_return = section.issubsection(subsection, checkenabled)
|
for item in subsection:
|
||||||
return to_return
|
if int(subsection[item]['enabled']) == 1:
|
||||||
|
to_return = True
|
||||||
def isenabled(sections, subsection):
|
|
||||||
# checks if subsections are enabled, returns true/false in {}
|
|
||||||
to_return = False
|
|
||||||
for section in sections.values():
|
|
||||||
to_return = section.isenabled(subsection)
|
|
||||||
return to_return
|
return to_return
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sections(sections):
|
def sections(sections):
|
||||||
# returns [subsections]
|
# returns [subsections]
|
||||||
to_return = []
|
to_return = []
|
||||||
for section in sections:
|
for section, subsection in sections.items():
|
||||||
to_return.append(sections[section].sections)
|
to_return.append(subsection)
|
||||||
return list(set(chain.from_iterable(to_return)))
|
return list(set(chain.from_iterable(to_return)))
|
||||||
|
|
||||||
@property
|
def __getitem__(self, key):
|
||||||
def subsections(sections):
|
# check for key in sections
|
||||||
# returns {section name:[subsections]}
|
if key in self:
|
||||||
to_return = {}
|
return dict.__getitem__(self, key)
|
||||||
for section in sections:
|
|
||||||
to_return.update({section:sections[section].subsections})
|
# check for key in subsections
|
||||||
|
to_return = Sections()
|
||||||
|
for section, subsection in self.items():
|
||||||
|
if key in subsection:
|
||||||
|
to_return.update({section:{key:dict.__getitem__(subsection, key)}})
|
||||||
return to_return
|
return to_return
|
||||||
|
|
||||||
class Section(lib.configobj.Section):
|
class Section(lib.configobj.Section):
|
||||||
def issubsection(section, subsection, checkenabled=True):
|
def isenabled(section):
|
||||||
# checks section for subsection, returns true/false
|
|
||||||
to_return = False
|
|
||||||
if subsection in section:
|
|
||||||
if checkenabled and section.isenabled(subsection):
|
|
||||||
to_return = True
|
|
||||||
else:
|
|
||||||
to_return = True
|
|
||||||
return to_return
|
|
||||||
|
|
||||||
def isenabled(section, subsection):
|
|
||||||
# checks if subsection enabled, returns true/false if subsection specified otherwise returns true/false in {}
|
# checks if subsection enabled, returns true/false if subsection specified otherwise returns true/false in {}
|
||||||
to_return = False
|
if section:
|
||||||
if subsection in section and int(section[subsection]['enabled']) == 1:
|
if int(section['enabled']) == 1:
|
||||||
to_return = True
|
return True
|
||||||
return to_return
|
return False
|
||||||
|
|
||||||
@property
|
|
||||||
def subsections(section):
|
|
||||||
# returns {section name:[subsections]}
|
|
||||||
to_return = {}
|
|
||||||
for subsection in section:
|
|
||||||
to_return.update({subsection:section[subsection]})
|
|
||||||
return to_return
|
|
||||||
|
|
||||||
def findsection(section, key):
|
def findsection(section, key):
|
||||||
for subsection in section:
|
for subsection in section:
|
||||||
if key in section[subsection]:
|
if key in section[subsection]:
|
||||||
return subsection
|
return subsection
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
# check for key in section
|
||||||
|
if key in self.keys():
|
||||||
|
return dict.__getitem__(self, key)
|
||||||
|
|
||||||
|
# check for key in subsection
|
||||||
|
result = Sections()
|
||||||
|
for section in key:
|
||||||
|
if section in self:
|
||||||
|
subsection = dict.__getitem__(self, section)
|
||||||
|
result.update({section: subsection})
|
||||||
|
return result
|
||||||
|
|
||||||
class ConfigObj(lib.configobj.ConfigObj, Section):
|
class ConfigObj(lib.configobj.ConfigObj, Section):
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
|
@ -73,18 +67,6 @@ class ConfigObj(lib.configobj.ConfigObj, Section):
|
||||||
super(lib.configobj.ConfigObj, self).__init__(*args, **kw)
|
super(lib.configobj.ConfigObj, self).__init__(*args, **kw)
|
||||||
self.interpolation = False
|
self.interpolation = False
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
result = Sections()
|
|
||||||
if isinstance(key, tuple):
|
|
||||||
for item in key:
|
|
||||||
val = dict.__getitem__(self, item)
|
|
||||||
result.update({item: val})
|
|
||||||
return result
|
|
||||||
else:
|
|
||||||
val = dict.__getitem__(self, key)
|
|
||||||
#result.update({key: val})
|
|
||||||
return val
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def migrate():
|
def migrate():
|
||||||
global CFG_NEW, CFG_OLD
|
global CFG_NEW, CFG_OLD
|
||||||
|
@ -211,9 +193,6 @@ class ConfigObj(lib.configobj.ConfigObj, Section):
|
||||||
with open(nzbtomedia.CONFIG_FILE, 'wb') as configFile:
|
with open(nzbtomedia.CONFIG_FILE, 'wb') as configFile:
|
||||||
CFG_NEW.write(configFile)
|
CFG_NEW.write(configFile)
|
||||||
|
|
||||||
# reload config
|
|
||||||
nzbtomedia.CFG = CFG_NEW
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -350,9 +329,6 @@ class ConfigObj(lib.configobj.ConfigObj, Section):
|
||||||
with open(nzbtomedia.CONFIG_FILE, 'wb') as configFile:
|
with open(nzbtomedia.CONFIG_FILE, 'wb') as configFile:
|
||||||
CFG_NEW.write(configFile)
|
CFG_NEW.write(configFile)
|
||||||
|
|
||||||
# reload config
|
|
||||||
nzbtomedia.CFG = CFG_NEW
|
|
||||||
|
|
||||||
lib.configobj.Section = Section
|
lib.configobj.Section = Section
|
||||||
lib.configobj.ConfigObj = ConfigObj
|
lib.configobj.ConfigObj = ConfigObj
|
||||||
config = ConfigObj
|
config = ConfigObj
|
||||||
|
|
|
@ -381,7 +381,7 @@ def get_dirnames(section, subsections=None):
|
||||||
dirNames = []
|
dirNames = []
|
||||||
|
|
||||||
if subsections is None:
|
if subsections is None:
|
||||||
subsections = nzbtomedia.CFG[section].subsections.values()
|
subsections = nzbtomedia.SUBSECTIONS[section].sections
|
||||||
|
|
||||||
if not isinstance(subsections, list):
|
if not isinstance(subsections, list):
|
||||||
subsections = [subsections]
|
subsections = [subsections]
|
||||||
|
|
|
@ -4,25 +4,29 @@ from nzbtomedia import logger
|
||||||
|
|
||||||
# Initialize the config
|
# Initialize the config
|
||||||
nzbtomedia.initialize()
|
nzbtomedia.initialize()
|
||||||
|
print nzbtomedia.CFG['SickBear','NzbDrone']['tv'].isenabled()
|
||||||
|
print nzbtomedia.CFG['SickBeard','NzbDrone']['tv'].isenabled()
|
||||||
|
|
||||||
print nzbtomedia.SUBSECTIONS["SickBeard"].items()
|
if nzbtomedia.CFG['SickBeard', 'NzbDrone', 'CouchPotato']['tv']:
|
||||||
|
print True
|
||||||
|
else:
|
||||||
|
print False
|
||||||
|
|
||||||
|
if nzbtomedia.CFG['SickBeard']['tv']:
|
||||||
|
print True
|
||||||
|
else:
|
||||||
|
print False
|
||||||
|
|
||||||
|
print
|
||||||
|
print nzbtomedia.SUBSECTIONS["SickBeard"]
|
||||||
print
|
print
|
||||||
print nzbtomedia.CFG.findsection('tv')
|
print nzbtomedia.CFG.findsection('tv')
|
||||||
print
|
print
|
||||||
print nzbtomedia.CFG.sections
|
print nzbtomedia.CFG.sections
|
||||||
print
|
print
|
||||||
sections = ("CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez")
|
sections = ("CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez")
|
||||||
print nzbtomedia.CFG[sections].subsections
|
|
||||||
print nzbtomedia.CFG['SickBeard'].subsections
|
|
||||||
print
|
|
||||||
print nzbtomedia.CFG[sections].sections
|
print nzbtomedia.CFG[sections].sections
|
||||||
print nzbtomedia.CFG['SickBeard'].sections
|
print nzbtomedia.CFG['SickBeard'].sections
|
||||||
print
|
print
|
||||||
print nzbtomedia.CFG['SickBeard','NzbDrone']
|
print nzbtomedia.CFG['SickBeard','NzbDrone']
|
||||||
print nzbtomedia.CFG['SickBeard']
|
print nzbtomedia.CFG['SickBeard']
|
||||||
print
|
|
||||||
print nzbtomedia.CFG['SickBeard','NzbDrone','CouchPotato'].issubsection('tv', True)
|
|
||||||
print nzbtomedia.CFG['SickBeard'].issubsection('tv', True)
|
|
||||||
print
|
|
||||||
print nzbtomedia.CFG['SickBeard','NzbDrone'].isenabled('tv')
|
|
||||||
print nzbtomedia.CFG['SickBeard'].isenabled('tv')
|
|
Loading…
Add table
Add a link
Reference in a new issue