From eca7f5710b978af6b39491114a19c19228443160 Mon Sep 17 00:00:00 2001 From: Shane Frischkorn Date: Mon, 29 Jul 2013 09:40:35 +1000 Subject: [PATCH] making looking for duplicates case insensitive --- libfilemanager.py | 29 +++++++++++++++++++++++++---- settings.cfg | 14 +++++++------- tests/libfilemanagertest.py | 17 +++++++++++++++++ 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/libfilemanager.py b/libfilemanager.py index 3faa963..b697c82 100644 --- a/libfilemanager.py +++ b/libfilemanager.py @@ -35,12 +35,12 @@ class EncodeData: errors = [] - if os.path.exists(self.outputfile): + if checkfileexists(self.outputfile, False): errors.append("FILE_EXISTS") if self.outputfile[-5:-4] == "_": tempoutfile = self.outputfile[:-5] + self.outputfile[-4:] - if os.path.exists(tempoutfile): + if checkfileexists(tempoutfile, False): errors.append("FILE_EXISTS") return errors @@ -155,12 +155,19 @@ class FileManager: return False @staticmethod - def checkfileexists(filename): + 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 os.path.exists(filename) + return False def __getinputfilestoencode(self): """ @@ -215,3 +222,17 @@ def findseason(path, filename, readonly): os.makedirs(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 diff --git a/settings.cfg b/settings.cfg index 286ed6b..b84c6ca 100644 --- a/settings.cfg +++ b/settings.cfg @@ -22,49 +22,49 @@ IllegalCharacters = "?", ":" KidsTVDir = "/srv/storage2/videos/Kids/TV/" UnknownInput = "%(VideoProcessingDir)sUnknown/" [[ "Thomas the Tank Engine & Friends" ]] - InputDirectory = "%(VideoProcessingDir)sThomas/Input/" + InputDirectory = "%(VideoProcessingDir)sThomas/" UnknownDirectory = "%(UnknownInput)sThomas/" OutputDirectory = "%(KidsTVDir)sThomas The Tank Engine & Friends/" alias = "Thomas and Friends", MythTvEpisodePrefix = , SickbeardPrefix = "" [[ "Chuggington" ]] - InputDirectory = "%(VideoProcessingDir)sChuggington/Input/" + InputDirectory = "%(VideoProcessingDir)sChuggington/" UnknownDirectory = "%(UnknownInput)sChuggington/" OutputDirectory = "%(KidsTVDir)sChuggington/" alias = , MythTvEpisodePrefix = , SickbeardPrefix = "" [[ "Mike the Knight" ]] - InputDirectory = "%(VideoProcessingDir)sMikeTheKnight/Input/" + InputDirectory = "%(VideoProcessingDir)sMikeTheKnight/" UnknownDirectory = "%(UnknownInput)sMikeTheKnight/" OutputDirectory = "%(KidsTVDir)sMike the Knight/" alias = , MythTvEpisodePrefix = "Mike the Knight and the ", Mike the Knight and " SickbeardPrefix = "" [[ "Octonauts" ]] - InputDirectory = "%(VideoProcessingDir)sOctonauts/Input/" + InputDirectory = "%(VideoProcessingDir)sOctonauts/" UnknownDirectory = "%(UnknownInput)sOctonauts/" OutputDirectory = "%(KidsTVDir)sOctonauts/" alias = "The Octonauts", MythTvEpisodePrefix = "The Octonauts and ", SickbeardPrefix = "The" [[ "In the Night Garden" ]] - InputDirectory = "%(VideoProcessingDir)sInTheNightGarden/Input/" + InputDirectory = "%(VideoProcessingDir)sInTheNightGarden/" UnknownDirectory = "%(UnknownInput)sInTheNightGarden/" OutputDirectory = "%(KidsTVDir)sIn The Night Garden/" alias = , MythTvEpisodePrefix = , SickbeardPrefix = "" [[ "Raa Raa! The Noisy Lion" ]] - InputDirectory = "%(VideoProcessingDir)sRaaRaa/Input/" + InputDirectory = "%(VideoProcessingDir)sRaaRaa/" UnknownDirectory = "%(UnknownInput)sRaaRaa/" OutputDirectory = "%(KidsTVDir)sRaa Raa the Noisy Lion/" alias = , MythTvEpisodePrefix = , SickbeardPrefix = "" [[ "Fireman Sam" ]] - InputDirectory = "%(VideoProcessingDir)sFiremanSam/Input/" + InputDirectory = "%(VideoProcessingDir)sFiremanSam/" UnknownDirectory = "%(UnknownInput)sFiremanSam/" OutputDirectory = "%(KidsTVDir)sFireman Sam/" alias = , diff --git a/tests/libfilemanagertest.py b/tests/libfilemanagertest.py index 94e0bd8..0ebc2b8 100644 --- a/tests/libfilemanagertest.py +++ b/tests/libfilemanagertest.py @@ -36,6 +36,7 @@ class libfilemanagertest(unittest.TestCase): result = data.checkproblems() self.assertIn("FILE_EXISTS", result) + minimock.restore() def test_EncodeDataCheckProblemsFile_Exists(self): showname = "test show" @@ -45,6 +46,18 @@ class libfilemanagertest(unittest.TestCase): mock("os.path.exists", returns_iter=[False, True]) result = data.checkproblems() 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): settings = Mock('libsettings.Settings') @@ -55,6 +68,7 @@ class libfilemanagertest(unittest.TestCase): result = filemanager.checkduplicates("/path/to/S03E14 - Test - SD TV.mkv") self.assertTrue(result) + minimock.restore() def test_checkduplicatenomatch(self): settings = Mock('libsettings.Settings') @@ -65,6 +79,7 @@ class libfilemanagertest(unittest.TestCase): result = filemanager.checkduplicates("/path/to/S03E13 - Test - SD TV.mkv") self.assertFalse(result) + minimock.restore() def test_checkduplicatesameextension(self): settings = Mock('libsettings.Settings') @@ -75,6 +90,8 @@ class libfilemanagertest(unittest.TestCase): result = filemanager.checkduplicates("/path/to/S03E14 - Test - SD TV.avi") self.assertFalse(result) + minimock.restore() + def dummywalk(arg):