mirror of
https://github.com/SickGear/SickGear.git
synced 2024-11-23 21:35:05 +00:00
Change improve perf by using generators with any
.
This commit is contained in:
parent
40f09ea79a
commit
9fe62aa486
10 changed files with 24 additions and 22 deletions
|
@ -4,6 +4,8 @@
|
||||||
* Change remove calls to legacy py2 fix encoding function
|
* Change remove calls to legacy py2 fix encoding function
|
||||||
* Change requirements for pure py3
|
* Change requirements for pure py3
|
||||||
* Change codebase cleanups
|
* Change codebase cleanups
|
||||||
|
* Change improve perf by using generators with `any`
|
||||||
|
|
||||||
|
|
||||||
[develop changelog]
|
[develop changelog]
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@
|
||||||
#except
|
#except
|
||||||
#pass
|
#pass
|
||||||
#end try
|
#end try
|
||||||
#if not any([x in $body_attr for x in ['back-art', 'pro', 'ii']])
|
#if not any(x in $body_attr for x in ['back-art', 'pro', 'ii'])
|
||||||
#set $parts = $body_attr.split('class="')
|
#set $parts = $body_attr.split('class="')
|
||||||
#set $body_attr = ('class="%s '.join($parts), $parts[0] + ' class="%s"')[1 == len($parts)] % {0: '', 1: 'pro', 2: 'pro ii'}.get(getattr($sickgear, 'DISPLAY_SHOW_VIEWMODE', 0))
|
#set $body_attr = ('class="%s '.join($parts), $parts[0] + ' class="%s"')[1 == len($parts)] % {0: '', 1: 'pro', 2: 'pro ii'}.get(getattr($sickgear, 'DISPLAY_SHOW_VIEWMODE', 0))
|
||||||
#end if
|
#end if
|
||||||
|
|
|
@ -381,7 +381,7 @@ class Plex(object):
|
||||||
|
|
||||||
section_path = re.sub(r'[/\\]+', '/', section.find('Location').get('path').lower())
|
section_path = re.sub(r'[/\\]+', '/', section.find('Location').get('path').lower())
|
||||||
section_path = re.sub(r'^(.{,2})[/\\]', '', section_path)
|
section_path = re.sub(r'^(.{,2})[/\\]', '', section_path)
|
||||||
if not any([section_path in path for path in self.section_filter_path]):
|
if not any(section_path in path for path in self.section_filter_path):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if section.get('key') not in self.ignore_sections \
|
if section.get('key') not in self.ignore_sections \
|
||||||
|
|
|
@ -195,7 +195,7 @@ class ShowInfoFilter(object):
|
||||||
return isinstance(show_info, dict) \
|
return isinstance(show_info, dict) \
|
||||||
and 'seriesname' in show_info \
|
and 'seriesname' in show_info \
|
||||||
and isinstance(show_info['seriesname'], string_types) \
|
and isinstance(show_info['seriesname'], string_types) \
|
||||||
and any([x.search(show_info['seriesname']) for x in self.bad_names])
|
and any(x.search(show_info['seriesname']) for x in self.bad_names)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _fix_firstaired(show_info):
|
def _fix_firstaired(show_info):
|
||||||
|
|
|
@ -745,9 +745,9 @@ class NeededQualities(object):
|
||||||
else:
|
else:
|
||||||
if not self.need_sd and min(wanted_qualities) <= NeededQualities.max_sd:
|
if not self.need_sd and min(wanted_qualities) <= NeededQualities.max_sd:
|
||||||
self.need_sd = True
|
self.need_sd = True
|
||||||
if not self.need_hd and any([i in NeededQualities.hd_qualities for i in wanted_qualities]):
|
if not self.need_hd and any(i in NeededQualities.hd_qualities for i in wanted_qualities):
|
||||||
self.need_hd = True
|
self.need_hd = True
|
||||||
if not self.need_webdl and any([i in NeededQualities.webdl_qualities for i in wanted_qualities]):
|
if not self.need_webdl and any(i in NeededQualities.webdl_qualities for i in wanted_qualities):
|
||||||
self.need_webdl = True
|
self.need_webdl = True
|
||||||
if not self.need_uhd and max(wanted_qualities) > NeededQualities.max_hd:
|
if not self.need_uhd and max(wanted_qualities) > NeededQualities.max_hd:
|
||||||
self.need_uhd = True
|
self.need_uhd = True
|
||||||
|
|
|
@ -501,8 +501,8 @@ class GenericProvider(object):
|
||||||
if time_left > datetime.timedelta(seconds=0):
|
if time_left > datetime.timedelta(seconds=0):
|
||||||
if log_warning:
|
if log_warning:
|
||||||
# Ensure provider name output (e.g. when displaying config/provs) instead of e.g. thread "Tornado"
|
# Ensure provider name output (e.g. when displaying config/provs) instead of e.g. thread "Tornado"
|
||||||
prepend = ('[%s] :: ' % self.name, '')[any([x.name in threading.current_thread().name
|
prepend = ('[%s] :: ' % self.name, '')[any(x.name in threading.current_thread().name
|
||||||
for x in sickgear.providers.sorted_sources()])]
|
for x in sickgear.providers.sorted_sources())]
|
||||||
logger.log('%sToo many requests reached at %s, waiting for %s' % (
|
logger.log('%sToo many requests reached at %s, waiting for %s' % (
|
||||||
prepend, self.fmt_delta(self.tmr_limit_time), self.fmt_delta(time_left)), logger.WARNING)
|
prepend, self.fmt_delta(self.tmr_limit_time), self.fmt_delta(time_left)), logger.WARNING)
|
||||||
return use_tmr_limit
|
return use_tmr_limit
|
||||||
|
@ -1009,9 +1009,9 @@ class GenericProvider(object):
|
||||||
|
|
||||||
headers = [re.sub(
|
headers = [re.sub(
|
||||||
r'\s+', '',
|
r'\s+', '',
|
||||||
((any([cell.get_text()]) and any([rc[x].search(cell.get_text()) for x in iterkeys(rc)]) and cell.get_text())
|
((any([cell.get_text()]) and any(rc[x].search(cell.get_text()) for x in iterkeys(rc)) and cell.get_text())
|
||||||
or (cell.attrs.get('id') and any([rc[x].search(cell['id']) for x in iterkeys(rc)]) and cell['id'])
|
or (cell.attrs.get('id') and any(rc[x].search(cell['id']) for x in iterkeys(rc)) and cell['id'])
|
||||||
or (cell.attrs.get('title') and any([rc[x].search(cell['title']) for x in iterkeys(rc)]) and cell['title'])
|
or (cell.attrs.get('title') and any(rc[x].search(cell['title']) for x in iterkeys(rc)) and cell['title'])
|
||||||
or next(iter(set(filter(lambda rz: any([rz]), [
|
or next(iter(set(filter(lambda rz: any([rz]), [
|
||||||
next(iter(set(filter(lambda ry: any([ry]), [
|
next(iter(set(filter(lambda ry: any([ry]), [
|
||||||
cell.find(tag, **p) for p in [{attr: rc[x]} for x in iterkeys(rc)]]))), {}).get(attr)
|
cell.find(tag, **p) for p in [{attr: rc[x]} for x in iterkeys(rc)]]))), {}).get(attr)
|
||||||
|
@ -1932,7 +1932,7 @@ class TorrentProvider(GenericProvider):
|
||||||
url_list = list(map(lambda u: '%s/' % u.rstrip('/'), url_list))
|
url_list = list(map(lambda u: '%s/' % u.rstrip('/'), url_list))
|
||||||
last_url, expire = sickgear.PROVIDER_HOMES.get(self.get_id(), ('', None))
|
last_url, expire = sickgear.PROVIDER_HOMES.get(self.get_id(), ('', None))
|
||||||
url_drop = (url_exclude or []) + getattr(self, 'url_drop', [])
|
url_drop = (url_exclude or []) + getattr(self, 'url_drop', [])
|
||||||
if url_drop and any([url in last_url for url in url_drop]): # deprecate url
|
if url_drop and any(url in last_url for url in url_drop): # deprecate url
|
||||||
last_url = ''
|
last_url = ''
|
||||||
|
|
||||||
if 'site down' == last_url:
|
if 'site down' == last_url:
|
||||||
|
|
|
@ -911,9 +911,9 @@ class NewznabProvider(generic.NZBProvider):
|
||||||
# category ids
|
# category ids
|
||||||
cat = []
|
cat = []
|
||||||
if 'Episode' == mode or 'Season' == mode:
|
if 'Episode' == mode or 'Season' == mode:
|
||||||
if not (any([x in params for x in
|
if not (any(x in params for x in
|
||||||
[v for c, v in iteritems(self.caps)
|
[v for c, v in iteritems(self.caps)
|
||||||
if c not in [NewznabConstants.SEARCH_EPISODE, NewznabConstants.SEARCH_SEASON]]])):
|
if c not in [NewznabConstants.SEARCH_EPISODE, NewznabConstants.SEARCH_SEASON]])):
|
||||||
logger.log('Show is missing either an id or search term for search')
|
logger.log('Show is missing either an id or search term for search')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -938,7 +938,7 @@ class NewznabProvider(generic.NZBProvider):
|
||||||
request_params = base_params.copy()
|
request_params = base_params.copy()
|
||||||
# if ('Propers' == mode or 'nzbs_org' == self.get_id()) \
|
# if ('Propers' == mode or 'nzbs_org' == self.get_id()) \
|
||||||
if 'Propers' == mode \
|
if 'Propers' == mode \
|
||||||
and 'q' in params and not (any([x in params for x in ['season', 'ep']])):
|
and 'q' in params and not (any(x in params for x in ['season', 'ep'])):
|
||||||
request_params['t'] = 'search'
|
request_params['t'] = 'search'
|
||||||
request_params.update(params)
|
request_params.update(params)
|
||||||
|
|
||||||
|
@ -1048,10 +1048,10 @@ class NewznabProvider(generic.NZBProvider):
|
||||||
if exit_log:
|
if exit_log:
|
||||||
self._log_search(mode, len(results), search_url)
|
self._log_search(mode, len(results), search_url)
|
||||||
|
|
||||||
if not try_all_searches and any([x in request_params for x in [
|
if not try_all_searches and any(x in request_params for x in [
|
||||||
v for c, v in iteritems(self.caps)
|
v for c, v in iteritems(self.caps)
|
||||||
if c not in [NewznabConstants.SEARCH_EPISODE, NewznabConstants.SEARCH_SEASON,
|
if c not in [NewznabConstants.SEARCH_EPISODE, NewznabConstants.SEARCH_SEASON,
|
||||||
NewznabConstants.SEARCH_TEXT]]]) and len(results):
|
NewznabConstants.SEARCH_TEXT]]) and len(results):
|
||||||
break
|
break
|
||||||
|
|
||||||
return results, n_spaces
|
return results, n_spaces
|
||||||
|
|
|
@ -583,6 +583,6 @@ def has_abs_episodes(ep_obj=None, name=None):
|
||||||
:return:
|
:return:
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
return any([(name or ep_obj.show_obj.name or '').lower().startswith(x.lower()) for x in [
|
return any((name or ep_obj.show_obj.name or '').lower().startswith(x.lower()) for x in [
|
||||||
'The Eighties', 'The Making of the Mob', 'The Night Of', 'Roots 2016', 'Trepalium'
|
'The Eighties', 'The Making of the Mob', 'The Night Of', 'Roots 2016', 'Trepalium'
|
||||||
]])
|
])
|
||||||
|
|
|
@ -3042,7 +3042,7 @@ class TVShow(TVShowBase):
|
||||||
page_url = 'https://www.imdb.com/title/{0}/'.format(imdb_id)
|
page_url = 'https://www.imdb.com/title/{0}/'.format(imdb_id)
|
||||||
try:
|
try:
|
||||||
response = requests.head(page_url, allow_redirects=True)
|
response = requests.head(page_url, allow_redirects=True)
|
||||||
if response.history and any([h for h in response.history if 301 == h.status_code]):
|
if response.history and any(h for h in response.history if 301 == h.status_code):
|
||||||
return helpers.parse_imdb_id(response.url)
|
return helpers.parse_imdb_id(response.url)
|
||||||
except (BaseException, Exception):
|
except (BaseException, Exception):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -600,7 +600,7 @@ class ApiCall(object):
|
||||||
elif isinstance(value, string_types):
|
elif isinstance(value, string_types):
|
||||||
if '|' in value:
|
if '|' in value:
|
||||||
li = [int(v) for v in value.split('|')]
|
li = [int(v) for v in value.split('|')]
|
||||||
if any([not isinstance(v, integer_types) for v in li]):
|
if any(not isinstance(v, integer_types) for v in li):
|
||||||
error = True
|
error = True
|
||||||
else:
|
else:
|
||||||
value = li
|
value = li
|
||||||
|
@ -610,7 +610,7 @@ class ApiCall(object):
|
||||||
error = True
|
error = True
|
||||||
else:
|
else:
|
||||||
li = value.split('|')
|
li = value.split('|')
|
||||||
if any([sub_type is not type(v) for v in li]):
|
if any(sub_type is not type(v) for v in li):
|
||||||
error = True
|
error = True
|
||||||
else:
|
else:
|
||||||
value = li
|
value = li
|
||||||
|
|
Loading…
Reference in a new issue