making looking for duplicates case insensitive

This commit is contained in:
2013-07-29 09:40:35 +10:00
parent ac508047bd
commit eca7f5710b
3 changed files with 49 additions and 11 deletions

View File

@@ -35,12 +35,12 @@ class EncodeData:
errors = [] errors = []
if os.path.exists(self.outputfile): if checkfileexists(self.outputfile, False):
errors.append("FILE_EXISTS") errors.append("FILE_EXISTS")
if self.outputfile[-5:-4] == "_": if self.outputfile[-5:-4] == "_":
tempoutfile = self.outputfile[:-5] + self.outputfile[-4:] tempoutfile = self.outputfile[:-5] + self.outputfile[-4:]
if os.path.exists(tempoutfile): if checkfileexists(tempoutfile, False):
errors.append("FILE_EXISTS") errors.append("FILE_EXISTS")
return errors return errors
@@ -155,12 +155,19 @@ class FileManager:
return False return False
@staticmethod @staticmethod
def checkfileexists(filename): def checkfileexists(filename, casesensitive=True):
""" """
Check to see if a file currently exists Check to see if a file currently exists
""" """
if casesensitive:
return os.path.exists(filename)
else:
filename = os.path.basename(filename)
for dirfile in os.listdir(os.path.dirname(filename)):
if (filename.lower() == dirfile.lower()):
return True
return os.path.exists(filename) return False
def __getinputfilestoencode(self): def __getinputfilestoencode(self):
""" """
@@ -215,3 +222,17 @@ def findseason(path, filename, readonly):
os.makedirs(seasonpath) os.makedirs(seasonpath)
return seasonpath return seasonpath
def checkfileexists(filename, casesensitive=True):
"""
Check to see if a file currently exists
"""
if casesensitive:
return os.path.exists(filename)
else:
filename = os.path.basename(filename)
for dirfile in os.listdir(os.path.dirname(filename)):
if (filename.lower() == dirfile.lower()):
return True
return False

View File

@@ -22,49 +22,49 @@ IllegalCharacters = "?", ":"
KidsTVDir = "/srv/storage2/videos/Kids/TV/" KidsTVDir = "/srv/storage2/videos/Kids/TV/"
UnknownInput = "%(VideoProcessingDir)sUnknown/" UnknownInput = "%(VideoProcessingDir)sUnknown/"
[[ "Thomas the Tank Engine & Friends" ]] [[ "Thomas the Tank Engine & Friends" ]]
InputDirectory = "%(VideoProcessingDir)sThomas/Input/" InputDirectory = "%(VideoProcessingDir)sThomas/"
UnknownDirectory = "%(UnknownInput)sThomas/" UnknownDirectory = "%(UnknownInput)sThomas/"
OutputDirectory = "%(KidsTVDir)sThomas The Tank Engine & Friends/" OutputDirectory = "%(KidsTVDir)sThomas The Tank Engine & Friends/"
alias = "Thomas and Friends", alias = "Thomas and Friends",
MythTvEpisodePrefix = , MythTvEpisodePrefix = ,
SickbeardPrefix = "" SickbeardPrefix = ""
[[ "Chuggington" ]] [[ "Chuggington" ]]
InputDirectory = "%(VideoProcessingDir)sChuggington/Input/" InputDirectory = "%(VideoProcessingDir)sChuggington/"
UnknownDirectory = "%(UnknownInput)sChuggington/" UnknownDirectory = "%(UnknownInput)sChuggington/"
OutputDirectory = "%(KidsTVDir)sChuggington/" OutputDirectory = "%(KidsTVDir)sChuggington/"
alias = , alias = ,
MythTvEpisodePrefix = , MythTvEpisodePrefix = ,
SickbeardPrefix = "" SickbeardPrefix = ""
[[ "Mike the Knight" ]] [[ "Mike the Knight" ]]
InputDirectory = "%(VideoProcessingDir)sMikeTheKnight/Input/" InputDirectory = "%(VideoProcessingDir)sMikeTheKnight/"
UnknownDirectory = "%(UnknownInput)sMikeTheKnight/" UnknownDirectory = "%(UnknownInput)sMikeTheKnight/"
OutputDirectory = "%(KidsTVDir)sMike the Knight/" OutputDirectory = "%(KidsTVDir)sMike the Knight/"
alias = , alias = ,
MythTvEpisodePrefix = "Mike the Knight and the ", Mike the Knight and " MythTvEpisodePrefix = "Mike the Knight and the ", Mike the Knight and "
SickbeardPrefix = "" SickbeardPrefix = ""
[[ "Octonauts" ]] [[ "Octonauts" ]]
InputDirectory = "%(VideoProcessingDir)sOctonauts/Input/" InputDirectory = "%(VideoProcessingDir)sOctonauts/"
UnknownDirectory = "%(UnknownInput)sOctonauts/" UnknownDirectory = "%(UnknownInput)sOctonauts/"
OutputDirectory = "%(KidsTVDir)sOctonauts/" OutputDirectory = "%(KidsTVDir)sOctonauts/"
alias = "The Octonauts", alias = "The Octonauts",
MythTvEpisodePrefix = "The Octonauts and ", MythTvEpisodePrefix = "The Octonauts and ",
SickbeardPrefix = "The" SickbeardPrefix = "The"
[[ "In the Night Garden" ]] [[ "In the Night Garden" ]]
InputDirectory = "%(VideoProcessingDir)sInTheNightGarden/Input/" InputDirectory = "%(VideoProcessingDir)sInTheNightGarden/"
UnknownDirectory = "%(UnknownInput)sInTheNightGarden/" UnknownDirectory = "%(UnknownInput)sInTheNightGarden/"
OutputDirectory = "%(KidsTVDir)sIn The Night Garden/" OutputDirectory = "%(KidsTVDir)sIn The Night Garden/"
alias = , alias = ,
MythTvEpisodePrefix = , MythTvEpisodePrefix = ,
SickbeardPrefix = "" SickbeardPrefix = ""
[[ "Raa Raa! The Noisy Lion" ]] [[ "Raa Raa! The Noisy Lion" ]]
InputDirectory = "%(VideoProcessingDir)sRaaRaa/Input/" InputDirectory = "%(VideoProcessingDir)sRaaRaa/"
UnknownDirectory = "%(UnknownInput)sRaaRaa/" UnknownDirectory = "%(UnknownInput)sRaaRaa/"
OutputDirectory = "%(KidsTVDir)sRaa Raa the Noisy Lion/" OutputDirectory = "%(KidsTVDir)sRaa Raa the Noisy Lion/"
alias = , alias = ,
MythTvEpisodePrefix = , MythTvEpisodePrefix = ,
SickbeardPrefix = "" SickbeardPrefix = ""
[[ "Fireman Sam" ]] [[ "Fireman Sam" ]]
InputDirectory = "%(VideoProcessingDir)sFiremanSam/Input/" InputDirectory = "%(VideoProcessingDir)sFiremanSam/"
UnknownDirectory = "%(UnknownInput)sFiremanSam/" UnknownDirectory = "%(UnknownInput)sFiremanSam/"
OutputDirectory = "%(KidsTVDir)sFireman Sam/" OutputDirectory = "%(KidsTVDir)sFireman Sam/"
alias = , alias = ,

