mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 21:03:14 -07:00
Merge pull request #1599 from clinton-hall/flake8/bugbear
Flake8/bugbear
This commit is contained in:
commit
aeed469c5f
9 changed files with 27 additions and 20 deletions
|
@ -504,7 +504,7 @@ def get_release(base_url, imdb_id=None, download_id=None, release_id=None):
|
||||||
# Narrow results by removing old releases by comparing their last_edit field
|
# Narrow results by removing old releases by comparing their last_edit field
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
for id1, x1 in results.items():
|
for id1, x1 in results.items():
|
||||||
for id2, x2 in results.items():
|
for x2 in results.values():
|
||||||
try:
|
try:
|
||||||
if x2['last_edit'] > x1['last_edit']:
|
if x2['last_edit'] > x1['last_edit']:
|
||||||
results.pop(id1)
|
results.pop(id1)
|
||||||
|
|
|
@ -13,17 +13,17 @@ from core import logger
|
||||||
|
|
||||||
|
|
||||||
class Section(configobj.Section, object):
|
class Section(configobj.Section, object):
|
||||||
def isenabled(section):
|
def isenabled(self):
|
||||||
# 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 {}
|
||||||
if not section.sections:
|
if not self.sections:
|
||||||
try:
|
try:
|
||||||
value = list(ConfigObj.find_key(section, 'enabled'))[0]
|
value = list(ConfigObj.find_key(self, 'enabled'))[0]
|
||||||
except Exception:
|
except Exception:
|
||||||
value = 0
|
value = 0
|
||||||
if int(value) == 1:
|
if int(value) == 1:
|
||||||
return section
|
return self
|
||||||
else:
|
else:
|
||||||
to_return = copy.deepcopy(section)
|
to_return = copy.deepcopy(self)
|
||||||
for section_name, subsections in to_return.items():
|
for section_name, subsections in to_return.items():
|
||||||
for subsection in subsections:
|
for subsection in subsections:
|
||||||
try:
|
try:
|
||||||
|
@ -40,8 +40,8 @@ class Section(configobj.Section, object):
|
||||||
|
|
||||||
return to_return
|
return to_return
|
||||||
|
|
||||||
def findsection(section, key):
|
def findsection(self, key):
|
||||||
to_return = copy.deepcopy(section)
|
to_return = copy.deepcopy(self)
|
||||||
for subsection in to_return:
|
for subsection in to_return:
|
||||||
try:
|
try:
|
||||||
value = list(ConfigObj.find_key(to_return[subsection], key))[0]
|
value = list(ConfigObj.find_key(to_return[subsection], key))[0]
|
||||||
|
@ -136,10 +136,10 @@ class ConfigObj(configobj.ConfigObj, Section):
|
||||||
|
|
||||||
subsections = {}
|
subsections = {}
|
||||||
# gather all new-style and old-style sub-sections
|
# gather all new-style and old-style sub-sections
|
||||||
for newsection, newitems in CFG_NEW.items():
|
for newsection in CFG_NEW:
|
||||||
if CFG_NEW[newsection].sections:
|
if CFG_NEW[newsection].sections:
|
||||||
subsections.update({newsection: CFG_NEW[newsection].sections})
|
subsections.update({newsection: CFG_NEW[newsection].sections})
|
||||||
for section, items in CFG_OLD.items():
|
for section in CFG_OLD:
|
||||||
if CFG_OLD[section].sections:
|
if CFG_OLD[section].sections:
|
||||||
subsections.update({section: CFG_OLD[section].sections})
|
subsections.update({section: CFG_OLD[section].sections})
|
||||||
for option, value in CFG_OLD[section].items():
|
for option, value in CFG_OLD[section].items():
|
||||||
|
|
|
@ -6,6 +6,7 @@ import sys
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import core
|
import core
|
||||||
|
import functools
|
||||||
|
|
||||||
# number of log files to keep
|
# number of log files to keep
|
||||||
NUM_LOGS = 3
|
NUM_LOGS = 3
|
||||||
|
@ -199,9 +200,8 @@ class NTMRotatingLogHandler(object):
|
||||||
ntm_logger = logging.getLogger('nzbtomedia')
|
ntm_logger = logging.getLogger('nzbtomedia')
|
||||||
pp_logger = logging.getLogger('postprocess')
|
pp_logger = logging.getLogger('postprocess')
|
||||||
db_logger = logging.getLogger('db')
|
db_logger = logging.getLogger('db')
|
||||||
setattr(pp_logger, 'postprocess', lambda *args: pp_logger.log(POSTPROCESS, *args))
|
pp_logger.postprocess = functools.partial(pp_logger.log, POSTPROCESS)
|
||||||
setattr(db_logger, 'db', lambda *args: db_logger.log(DB, *args))
|
db_logger.db = functools.partial(db_logger.log, DB)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if log_level == DEBUG:
|
if log_level == DEBUG:
|
||||||
if core.LOG_DEBUG == 1:
|
if core.LOG_DEBUG == 1:
|
||||||
|
|
|
@ -121,7 +121,7 @@ def reverse_filename(filename, dirname, name):
|
||||||
|
|
||||||
def rename_script(dirname):
|
def rename_script(dirname):
|
||||||
rename_file = ''
|
rename_file = ''
|
||||||
for directory, directories, files in os.walk(dirname):
|
for directory, _, files in os.walk(dirname):
|
||||||
for file in files:
|
for file in files:
|
||||||
if re.search(r'(rename\S*\.(sh|bat)$)', file, re.IGNORECASE):
|
if re.search(r'(rename\S*\.(sh|bat)$)', file, re.IGNORECASE):
|
||||||
rename_file = os.path.join(directory, file)
|
rename_file = os.path.join(directory, file)
|
||||||
|
|
|
@ -519,7 +519,7 @@ def get_subs(file):
|
||||||
sub_ext = ['.srt', '.sub', '.idx']
|
sub_ext = ['.srt', '.sub', '.idx']
|
||||||
name = os.path.splitext(os.path.split(file)[1])[0]
|
name = os.path.splitext(os.path.split(file)[1])[0]
|
||||||
path = os.path.split(file)[0]
|
path = os.path.split(file)[0]
|
||||||
for directory, directories, filenames in os.walk(path):
|
for directory, _, filenames in os.walk(path):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
filepaths.extend([os.path.join(directory, filename)])
|
filepaths.extend([os.path.join(directory, filename)])
|
||||||
subfiles = [item for item in filepaths if os.path.splitext(item)[1] in sub_ext and name in item]
|
subfiles = [item for item in filepaths if os.path.splitext(item)[1] in sub_ext and name in item]
|
||||||
|
|
|
@ -47,7 +47,7 @@ def external_script(output_destination, torrent_name, torrent_label, settings):
|
||||||
logger.info('Corrupt video file found {0}. Deleting.'.format(video), 'USERSCRIPT')
|
logger.info('Corrupt video file found {0}. Deleting.'.format(video), 'USERSCRIPT')
|
||||||
os.unlink(video)
|
os.unlink(video)
|
||||||
|
|
||||||
for dirpath, dirnames, filenames in os.walk(output_destination):
|
for dirpath, _, filenames in os.walk(output_destination):
|
||||||
for file in filenames:
|
for file in filenames:
|
||||||
|
|
||||||
file_path = core.os.path.join(dirpath, file)
|
file_path = core.os.path.join(dirpath, file)
|
||||||
|
@ -102,7 +102,7 @@ def external_script(output_destination, torrent_name, torrent_label, settings):
|
||||||
final_result += result
|
final_result += result
|
||||||
|
|
||||||
num_files_new = 0
|
num_files_new = 0
|
||||||
for dirpath, dirnames, filenames in os.walk(output_destination):
|
for _, _, filenames in os.walk(output_destination):
|
||||||
for file in filenames:
|
for file in filenames:
|
||||||
file_name, file_extension = os.path.splitext(file)
|
file_name, file_extension = os.path.splitext(file)
|
||||||
|
|
||||||
|
|
|
@ -68,14 +68,14 @@ def convert_to_ascii(input_name, dir_name):
|
||||||
if 'NZBOP_SCRIPTDIR' in os.environ:
|
if 'NZBOP_SCRIPTDIR' in os.environ:
|
||||||
print('[NZB] DIRECTORY={0}'.format(dir_name))
|
print('[NZB] DIRECTORY={0}'.format(dir_name))
|
||||||
|
|
||||||
for dirname, dirnames, filenames in os.walk(dir_name, topdown=False):
|
for dirname, dirnames, _ in os.walk(dir_name, topdown=False):
|
||||||
for subdirname in dirnames:
|
for subdirname in dirnames:
|
||||||
encoded, subdirname2 = char_replace(subdirname)
|
encoded, subdirname2 = char_replace(subdirname)
|
||||||
if encoded:
|
if encoded:
|
||||||
logger.info('Renaming directory to: {0}.'.format(subdirname2), 'ENCODER')
|
logger.info('Renaming directory to: {0}.'.format(subdirname2), 'ENCODER')
|
||||||
os.rename(os.path.join(dirname, subdirname), os.path.join(dirname, subdirname2))
|
os.rename(os.path.join(dirname, subdirname), os.path.join(dirname, subdirname2))
|
||||||
|
|
||||||
for dirname, dirnames, filenames in os.walk(dir_name):
|
for dirname, _, filenames in os.walk(dir_name):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
encoded, filename2 = char_replace(filename)
|
encoded, filename2 = char_replace(filename)
|
||||||
if encoded:
|
if encoded:
|
||||||
|
|
|
@ -487,7 +487,7 @@ class SourceUpdateManager(UpdateManager):
|
||||||
# walk temp folder and move files to main folder
|
# walk temp folder and move files to main folder
|
||||||
logger.log(u'Moving files from {source} to {destination}'.format
|
logger.log(u'Moving files from {source} to {destination}'.format
|
||||||
(source=content_dir, destination=core.APP_ROOT))
|
(source=content_dir, destination=core.APP_ROOT))
|
||||||
for dirname, dirnames, filenames in os.walk(content_dir): # @UnusedVariable
|
for dirname, _, filenames in os.walk(content_dir): # @UnusedVariable
|
||||||
dirname = dirname[len(content_dir) + 1:]
|
dirname = dirname[len(content_dir) + 1:]
|
||||||
for curfile in filenames:
|
for curfile in filenames:
|
||||||
old_path = os.path.join(content_dir, dirname, curfile)
|
old_path = os.path.join(content_dir, dirname, curfile)
|
||||||
|
|
7
tox.ini
7
tox.ini
|
@ -33,6 +33,12 @@ commands =
|
||||||
max-line-length = 79
|
max-line-length = 79
|
||||||
verbose = 2
|
verbose = 2
|
||||||
statistics = True
|
statistics = True
|
||||||
|
select =
|
||||||
|
; -- flake8-bugbear --
|
||||||
|
; B902 Invalid first argument used for instance method.
|
||||||
|
; B903 Data class should either be immutable or use __slots__ to save memory.
|
||||||
|
B902, B903
|
||||||
|
|
||||||
ignore =
|
ignore =
|
||||||
; -- flake8 --
|
; -- flake8 --
|
||||||
; E501 line too long
|
; E501 line too long
|
||||||
|
@ -65,6 +71,7 @@ per-file-ignores =
|
||||||
[testenv:check]
|
[testenv:check]
|
||||||
deps =
|
deps =
|
||||||
flake8
|
flake8
|
||||||
|
flake8-bugbear
|
||||||
flake8-commas
|
flake8-commas
|
||||||
flake8-comprehensions
|
flake8-comprehensions
|
||||||
flake8-docstrings
|
flake8-docstrings
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue