Skip to content

Commit

Permalink
Fix using len() to see if something is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
labrys committed Mar 19, 2016
1 parent e29431c commit d9bda40
Show file tree
Hide file tree
Showing 27 changed files with 75 additions and 76 deletions.
2 changes: 1 addition & 1 deletion sickbeard/clients/deluge_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _get_auth(self):
return None

hosts = self.response.json()['result']
if len(hosts) == 0:
if not hosts:
logger.log(self.name + u': WebUI does not contain daemons', logger.ERROR)
return None

Expand Down
2 changes: 1 addition & 1 deletion sickbeard/dailysearcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run(self, force=False): # pylint:disable=too-many-branches

sql_l.append(ep.get_sql())

if len(sql_l) > 0:
if sql_l:
main_db_con = db.DBConnection()
main_db_con.mass_action(sql_l)
else:
Expand Down
21 changes: 10 additions & 11 deletions sickbeard/failed_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,28 @@ def logFailed(release):
failed_db_con = db.DBConnection('failed.db')
sql_results = failed_db_con.select("SELECT * FROM history WHERE release=?", [release])

if len(sql_results) == 0:
logger.log(
u"Release not found in snatch history.", logger.WARNING)
elif len(sql_results) > 1:
if not sql_results:
logger.log(u"Release not found in snatch history.", logger.WARNING)
elif len(sql_results) == 1:
size = sql_results[0]["size"]
provider = sql_results[0]["provider"]
else:
logger.log(u"Multiple logged snatches found for release", logger.WARNING)
sizes = len(set(x["size"] for x in sql_results))
providers = len(set(x["provider"] for x in sql_results))
if sizes == 1:
logger.log(u"However, they're all the same size. Continuing with found size.", logger.WARNING)
logger.log(u"However, they're all the same size. "
u"Continuing with found size.", logger.WARNING)
size = sql_results[0]["size"]
else:
logger.log(
u"They also vary in size. Deleting the logged snatches and recording this release with no size/provider",
logger.WARNING)
logger.log(u"They also vary in size. Deleting the logged snatches and "
u"recording this release with no size/provider", logger.WARNING)
for result in sql_results:
deleteLoggedSnatch(result["release"], result["size"], result["provider"])

if providers == 1:
logger.log(u"They're also from the same provider. Using it as well.")
provider = sql_results[0]["provider"]
else:
size = sql_results[0]["size"]
provider = sql_results[0]["provider"]

if not hasFailed(release, size, provider):
failed_db_con = db.DBConnection('failed.db')
Expand Down
2 changes: 1 addition & 1 deletion sickbeard/generic_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def run(self, force=False):
self.currentItem = None

# if there's something in the queue then run it in a thread and take it out of the queue
if len(self.queue) > 0:
if self.queue:

# sort by priority
def sorter(x, y):
Expand Down
6 changes: 3 additions & 3 deletions sickbeard/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def indentXML(elem, level=0):
Does our pretty printing, makes Matt very happy
"""
i = "\n" + level * " "
if len(elem):
if elem:
if not elem.text or not elem.text.strip():
elem.text = i + " "
if not elem.tail or not elem.tail.strip():
Expand Down Expand Up @@ -738,7 +738,7 @@ def get_all_episodes_from_absolute_number(show, absolute_numbers, indexer_id=Non
episodes = []
season = None

if len(absolute_numbers):
if absolute_numbers:
if not show and indexer_id:
show = Show.find(sickbeard.showList, indexer_id)

Expand Down Expand Up @@ -1340,7 +1340,7 @@ def mapIndexersToShow(showObj):
"INSERT OR IGNORE INTO indexer_mapping (indexer_id, indexer, mindexer_id, mindexer) VALUES (?,?,?,?)",
[showObj.indexerid, showObj.indexer, int(mapped_show[0]['id']), indexer]])

if len(sql_l) > 0:
if sql_l:
main_db_con = db.DBConnection()
main_db_con.mass_action(sql_l)

Expand Down
4 changes: 2 additions & 2 deletions sickbeard/metadata/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def save_season_posters(self, show_obj, season):

cur_season_art = season_dict[cur_season]

if len(cur_season_art) == 0:
if not cur_season_art:
continue

# Just grab whatever's there for now
Expand Down Expand Up @@ -625,7 +625,7 @@ def save_season_banners(self, show_obj, season):

cur_season_art = season_dict[cur_season]

if len(cur_season_art) == 0:
if not cur_season_art:
continue

# Just grab whatever's there for now
Expand Down
16 changes: 8 additions & 8 deletions sickbeard/notifiers/emailnotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def notify_snatch(self, ep_name, title='Snatched:'): # pylint: disable=unused-a
if sickbeard.USE_EMAIL and sickbeard.EMAIL_NOTIFY_ONSNATCH:
show = self._parseEp(ep_name)
to = self._generate_recipients(show)
if len(to) == 0:
if not to:
logger.log('Skipping email notify because there are no configured recipients', logger.DEBUG)
else:
try:
Expand Down Expand Up @@ -113,7 +113,7 @@ def notify_download(self, ep_name, title='Completed:'): # pylint: disable=unuse
if sickbeard.USE_EMAIL and sickbeard.EMAIL_NOTIFY_ONDOWNLOAD:
show = self._parseEp(ep_name)
to = self._generate_recipients(show)
if len(to) == 0:
if not to:
logger.log('Skipping email notify because there are no configured recipients', logger.DEBUG)
else:
try:
Expand Down Expand Up @@ -159,7 +159,7 @@ def notify_subtitle_download(self, ep_name, lang, title='Downloaded subtitle:'):
if sickbeard.USE_EMAIL and sickbeard.EMAIL_NOTIFY_ONSUBTITLEDOWNLOAD:
show = self._parseEp(ep_name)
to = self._generate_recipients(show)
if len(to) == 0:
if not to:
logger.log('Skipping email notify because there are no configured recipients', logger.DEBUG)
else:
try:
Expand Down Expand Up @@ -199,7 +199,7 @@ def notify_git_update(self, new_version='??'):
'''
if sickbeard.USE_EMAIL:
to = self._generate_recipients(None)
if len(to) == 0:
if not to:
logger.log('Skipping email notify because there are no configured recipients', logger.DEBUG)
else:
try:
Expand Down Expand Up @@ -236,7 +236,7 @@ def notify_login(self, ipaddress=''):
'''
if sickbeard.USE_EMAIL:
to = self._generate_recipients(None)
if not len(to):
if not to:
logger.log('Skipping email notify because there are no configured recipients', logger.DEBUG)
else:
try:
Expand Down Expand Up @@ -274,7 +274,7 @@ def _generate_recipients(show): # pylint: disable=too-many-branches
# Grab the global recipients
if sickbeard.EMAIL_LIST:
for addr in sickbeard.EMAIL_LIST.split(','):
if len(addr.strip()) > 0:
if addr.strip():
addrs.append(addr)

# Grab the per-show-notification recipients
Expand All @@ -285,11 +285,11 @@ def _generate_recipients(show): # pylint: disable=too-many-branches
if subs[b'notify_list'][0] == '{':
entries = dict(ast.literal_eval(subs[b'notify_list']))
for addr in entries[b'emails'].split(','):
if len(addr.strip()) > 0:
if addr.strip():
addrs.append(addr)
else: # Legacy
for addr in subs[b'notify_list'].split(','):
if len(addr.strip()) > 0:
if addr.strip():
addrs.append(addr)

addrs = set(addrs)
Expand Down
12 changes: 6 additions & 6 deletions sickbeard/notifiers/prowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def notify_snatch(self, ep_name):
if sickbeard.PROWL_NOTIFY_ONSNATCH:
show = self._parse_episode(ep_name)
recipients = self._generate_recipients(show)
if len(recipients) == 0:
if not recipients:
logger.log('Skipping prowl notify because there are no configured recipients', logger.DEBUG)
else:
for api in recipients:
Expand All @@ -61,7 +61,7 @@ def notify_download(self, ep_name):
if sickbeard.PROWL_NOTIFY_ONDOWNLOAD:
show = self._parse_episode(ep_name)
recipients = self._generate_recipients(show)
if len(recipients) == 0:
if not recipients:
logger.log('Skipping prowl notify because there are no configured recipients', logger.DEBUG)
else:
for api in recipients:
Expand All @@ -73,7 +73,7 @@ def notify_subtitle_download(self, ep_name, lang):
if sickbeard.PROWL_NOTIFY_ONSUBTITLEDOWNLOAD:
show = self._parse_episode(ep_name)
recipients = self._generate_recipients(show)
if len(recipients) == 0:
if not recipients:
logger.log('Skipping prowl notify because there are no configured recipients', logger.DEBUG)
else:
for api in recipients:
Expand Down Expand Up @@ -102,7 +102,7 @@ def _generate_recipients(show=None):
# Grab the global recipient(s)
if sickbeard.PROWL_API:
for api in sickbeard.PROWL_API.split(','):
if len(api.strip()) > 0:
if api.strip():
apis.append(api)

# Grab the per-show-notification recipients
Expand All @@ -113,7 +113,7 @@ def _generate_recipients(show=None):
if subs['notify_list'][0] == '{': # legacy format handling
entries = dict(ast.literal_eval(subs['notify_list']))
for api in entries['prowlAPIs'].split(','):
if len(api.strip()) > 0:
if api.strip():
apis.append(api)

apis = set(apis)
Expand All @@ -127,7 +127,7 @@ def _send_prowl(prowl_api=None, prowl_priority=None, event=None, message=None, f

if prowl_api is None:
prowl_api = sickbeard.PROWL_API
if len(prowl_api) == 0:
if not prowl_api:
return False

if prowl_priority is None:
Expand Down
2 changes: 1 addition & 1 deletion sickbeard/numdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, iterable=None, **kwargs):
iterable = kwargs.pop('dict', None) if iterable is None else iterable
if iterable is not None:
self.update(iterable)
if len(kwargs):
if kwargs:
self.update(kwargs)

def __len__(self):
Expand Down
2 changes: 1 addition & 1 deletion sickbeard/nzbSplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def split_result(obj):
logger.log(u"Found " + new_nzb + " inside " + obj.name + " but it doesn't seem to belong to the same season, ignoring it",
logger.WARNING)
continue
elif len(parsed_obj.episode_numbers) == 0:
elif not parsed_obj.episode_numbers:
# pylint: disable=no-member
logger.log(u"Found " + new_nzb + " inside " + obj.name + " but it doesn't seem to be a valid episode NZB, ignoring it",
logger.WARNING)
Expand Down
6 changes: 3 additions & 3 deletions sickbeard/postProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def _history_lookup(self):
search_name = re.sub(r"[\.\- ]", "_", curName)
sql_results = main_db_con.select("SELECT showid, season, quality, version, resource FROM history WHERE resource LIKE ? AND (action % 100 = 4 OR action % 100 = 6)", [search_name])

if len(sql_results) == 0:
if not sql_results:
continue

indexer_id = int(sql_results[0]["showid"])
Expand Down Expand Up @@ -1166,7 +1166,7 @@ def process(self): # pylint: disable=too-many-return-statements, too-many-local
cur_ep.download_subtitles(force=True)

# now that processing has finished, we can put the info in the DB. If we do it earlier, then when processing fails, it won't try again.
if len(sql_l) > 0:
if sql_l:
main_db_con = db.DBConnection()
main_db_con.mass_action(sql_l)

Expand All @@ -1177,7 +1177,7 @@ def process(self): # pylint: disable=too-many-return-statements, too-many-local
cur_ep.location = ek(os.path.join, dest_path, new_file_name)
sql_l.append(cur_ep.get_sql())

if len(sql_l) > 0:
if sql_l:
main_db_con = db.DBConnection()
main_db_con.mass_action(sql_l)

Expand Down
2 changes: 1 addition & 1 deletion sickbeard/properFinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def _set_lastProperSearch(when):
main_db_con = db.DBConnection()
sql_results = main_db_con.select("SELECT last_proper_search FROM info")

if len(sql_results) == 0:
if not sql_results:
main_db_con.action("INSERT INTO info (last_backlog, last_indexer, last_proper_search) VALUES (?,?,?)",
[0, 0, str(when)])
else:
Expand Down
2 changes: 1 addition & 1 deletion sickbeard/providers/binsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def updateCache(self):
if ci:
cl.append(ci)

if len(cl) > 0:
if cl:
cache_db_con = self._getDB()
cache_db_con.mass_action(cl)

Expand Down
4 changes: 2 additions & 2 deletions sickbeard/providers/freshontv.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def search(self, search_params, age=0, ep_obj=None): # pylint: disable=too-many
else:
page_links = []

if len(page_links) > 0:
if page_links:
for lnk in page_links:
link_text = lnk.text.strip()
if link_text.isdigit():
Expand Down Expand Up @@ -181,7 +181,7 @@ def search(self, search_params, age=0, ep_obj=None): # pylint: disable=too-many
torrent_rows = html.findAll("tr", {"class": re.compile('torrent_[0-9]*')})

# Continue only if a Release is found
if len(torrent_rows) == 0:
if not torrent_rows:
logger.log(u"Data returned from provider does not contain any torrents", logger.DEBUG)
continue

Expand Down
2 changes: 1 addition & 1 deletion sickbeard/providers/newpct.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def download_result(self, result):
logger.log('Could not download {}'.format(url), logger.WARNING)
helpers.remove_file_failed(filename)

if len(urls):
if urls:
logger.log('Failed to download any results', logger.WARNING)

return False
Expand Down
4 changes: 2 additions & 2 deletions sickbeard/providers/tntvillage.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _episodeQuality(torrent_rows): # pylint: disable=too-many-return-statements

img_all = (torrent_rows.find_all('td'))[1].find_all('img')

if len(img_all) > 0:
if img_all:
for img_type in img_all:
try:
file_quality = file_quality + " " + img_type['src'].replace("style_images/mkportal-636/", "").replace(".gif", "").replace(".png", "")
Expand All @@ -197,7 +197,7 @@ def checkName(options, func):
hdOptions = checkName(["720p"], any)
fullHD = checkName(["1080p", "fullHD"], any)

if len(img_all) > 0:
if img_all:
file_quality = (torrent_rows.find_all('td'))[1].get_text()

webdl = checkName(["webdl", "webmux", "webrip", "dl-webmux", "web-dlmux", "webdl-mux", "web-dl", "webdlmux", "dlmux"], any)
Expand Down
2 changes: 1 addition & 1 deletion sickbeard/providers/womble.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def updateCache(self):
if ci:
cl.append(ci)

if len(cl) > 0:
if cl:
cache_db_con = self._getDB()
cache_db_con.mass_action(cl)

Expand Down
4 changes: 2 additions & 2 deletions sickbeard/scene_numbering.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def xem_refresh(indexer_id, indexer, force=False):
entry[sickbeard.indexerApi(indexer).config['xem_origin']]['episode']]
])

if len(cl) > 0:
if cl:
main_db_con = db.DBConnection()
main_db_con.mass_action(cl)

Expand Down Expand Up @@ -649,6 +649,6 @@ def fix_xem_numbering(indexer_id, indexer): # pylint:disable=too-many-locals, t
])
update_scene_absolute_number = False

if len(cl) > 0:
if cl:
main_db_con = db.DBConnection()
main_db_con.mass_action(cl)
4 changes: 2 additions & 2 deletions sickbeard/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def snatchEpisode(result, endStatus=SNATCHED): # pylint: disable=too-many-branc
if data:
notifiers.trakt_notifier.update_watchlist(result.show, data_episode=data, update="add")

if len(sql_l) > 0:
if sql_l:
main_db_con = db.DBConnection()
main_db_con.mass_action(sql_l)

Expand Down Expand Up @@ -540,7 +540,7 @@ def searchProviders(show, episodes, manualSearch=False, downCurQuality=False, ma

didSearch = True

if len(searchResults):
if searchResults:
# make a list of all the results for this provider
for curEp in searchResults:
if curEp in foundResults:
Expand Down

0 comments on commit d9bda40

Please sign in to comment.