View File

@@ -36,6 +36,7 @@ class libfilemanagertest(unittest.TestCase):
result = data.checkproblems() result = data.checkproblems()
self.assertIn("FILE_EXISTS", result) self.assertIn("FILE_EXISTS", result)
minimock.restore()
def test_EncodeDataCheckProblemsFile_Exists(self): def test_EncodeDataCheckProblemsFile_Exists(self):
showname = "test show" showname = "test show"
@@ -45,6 +46,18 @@ class libfilemanagertest(unittest.TestCase):
mock("os.path.exists", returns_iter=[False, True]) mock("os.path.exists", returns_iter=[False, True])
result = data.checkproblems() result = data.checkproblems()
self.assertIn("FILE_EXISTS", result) self.assertIn("FILE_EXISTS", result)
minimock.restore()
def test_checkfileexistscaseinsensitive(self):
settings = Mock('libsettings.Settings')
filemanager = FileManager(settings)
mock("os.listdir", returns=["filename.test"])
result = filemanager.checkfileexists("/path/to/fiLename.test", False)
self.assertTrue(result)
minimock.restore()
def test_checkduplicateavi(self): def test_checkduplicateavi(self):
settings = Mock('libsettings.Settings') settings = Mock('libsettings.Settings')
@@ -55,6 +68,7 @@ class libfilemanagertest(unittest.TestCase):
result = filemanager.checkduplicates("/path/to/S03E14 - Test - SD TV.mkv") result = filemanager.checkduplicates("/path/to/S03E14 - Test - SD TV.mkv")
self.assertTrue(result) self.assertTrue(result)
minimock.restore()
def test_checkduplicatenomatch(self): def test_checkduplicatenomatch(self):
settings = Mock('libsettings.Settings') settings = Mock('libsettings.Settings')
@@ -65,6 +79,7 @@ class libfilemanagertest(unittest.TestCase):
result = filemanager.checkduplicates("/path/to/S03E13 - Test - SD TV.mkv") result = filemanager.checkduplicates("/path/to/S03E13 - Test - SD TV.mkv")
self.assertFalse(result) self.assertFalse(result)
minimock.restore()
def test_checkduplicatesameextension(self): def test_checkduplicatesameextension(self):
settings = Mock('libsettings.Settings') settings = Mock('libsettings.Settings')
@@ -75,6 +90,8 @@ class libfilemanagertest(unittest.TestCase):
result = filemanager.checkduplicates("/path/to/S03E14 - Test - SD TV.avi") result = filemanager.checkduplicates("/path/to/S03E14 - Test - SD TV.avi")
self.assertFalse(result) self.assertFalse(result)
minimock.restore()
def dummywalk(arg): def dummywalk(arg):