PEP8: Tests for membership should use in/not in

* .has_key() is deprecated, use `in`
This commit is contained in:
Labrys 2016-06-04 22:20:45 -04:00
parent 92ae852513
commit 1fd904eb5b
5 changed files with 37 additions and 37 deletions

View file

@ -227,7 +227,7 @@ def initialize(section=None):
if __INITIALIZED__: if __INITIALIZED__:
return False return False
if os.environ.has_key('NTM_LOGFILE'): if 'NTM_LOGFILE' in os.environ:
LOG_FILE = os.environ['NTM_LOGFILE'] LOG_FILE = os.environ['NTM_LOGFILE']
LOG_DIR = os.path.split(LOG_FILE)[0] LOG_DIR = os.path.split(LOG_FILE)[0]
@ -259,7 +259,7 @@ def initialize(section=None):
except: except:
print 'Sorry, you MUST add the nzbToMedia folder to the PYTHONPATH environment variable' print 'Sorry, you MUST add the nzbToMedia folder to the PYTHONPATH environment variable'
print 'or find another way to force Python to use ' + SYS_ENCODING + ' for string encoding.' print 'or find another way to force Python to use ' + SYS_ENCODING + ' for string encoding.'
if os.environ.has_key('NZBOP_SCRIPTDIR'): if 'NZBOP_SCRIPTDIR' in os.environ:
sys.exit(NZBGET_POSTPROCESS_ERROR) sys.exit(NZBGET_POSTPROCESS_ERROR)
else: else:
sys.exit(1) sys.exit(1)
@ -270,13 +270,13 @@ def initialize(section=None):
# 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 migrate config file %s, exiting ..." % (CONFIG_FILE)) logger.error("Unable to migrate config file %s, exiting ..." % (CONFIG_FILE))
if os.environ.has_key('NZBOP_SCRIPTDIR'): if 'NZBOP_SCRIPTDIR' in os.environ:
pass # We will try and read config from Environment. pass # We will try and read config from Environment.
else: else:
sys.exit(-1) sys.exit(-1)
# run migrate to convert NzbGet data from old cfg style to new cfg style # run migrate to convert NzbGet data from old cfg style to new cfg style
if os.environ.has_key('NZBOP_SCRIPTDIR'): if 'NZBOP_SCRIPTDIR' in os.environ:
CFG = config.addnzbget() CFG = config.addnzbget()
else: # load newly migrated config else: # load newly migrated config
@ -441,9 +441,9 @@ def initialize(section=None):
GENERALOPTS = GENERALOPTS.split(',') GENERALOPTS = GENERALOPTS.split(',')
if GENERALOPTS == ['']: if GENERALOPTS == ['']:
GENERALOPTS = [] GENERALOPTS = []
if not '-fflags' in GENERALOPTS: if '-fflags' not in GENERALOPTS:
GENERALOPTS.append('-fflags') GENERALOPTS.append('-fflags')
if not '+genpts' in GENERALOPTS: if '+genpts' not in GENERALOPTS:
GENERALOPTS.append('+genpts') GENERALOPTS.append('+genpts')
try: try:
OUTPUTQUALITYPERCENT = int(CFG["Transcoder"]["outputQualityPercent"]) OUTPUTQUALITYPERCENT = int(CFG["Transcoder"]["outputQualityPercent"])

View file

@ -228,7 +228,7 @@ class NTMRotatingLogHandler(object):
def log_error_and_exit(self, error_msg): def log_error_and_exit(self, error_msg):
log(error_msg, ERROR) log(error_msg, ERROR)
if os.environ.has_key('NZBOP_SCRIPTDIR'): if 'NZBOP_SCRIPTDIR' in os.environ:
sys.exit(core.NZBGET_POSTPROCESS_ERROR) sys.exit(core.NZBGET_POSTPROCESS_ERROR)
elif not self.console_logging: elif not self.console_logging:
sys.exit(error_msg.encode(core.SYS_ENCODING, 'xmlcharrefreplace')) sys.exit(error_msg.encode(core.SYS_ENCODING, 'xmlcharrefreplace'))

View file

@ -186,7 +186,7 @@ class ConfigObj(configobj.ConfigObj, Section):
CFG_NEW['Posix'][option] = value CFG_NEW['Posix'][option] = value
values.pop(option) values.pop(option)
if option == "remote_path": if option == "remote_path":
if value and not value in ['0', '1', 0, 1]: if value and value not in ['0', '1', 0, 1]:
value = 1 value = 1
elif not value: elif not value:
value = 0 value = 0
@ -251,14 +251,14 @@ class ConfigObj(configobj.ConfigObj, Section):
CFG_NEW = config() CFG_NEW = config()
try: try:
if os.environ.has_key('NZBPO_NDCATEGORY') and os.environ.has_key('NZBPO_SBCATEGORY'): if 'NZBPO_NDCATEGORY' in os.environ and 'NZBPO_SBCATEGORY' in os.environ:
if os.environ['NZBPO_NDCATEGORY'] == os.environ['NZBPO_SBCATEGORY']: if os.environ['NZBPO_NDCATEGORY'] == os.environ['NZBPO_SBCATEGORY']:
logger.warning("%s category is set for SickBeard and NzbDrone. " logger.warning("%s category is set for SickBeard and NzbDrone. "
"Please check your config in NZBGet" % (os.environ['NZBPO_NDCATEGORY'])) "Please check your config in NZBGet" % (os.environ['NZBPO_NDCATEGORY']))
section = "Nzb" section = "Nzb"
key = 'NZBOP_DESTDIR' key = 'NZBOP_DESTDIR'
if os.environ.has_key(key): if key in os.environ:
option = 'default_downloadDirectory' option = 'default_downloadDirectory'
value = os.environ[key] value = os.environ[key]
CFG_NEW[section][option] = value CFG_NEW[section][option] = value
@ -268,7 +268,7 @@ class ConfigObj(configobj.ConfigObj, Section):
cfgKeys = ['auto_update', 'check_media', 'safe_mode'] cfgKeys = ['auto_update', 'check_media', 'safe_mode']
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_' + envKeys[index] key = 'NZBPO_' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
CFG_NEW[section][option] = value CFG_NEW[section][option] = value
@ -278,7 +278,7 @@ class ConfigObj(configobj.ConfigObj, Section):
cfgKeys = ['mount_points'] cfgKeys = ['mount_points']
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_' + envKeys[index] key = 'NZBPO_' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
CFG_NEW[section][option] = value CFG_NEW[section][option] = value
@ -289,10 +289,10 @@ class ConfigObj(configobj.ConfigObj, Section):
'WAIT_FOR', 'WATCH_DIR'] 'WAIT_FOR', 'WATCH_DIR']
cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'method', 'delete_failed', 'remote_path', cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'method', 'delete_failed', 'remote_path',
'wait_for', 'watch_dir'] 'wait_for', 'watch_dir']
if os.environ.has_key(envCatKey): if envCatKey in os.environ:
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_CPS' + envKeys[index] key = 'NZBPO_CPS' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
if os.environ[envCatKey] not in CFG_NEW[section].sections: if os.environ[envCatKey] not in CFG_NEW[section].sections:
@ -306,10 +306,10 @@ class ConfigObj(configobj.ConfigObj, Section):
'DELETE_FAILED', 'TORRENT_NOLINK', 'NZBEXTRACTIONBY', 'REMOTE_PATH', 'PROCESS_METHOD'] 'DELETE_FAILED', 'TORRENT_NOLINK', 'NZBEXTRACTIONBY', 'REMOTE_PATH', 'PROCESS_METHOD']
cfgKeys = ['enabled', 'host', 'port', 'username', 'password', 'ssl', 'web_root', 'watch_dir', 'fork', cfgKeys = ['enabled', 'host', 'port', 'username', 'password', 'ssl', 'web_root', 'watch_dir', 'fork',
'delete_failed', 'Torrent_NoLink', 'nzbExtractionBy', 'remote_path', 'process_method'] 'delete_failed', 'Torrent_NoLink', 'nzbExtractionBy', 'remote_path', 'process_method']
if os.environ.has_key(envCatKey): if envCatKey in os.environ:
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_SB' + envKeys[index] key = 'NZBPO_SB' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
if os.environ[envCatKey] not in CFG_NEW[section].sections: if os.environ[envCatKey] not in CFG_NEW[section].sections:
@ -323,10 +323,10 @@ class ConfigObj(configobj.ConfigObj, Section):
envCatKey = 'NZBPO_HPCATEGORY' envCatKey = 'NZBPO_HPCATEGORY'
envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'WAIT_FOR', 'WATCH_DIR', 'REMOTE_PATH'] envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'WAIT_FOR', 'WATCH_DIR', 'REMOTE_PATH']
cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'wait_for', 'watch_dir', 'remote_path'] cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'wait_for', 'watch_dir', 'remote_path']
if os.environ.has_key(envCatKey): if envCatKey in os.environ:
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_HP' + envKeys[index] key = 'NZBPO_HP' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
if os.environ[envCatKey] not in CFG_NEW[section].sections: if os.environ[envCatKey] not in CFG_NEW[section].sections:
@ -340,10 +340,10 @@ class ConfigObj(configobj.ConfigObj, Section):
'REMOTE_PATH'] 'REMOTE_PATH']
cfgKeys = ['enabled', 'host', 'port', 'username', 'password', 'apikey', 'ssl', 'web_root', 'watch_dir', cfgKeys = ['enabled', 'host', 'port', 'username', 'password', 'apikey', 'ssl', 'web_root', 'watch_dir',
'remote_path'] 'remote_path']
if os.environ.has_key(envCatKey): if envCatKey in os.environ:
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_MY' + envKeys[index] key = 'NZBPO_MY' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
if os.environ[envCatKey] not in CFG_NEW[section].sections: if os.environ[envCatKey] not in CFG_NEW[section].sections:
@ -355,10 +355,10 @@ class ConfigObj(configobj.ConfigObj, Section):
envCatKey = 'NZBPO_GZCATEGORY' envCatKey = 'NZBPO_GZCATEGORY'
envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'LIBRARY', 'REMOTE_PATH'] envKeys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'LIBRARY', 'REMOTE_PATH']
cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'watch_dir', 'library', 'remote_path'] cfgKeys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'watch_dir', 'library', 'remote_path']
if os.environ.has_key(envCatKey): if envCatKey in os.environ:
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_GZ' + envKeys[index] key = 'NZBPO_GZ' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
if os.environ[envCatKey] not in CFG_NEW[section].sections: if os.environ[envCatKey] not in CFG_NEW[section].sections:
@ -372,10 +372,10 @@ class ConfigObj(configobj.ConfigObj, Section):
'TORRENT_NOLINK', 'NZBEXTRACTIONBY', 'WAIT_FOR', 'DELETE_FAILED', 'REMOTE_PATH'] 'TORRENT_NOLINK', 'NZBEXTRACTIONBY', 'WAIT_FOR', 'DELETE_FAILED', 'REMOTE_PATH']
cfgKeys = ['enabled', 'host', 'apikey', 'port', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed', cfgKeys = ['enabled', 'host', 'apikey', 'port', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed',
'Torrent_NoLink', 'nzbExtractionBy', 'wait_for', 'delete_failed', 'remote_path'] 'Torrent_NoLink', 'nzbExtractionBy', 'wait_for', 'delete_failed', 'remote_path']
if os.environ.has_key(envCatKey): if envCatKey in os.environ:
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_ND' + envKeys[index] key = 'NZBPO_ND' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
if os.environ[envCatKey] not in CFG_NEW[section].sections: if os.environ[envCatKey] not in CFG_NEW[section].sections:
@ -390,7 +390,7 @@ class ConfigObj(configobj.ConfigObj, Section):
cfgKeys = ['compressedExtensions', 'mediaExtensions', 'metaExtensions'] cfgKeys = ['compressedExtensions', 'mediaExtensions', 'metaExtensions']
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_' + envKeys[index] key = 'NZBPO_' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
CFG_NEW[section][option] = value CFG_NEW[section][option] = value
@ -400,7 +400,7 @@ class ConfigObj(configobj.ConfigObj, Section):
cfgKeys = ['niceness', 'ionice_class', 'ionice_classdata'] cfgKeys = ['niceness', 'ionice_class', 'ionice_classdata']
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_' + envKeys[index] key = 'NZBPO_' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
CFG_NEW[section][option] = value CFG_NEW[section][option] = value
@ -428,7 +428,7 @@ class ConfigObj(configobj.ConfigObj, Section):
'outputAudioOtherChannels'] 'outputAudioOtherChannels']
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_' + envKeys[index] key = 'NZBPO_' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
CFG_NEW[section][option] = value CFG_NEW[section][option] = value
@ -438,7 +438,7 @@ class ConfigObj(configobj.ConfigObj, Section):
cfgKeys = ['wake', 'host', 'port', 'mac'] cfgKeys = ['wake', 'host', 'port', 'mac']
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_WOL' + envKeys[index] key = 'NZBPO_WOL' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
CFG_NEW[section][option] = value CFG_NEW[section][option] = value
@ -449,10 +449,10 @@ class ConfigObj(configobj.ConfigObj, Section):
'USER_SCRIPT_SUCCESSCODES', 'USER_SCRIPT_CLEAN', 'USDELAY', 'USREMOTE_PATH'] 'USER_SCRIPT_SUCCESSCODES', 'USER_SCRIPT_CLEAN', 'USDELAY', 'USREMOTE_PATH']
cfgKeys = ['user_script_mediaExtensions', 'user_script_path', 'user_script_param', 'user_script_runOnce', cfgKeys = ['user_script_mediaExtensions', 'user_script_path', 'user_script_param', 'user_script_runOnce',
'user_script_successCodes', 'user_script_clean', 'delay', 'remote_path'] 'user_script_successCodes', 'user_script_clean', 'delay', 'remote_path']
if os.environ.has_key(envCatKey): if envCatKey in os.environ:
for index in range(len(envKeys)): for index in range(len(envKeys)):
key = 'NZBPO_' + envKeys[index] key = 'NZBPO_' + envKeys[index]
if os.environ.has_key(key): if key in os.environ:
option = cfgKeys[index] option = cfgKeys[index]
value = os.environ[key] value = os.environ[key]
if os.environ[envCatKey] not in CFG_NEW[section].sections: if os.environ[envCatKey] not in CFG_NEW[section].sections:

View file

@ -157,7 +157,7 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
tordir = True tordir = True
imdbid = [item for item in pathlist if '.cp(tt' in item] # This looks for the .cp(tt imdb id in the path. imdbid = [item for item in pathlist if '.cp(tt' in item] # This looks for the .cp(tt imdb id in the path.
if imdbid and not '.cp(tt' in inputName: if imdbid and '.cp(tt' not in inputName:
inputName = imdbid[0] # This ensures the imdb id is preserved and passed to CP inputName = imdbid[0] # This ensures the imdb id is preserved and passed to CP
tordir = True tordir = True
@ -454,7 +454,7 @@ def convert_to_ascii(inputName, dirName):
dirName = os.path.join(dir, base2) dirName = os.path.join(dir, base2)
logger.info("Renaming directory to: %s." % (base2), 'ENCODER') logger.info("Renaming directory to: %s." % (base2), 'ENCODER')
os.rename(os.path.join(dir, base), dirName) os.rename(os.path.join(dir, base), dirName)
if os.environ.has_key('NZBOP_SCRIPTDIR'): if 'NZBOP_SCRIPTDIR' in os.environ:
print "[NZB] DIRECTORY=%s" % (dirName) # Return the new directory to NZBGet. print "[NZB] DIRECTORY=%s" % (dirName) # Return the new directory to NZBGet.
for dirname, dirnames, filenames in os.walk(dirName, topdown=False): for dirname, dirnames, filenames in os.walk(dirName, topdown=False):
@ -1038,7 +1038,7 @@ def find_imdbid(dirName, inputName):
imdbid = m.group(1) imdbid = m.group(1)
logger.info("Found imdbID [%s] via file name" % imdbid) logger.info("Found imdbID [%s] via file name" % imdbid)
return imdbid return imdbid
if os.environ.has_key('NZBPR__DNZB_MOREINFO'): if 'NZBPR__DNZB_MOREINFO' in os.environ:
dnzb_more_info = os.environ.get('NZBPR__DNZB_MOREINFO', '') dnzb_more_info = os.environ.get('NZBPR__DNZB_MOREINFO', '')
if dnzb_more_info != '': if dnzb_more_info != '':
regex = re.compile(r'^http://www.imdb.com/title/(tt[0-9]+)/$', re.IGNORECASE) regex = re.compile(r'^http://www.imdb.com/title/(tt[0-9]+)/$', re.IGNORECASE)
@ -1110,7 +1110,7 @@ def extractFiles(src, dst=None, keep_archive=None):
fullFileName = os.path.basename(inputFile) fullFileName = os.path.basename(inputFile)
archiveName = os.path.splitext(fullFileName)[0] archiveName = os.path.splitext(fullFileName)[0]
archiveName = re.sub(r"part[0-9]+", "", archiveName) archiveName = re.sub(r"part[0-9]+", "", archiveName)
if not archiveName in extracted_archive or keep_archive is True: if archiveName not in extracted_archive or keep_archive is True:
continue # don't remove if we haven't extracted this archive, or if we want to preserve them. continue # don't remove if we haven't extracted this archive, or if we want to preserve them.
logger.info("Removing extracted archive %s from folder %s ..." % (fullFileName, folder)) logger.info("Removing extracted archive %s from folder %s ..." % (fullFileName, folder))
try: try:

View file

@ -594,11 +594,11 @@ def processList(List, newDir, bitbucket):
for item in List: for item in List:
newfile = None newfile = None
ext = os.path.splitext(item)[1].lower() ext = os.path.splitext(item)[1].lower()
if ext in ['.iso', '.bin', '.img'] and not ext in core.IGNOREEXTENSIONS: if ext in ['.iso', '.bin', '.img'] and ext not in core.IGNOREEXTENSIONS:
logger.debug("Attempting to rip disk image: %s" % (item), "TRANSCODER") logger.debug("Attempting to rip disk image: %s" % (item), "TRANSCODER")
newList.extend(ripISO(item, newDir, bitbucket)) newList.extend(ripISO(item, newDir, bitbucket))
remList.append(item) remList.append(item)
elif re.match(".+VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]", item) and not '.vob' in core.IGNOREEXTENSIONS: elif re.match(".+VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]", item) and '.vob' not in core.IGNOREEXTENSIONS:
logger.debug("Found VIDEO_TS image file: %s" % (item), "TRANSCODER") logger.debug("Found VIDEO_TS image file: %s" % (item), "TRANSCODER")
if not vtsPath: if not vtsPath:
try: try:
@ -618,7 +618,7 @@ def processList(List, newDir, bitbucket):
if combine: if combine:
newList.extend(combineCD(combine)) newList.extend(combineCD(combine))
for file in newList: for file in newList:
if isinstance(file, str) and not 'concat:' in file and not os.path.isfile(file): if isinstance(file, str) and 'concat:' not in file and not os.path.isfile(file):
success = False success = False
break break
if success and newList: if success and newList: