Merge pull request #1067 from clinton-hall/pep

PEP 8: Fix long line length
This commit is contained in:
Labrys of Knossos 2016-06-18 21:11:41 -04:00 committed by GitHub
commit e05f429641

View file

@ -42,9 +42,9 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
logger.debug("Received Directory: {0} | Name: {1} | Category: {2}".format(inputDirectory, inputName, inputCategory)) logger.debug("Received Directory: {0} | Name: {1} | Category: {2}".format(inputDirectory, inputName, inputCategory))
inputDirectory, inputName, inputCategory, root = core.category_search(inputDirectory, inputName, # Confirm the category by parsing directory structure
inputCategory, root, inputDirectory, inputName, inputCategory, root = core.category_search(inputDirectory, inputName, inputCategory,
core.CATEGORIES) # Confirm the category by parsing directory structure root, core.CATEGORIES)
if inputCategory == "": if inputCategory == "":
inputCategory = "UNCAT" inputCategory = "UNCAT"
@ -58,32 +58,36 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
except UnicodeError: except UnicodeError:
pass pass
logger.debug("Determined Directory: {0} | Name: {1} | Category: {2}".format(inputDirectory, inputName, inputCategory)) logger.debug("Determined Directory: {0} | Name: {1} | Category: {2}".format
(inputDirectory, inputName, inputCategory))
# auto-detect section # auto-detect section
section = core.CFG.findsection(inputCategory).isenabled() section = core.CFG.findsection(inputCategory).isenabled()
if section is None: if section is None:
section = core.CFG.findsection("ALL").isenabled() section = core.CFG.findsection("ALL").isenabled()
if section is None: if section is None:
logger.error( logger.error('Category:[{0}] is not defined or is not enabled. '
'Category:[{0}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.'.format( 'Please rename it or ensure it is enabled for the appropriate section '
inputCategory)) 'in your autoProcessMedia.cfg and try again.'.format
(inputCategory))
return [-1, ""] return [-1, ""]
else: else:
usercat = "ALL" usercat = "ALL"
if len(section) > 1: if len(section) > 1:
logger.error( logger.error('Category:[{0}] is not unique, {1} are using it. '
'Category:[{0}] is not unique, {1} are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.'.format( 'Please rename it or disable all other sections using the same category name '
usercat, section.keys())) 'in your autoProcessMedia.cfg and try again.'.format
(usercat, section.keys()))
return [-1, ""] return [-1, ""]
if section: if section:
sectionName = section.keys()[0] sectionName = section.keys()[0]
logger.info('Auto-detected SECTION:{0}'.format(sectionName)) logger.info('Auto-detected SECTION:{0}'.format(sectionName))
else: else:
logger.error("Unable to locate a section with subsection:{0} enabled in your autoProcessMedia.cfg, exiting!".format( logger.error("Unable to locate a section with subsection:{0} "
inputCategory)) "enabled in your autoProcessMedia.cfg, exiting!".format
(inputCategory))
return [-1, ""] return [-1, ""]
Torrent_NoLink = int(section[usercat].get("Torrent_NoLink", 0)) Torrent_NoLink = int(section[usercat].get("Torrent_NoLink", 0))
@ -91,7 +95,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
extract = int(section[usercat].get('extract', 0)) extract = int(section[usercat].get('extract', 0))
try: try:
uniquePath = int(section[usercat].get("unique_path", 1)) uniquePath = int(section[usercat].get("unique_path", 1))
except: except TypeError:
uniquePath = 1 uniquePath = 1
if clientAgent != 'manual': if clientAgent != 'manual':
@ -121,9 +125,9 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
logger.info("Output directory set to: {0}".format(outputDestination)) logger.info("Output directory set to: {0}".format(outputDestination))
if core.SAFE_MODE and outputDestination == core.TORRENT_DEFAULTDIR: if core.SAFE_MODE and outputDestination == core.TORRENT_DEFAULTDIR:
logger.error( logger.error('The output directory:[{0}] is the Download Directory. '
'The output directory:[{0}] is the Download Directory. Edit outputDirectory in autoProcessMedia.cfg. Exiting'.format( 'Edit outputDirectory in autoProcessMedia.cfg. Exiting'.format
inputDirectory)) (inputDirectory))
return [-1, ""] return [-1, ""]
logger.debug("Scanning files in directory: {0}".format(inputDirectory)) logger.debug("Scanning files in directory: {0}".format(inputDirectory))
@ -149,8 +153,8 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
if not os.path.basename(filePath) in outputDestination: if not os.path.basename(filePath) in outputDestination:
targetFile = core.os.path.join( targetFile = core.os.path.join(
core.os.path.join(outputDestination, os.path.basename(filePath)), fullFileName) core.os.path.join(outputDestination, os.path.basename(filePath)), fullFileName)
logger.debug( logger.debug("Setting outputDestination to {0} to preserve folder structure".format
"Setting outputDestination to {0} to preserve folder structure".format(os.path.dirname(targetFile))) (os.path.dirname(targetFile)))
try: try:
targetFile = targetFile.encode(core.SYS_ENCODING) targetFile = targetFile.encode(core.SYS_ENCODING)
except UnicodeError: except UnicodeError:
@ -161,7 +165,8 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
if any([core.sanitizeName(inputName) in core.sanitizeName(inputFile), if any([core.sanitizeName(inputName) in core.sanitizeName(inputFile),
core.sanitizeName(fileName) in core.sanitizeName(inputName)]): core.sanitizeName(fileName) in core.sanitizeName(inputName)]):
foundFile = True foundFile = True
logger.debug("Found file {0} that matches Torrent Name {1}".format(fullFileName, inputName)) logger.debug("Found file {0} that matches Torrent Name {1}".format
(fullFileName, inputName))
else: else:
continue continue
@ -173,7 +178,8 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
logger.debug("Looking for files with modified/created dates less than 5 minutes old.") logger.debug("Looking for files with modified/created dates less than 5 minutes old.")
if (mtime_lapse < datetime.timedelta(minutes=5)) or (ctime_lapse < datetime.timedelta(minutes=5)): if (mtime_lapse < datetime.timedelta(minutes=5)) or (ctime_lapse < datetime.timedelta(minutes=5)):
foundFile = True foundFile = True
logger.debug("Found file {0} with date modified/created less than 5 minutes ago.".format(fullFileName)) logger.debug("Found file {0} with date modified/created less than 5 minutes ago.".format
(fullFileName))
else: else:
continue # This file has not been recently moved or created, skip it continue # This file has not been recently moved or created, skip it
@ -190,7 +196,8 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
logger.debug('Checking for archives to extract in directory: {0}'.format(inputDirectory)) logger.debug('Checking for archives to extract in directory: {0}'.format(inputDirectory))
core.extractFiles(inputDirectory, outputDestination, keep_archive) core.extractFiles(inputDirectory, outputDestination, keep_archive)
if inputCategory not in core.NOFLATTEN: # don't flatten hp in case multi cd albums, and we need to copy this back later. if inputCategory not in core.NOFLATTEN:
# don't flatten hp in case multi cd albums, and we need to copy this back later.
core.flatten(outputDestination) core.flatten(outputDestination)
# Now check if video files exist in destination: # Now check if video files exist in destination:
@ -206,7 +213,8 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
else: else:
logger.warning("Found no media files in {0}".format(outputDestination)) logger.warning("Found no media files in {0}".format(outputDestination))
# Only these sections can handling failed downloads so make sure everything else gets through without the check for failed # Only these sections can handling failed downloads
# so make sure everything else gets through without the check for failed
if sectionName not in ['CouchPotato', 'SickBeard', 'NzbDrone']: if sectionName not in ['CouchPotato', 'SickBeard', 'NzbDrone']:
status = 0 status = 0
@ -220,29 +228,32 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
result = external_script(outputDestination, inputName, inputCategory, section[usercat]) result = external_script(outputDestination, inputName, inputCategory, section[usercat])
elif sectionName == 'CouchPotato': elif sectionName == 'CouchPotato':
result = core.autoProcessMovie().process(sectionName, outputDestination, inputName, status, clientAgent, inputHash, result = core.autoProcessMovie().process(sectionName, outputDestination, inputName,
inputCategory) status, clientAgent, inputHash, inputCategory)
elif sectionName in ['SickBeard', 'NzbDrone']: elif sectionName in ['SickBeard', 'NzbDrone']:
if inputHash: if inputHash:
inputHash = inputHash.upper() inputHash = inputHash.upper()
result = core.autoProcessTV().processEpisode(sectionName, outputDestination, inputName, status, clientAgent, result = core.autoProcessTV().processEpisode(sectionName, outputDestination, inputName,
inputHash, inputCategory) status, clientAgent, inputHash, inputCategory)
elif sectionName == 'HeadPhones': elif sectionName == 'HeadPhones':
result = core.autoProcessMusic().process(sectionName, outputDestination, inputName, status, clientAgent, inputCategory) result = core.autoProcessMusic().process(sectionName, outputDestination, inputName,
status, clientAgent, inputCategory)
elif sectionName == 'Mylar': elif sectionName == 'Mylar':
result = core.autoProcessComics().processEpisode(sectionName, outputDestination, inputName, status, clientAgent, result = core.autoProcessComics().processEpisode(sectionName, outputDestination, inputName,
inputCategory) status, clientAgent, inputCategory)
elif sectionName == 'Gamez': elif sectionName == 'Gamez':
result = core.autoProcessGames().process(sectionName, outputDestination, inputName, status, clientAgent, inputCategory) result = core.autoProcessGames().process(sectionName, outputDestination, inputName,
status, clientAgent, inputCategory)
plex_update(inputCategory) plex_update(inputCategory)
if result[0] != 0: if result[0] != 0:
if not core.TORRENT_RESUME_ON_FAILURE: if not core.TORRENT_RESUME_ON_FAILURE:
logger.error("A problem was reported in the autoProcess* script. torrent won't resume seeding (settings)") logger.error("A problem was reported in the autoProcess* script. "
"Torrent won't resume seeding (settings)")
elif clientAgent != 'manual': elif clientAgent != 'manual':
logger.error( logger.error("A problem was reported in the autoProcess* script. "
"A problem was reported in the autoProcess* script. If torrent was paused we will resume seeding") "If torrent was paused we will resume seeding")
core.resume_torrent(clientAgent, inputHash, inputID, inputName) core.resume_torrent(clientAgent, inputHash, inputID, inputName)
else: else:
@ -259,7 +270,8 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
replace_links(os.path.join(dirpath, file)) replace_links(os.path.join(dirpath, file))
core.remove_torrent(clientAgent, inputHash, inputID, inputName) core.remove_torrent(clientAgent, inputHash, inputID, inputName)
if not sectionName == 'UserScript': # for user script, we assume this is cleaned by the script or option USER_SCRIPT_CLEAN if not sectionName == 'UserScript':
# for user script, we assume this is cleaned by the script or option USER_SCRIPT_CLEAN
# cleanup our processing folders of any misc unwanted files and empty directories # cleanup our processing folders of any misc unwanted files and empty directories
core.cleanDir(outputDestination, sectionName, inputCategory) core.cleanDir(outputDestination, sectionName, inputCategory)
@ -300,18 +312,19 @@ def main(args):
if not core.CFG[section][subsection].isenabled(): if not core.CFG[section][subsection].isenabled():
continue continue
for dirName in core.getDirs(section, subsection, link='hard'): for dirName in core.getDirs(section, subsection, link='hard'):
logger.info("Starting manual run for {0}:{1} - Folder:{2}".format(section, subsection, dirName)) logger.info("Starting manual run for {0}:{1} - Folder:{2}".format
(section, subsection, dirName))
logger.info("Checking database for download info for {0} ...".format(os.path.basename(dirName))) logger.info("Checking database for download info for {0} ...".format
(os.path.basename(dirName)))
core.DOWNLOADINFO = core.get_downloadInfo(os.path.basename(dirName), 0) core.DOWNLOADINFO = core.get_downloadInfo(os.path.basename(dirName), 0)
if core.DOWNLOADINFO: if core.DOWNLOADINFO:
logger.info( logger.info("Found download info for {0}, "
"Found download info for {0}, setting variables now ...".format(os.path.basename(dirName))) "setting variables now ...".format(os.path.basename(dirName)))
else: else:
logger.info( logger.info('Unable to locate download info for {0}, '
'Unable to locate download info for {0}, continuing to try and process this release ...'.format( 'continuing to try and process this release ...'.format
os.path.basename(dirName)) (os.path.basename(dirName)))
)
clientAgent = text_type(core.DOWNLOADINFO[0].get('client_agent', '')) clientAgent = text_type(core.DOWNLOADINFO[0].get('client_agent', ''))
inputHash = text_type(core.DOWNLOADINFO[0].get('input_hash', '')) inputHash = text_type(core.DOWNLOADINFO[0].get('input_hash', ''))
@ -333,8 +346,8 @@ def main(args):
results = processTorrent(dirName, inputName, subsection, inputHash or None, inputID or None, results = processTorrent(dirName, inputName, subsection, inputHash or None, inputID or None,
clientAgent or 'manual') clientAgent or 'manual')
if results[0] != 0: if results[0] != 0:
logger.error("A problem was reported when trying to perform a manual run for {0}:{1}.".format( logger.error("A problem was reported when trying to perform a manual run for {0}:{1}.".format
section, subsection)) (section, subsection))
result = results result = results
if result[0] == 0: if result[0] == 0: