Fix for startup issue when using python 2.6

This commit is contained in:
echel0n 2014-05-01 04:36:16 -07:00
parent 271afb8c5d
commit 3cefc5be86
3 changed files with 72 additions and 75 deletions

View file

@ -283,7 +283,7 @@ def makeDir(path):
def searchDBForShow(regShowName):
showNames = list({re.sub('[. -]', ' ', regShowName), regShowName})
showNames = list(set([re.sub('[. -]', ' ', regShowName), regShowName]))
myDB = db.DBConnection()
@ -309,7 +309,7 @@ def searchDBForShow(regShowName):
return (int(sqlResults[0]["indexer"]), int(sqlResults[0]["indexer_id"]), sqlResults[0]["show_name"])
def searchIndexerForShowID(regShowName, indexer=None, indexer_id=None, ui=None):
showNames = list({re.sub('[. -]', ' ', regShowName), regShowName})
showNames = list(set([re.sub('[. -]', ' ', regShowName), regShowName]))
# Query Indexers for each search term and build the list of results
for i in sickbeard.indexerApi().indexers if not indexer else int(indexer or []):
@ -942,7 +942,7 @@ def _check_against_names(name, show):
return False
def get_show_by_name(name, useIndexer=False):
def get_show_by_name(name, checkExceptions=False, checkIndexers=False):
in_cache = False
foundResult = None
@ -952,9 +952,9 @@ def get_show_by_name(name, useIndexer=False):
cacheResult = sickbeard.name_cache.retrieveNameFromCache(name)
if cacheResult:
in_cache = True
foundResult = findCertainShow(sickbeard.showList, cacheResult)
if foundResult:
in_cache = True
logger.log(
u"Cache lookup found Indexer ID:" + repr(
foundResult.indexerid) + ", using that for " + name,
@ -962,19 +962,7 @@ def get_show_by_name(name, useIndexer=False):
if not foundResult:
logger.log(
u"Checking the showlist for:" + str(name),
logger.DEBUG)
for show in sickbeard.showList:
if _check_against_names(name, show):
logger.log(
u"Showlist lookup found Indexer ID:" + str(show.indexerid) + ", using that for " + name,
logger.DEBUG)
foundResult = show
if not foundResult:
logger.log(
u"Checking the database for show:" + str(name),
u"Checking the database for:" + str(name),
logger.DEBUG)
dbResult = searchDBForShow(name)
@ -985,7 +973,20 @@ def get_show_by_name(name, useIndexer=False):
u"Database lookup found Indexer ID:" + str(
foundResult.indexerid) + ", using that for " + name, logger.DEBUG)
if not foundResult and useIndexer:
if not foundResult and checkExceptions:
if not foundResult:
logger.log(
u"Checking the scene exceptions list for:" + str(name),
logger.DEBUG)
for show in sickbeard.showList:
if _check_against_names(name, show):
logger.log(
u"Scene exceptions lookup found Indexer ID:" + str(show.indexerid) + ", using that for " + name,
logger.DEBUG)
foundResult = show
if not foundResult and checkIndexers:
logger.log(
u"Checking the Indexers for:" + str(name),
logger.DEBUG)
@ -1005,7 +1006,7 @@ def get_show_by_name(name, useIndexer=False):
foundResult = findCertainShow(sickbeard.showList, int(showObj["id"]))
if foundResult:
logger.log(
u"Indexer lookup found Indexer ID:" + str(
u"Indexers lookup found Indexer ID:" + str(
foundResult.indexerid) + ", using that for " + name, logger.DEBUG)
# add to name cache if we didn't get it from the cache

View file

@ -361,34 +361,34 @@ class ParseResult(object):
if len(self.episode_numbers) == 0: return self # need at least one episode
# convert scene numbered releases before storing to cache
showObj = helpers.get_show_by_name(self.series_name)
if showObj:
self.show = showObj
self.show = helpers.get_show_by_name(self.series_name)
if not self.show:
return self
new_episode_numbers = []
new_season_numbers = []
for epNo in self.episode_numbers:
(s, e) = scene_numbering.get_indexer_numbering(showObj.indexerid, self.season_number, epNo)
new_episode_numbers.append(e)
new_season_numbers.append(s)
new_episode_numbers = []
new_season_numbers = []
for epNo in self.episode_numbers:
(s, e) = scene_numbering.get_indexer_numbering(self.show.indexerid, self.season_number, epNo)
new_episode_numbers.append(e)
new_season_numbers.append(s)
# need to do a quick sanity check here. It's possible that we now have episodes
# from more than one season (by tvdb numbering), and this is just too much
# for sickbeard, so we'd need to flag it.
new_season_numbers = list(set(new_season_numbers)) # remove duplicates
if len(new_season_numbers) > 1:
raise InvalidNameException("Scene numbering results episodes from "
"seasons %s, (i.e. more than one) and "
"sickbeard does not support this. "
"Sorry." % (str(new_season_numbers)))
# need to do a quick sanity check here. It's possible that we now have episodes
# from more than one season (by tvdb numbering), and this is just too much
# for sickbeard, so we'd need to flag it.
new_season_numbers = list(set(new_season_numbers)) # remove duplicates
if len(new_season_numbers) > 1:
raise InvalidNameException("Scene numbering results episodes from "
"seasons %s, (i.e. more than one) and "
"sickbeard does not support this. "
"Sorry." % (str(new_season_numbers)))
# I guess it's possible that we'd have duplicate episodes too, so lets
# eliminate them
new_episode_numbers = list(set(new_episode_numbers))
new_episode_numbers.sort()
# I guess it's possible that we'd have duplicate episodes too, so lets
# eliminate them
new_episode_numbers = list(set(new_episode_numbers))
new_episode_numbers.sort()
self.episode_numbers = new_episode_numbers
self.season_number = new_season_numbers[0]
self.episode_numbers = new_episode_numbers
self.season_number = new_season_numbers[0]
return self

View file

@ -28,9 +28,8 @@ sys.path.append(os.path.abspath('../lib'))
import test_lib as test
import sickbeard
from sickbeard.helpers import get_show_by_name
from sickbeard.helpers import sanitizeSceneName, custom_strftime
from sickbeard.tv import TVShow
from sickbeard.name_parser.parser import NameParser, InvalidNameException
class XEMBasicTests(test.SickbeardTestDBCase):
def loadFromDB(self):
@ -48,44 +47,41 @@ class XEMBasicTests(test.SickbeardTestDBCase):
except Exception, e:
print "There was an error creating the show"
def test_parsing_scene_release(self):
def test_formating(self):
self.loadFromDB()
show = sickbeard.helpers.findCertainShow(sickbeard.showList, 75978)
ep = show.getEpisode(7, 6)
ep.airdate = datetime.datetime.now()
# parse the file name
scene_parsse_results1 = ''
scene_parsse_results2 = ''
scene_release = 'Pawn Stars S08E41 Field Trip HDTV x264-tNe'
try:
myParser = NameParser(False, 1)
scene_parsse_results1 = myParser.parse(scene_release)
scene_parsse_results2 = myParser.parse(scene_release).convert()
except InvalidNameException:
print(u"Unable to parse the filename " + scene_release + " into a valid episode")
print format(ep.episode, '02d')
print format(ep.scene_episode, '02d')
print scene_parsse_results1
print scene_parsse_results2
search_string = {'Episode':[]}
episode = ep.airdate
str(episode).replace('-', '|')
ep_string = sanitizeSceneName(show.name) + ' ' + \
str(episode).replace('-', '|') + '|' + \
sickbeard.helpers.custom_strftime('%b', episode)
sports_release = 'UFC.168.Weidman.vs.Silva.II.28th.Dec.2013.HDTV.x264-Sir.Paul'
try:
myParser = NameParser(False, 2)
parse_result = myParser.parse(sports_release)
search_string['Episode'].append(ep_string)
test = sickbeard.show_name_helpers.allPossibleShowNames(parse_result.series_name)
show = get_show_by_name(parse_result.series_name)
if show:
sql_results = test.db.DBConnection().select(
"SELECT season, episode FROM tv_episodes WHERE showid = ? AND airdate = ?",
[show.indexerid, parse_result.sports_event_date.toordinal()])
scene_ep_string = sanitizeSceneName(show.name) + ' ' + \
sickbeard.config.naming_ep_type[2] % {'seasonnumber': ep.scene_season,
'episodenumber': ep.scene_episode} + '|' + \
sickbeard.config.naming_ep_type[0] % {'seasonnumber': ep.scene_season,
'episodenumber': ep.scene_episode} + '|' + \
sickbeard.config.naming_ep_type[3] % {'seasonnumber': ep.scene_season,
'episodenumber': ep.scene_episode} + ' %s category:tv' % ''
actual_season = int(sql_results[0]["season"])
actual_episodes = [int(sql_results[0]["episode"])]
scene_season_string = show.name + ' S%02d' % int(ep.scene_season) + ' -S%02d' % int(ep.scene_season) + 'E' + ' category:tv' #1) ShowName SXX -SXXE
print actual_season
print actual_episodes
except InvalidNameException:
print(u"Unable to parse the filename " + scene_release + " into a valid episode")
print scene_parsse_results1
print(
u'Searching "%s" for "%s" as "%s"' % (show.name, ep.prettyName(), ep.scene_prettyName()))
print('Scene episode search strings: %s' % (scene_ep_string))
print('Scene season search strings: %s' % (scene_season_string))
if __name__ == "__main__":
print "=================="