Added checks for potential problems when listing files

This commit is contained in:
2013-07-15 22:27:06 +10:00
parent df4aefeca1
commit 35ca21e4e4
4 changed files with 58 additions and 15 deletions

View File

@@ -28,25 +28,39 @@ def showhelp():
print 'TVEncoder.py -e -l - list the files that would be encoded'
def print_shows(shows, filemanager):
def print_shows(shows):
"""
Prints he details of the shows.
"""
okshows = []
noepisodes = []
existingfiles = []
existing = []
for show in shows:
showstr = str(show)
for showdata in shows:
if filemanager.checkfileexists(showdata.outputfile):
existing.append(showdata)
else:
print showdata
errors = show.checkproblems()
if not errors:
okshows.append(showstr)
elif "NO_EPISODE" in errors:
noepisodes.append(showstr)
elif "FILE_EXISTS" in errors:
existingfiles.append(showstr)
if len(existing) > 0:
print colored("The following shows have existing output files that "
"need to be fixed before proceeding:\n", 'red')
for show in okshows:
print show
for showdata in existing:
print colored(showdata, 'red')
if noepisodes:
print colored("\nDetails of the episode could not be determined for "
"the following shows:", 'red')
for show in noepisodes:
print colored(show, 'red')
if existingfiles:
print colored("\nThe following shows have a pre-existing "
"output file:", 'red')
for show in existingfiles:
print colored(show, 'red')
def processarguments(options):
@@ -93,12 +107,12 @@ def main(argv):
if inputoptions.doencode:
#Generate the list of files that would be encoded
showdata = filemanager.getencodingfiles(inputoptions.readonly)
print_shows(showdata, filemanager)
print_shows(showdata)
else:
# Generate the list of files to process
shows = filemanager.getfilestoprepare(inputoptions.numfiles)
print "num results: {0}".format(len(shows))
print_shows(shows, filemanager)
print_shows(shows)
else:
if inputoptions.doencode:
#Encode the files and move them to their final destination

View File

@@ -28,6 +28,18 @@ class EncodeData:
return "Show: {0}\nInput: {1}\nOutput: " \
"{2}\n".format(self.show, self.inputfile, self.outputfile)
def checkproblems(self):
"""
Check the EncodeData object for any potential problems.
"""
errors = []
if os.path.exists(self.outputfile):
errors.append("FILE_EXISTS")
return errors
class FileManager:
"""

View File

@@ -5,6 +5,9 @@ Created on Sat Jul 6 20:26:22 2013
@author: shanef
"""
import os
#from libfilemanager import FileManager
class TVShow(object):
"""
@@ -24,3 +27,17 @@ class TVShow(object):
def __str__(self):
return "Input: {0} -> Output: {1}".format(self.inputfile,
self.outputfile)
def checkproblems(self):
"""
Check the TVShow object for any potential problems.
"""
errors = []
if self.episode == "E00" or self.season == "S00" or not self.subtitle:
errors.append("NO_EPISODE")
if os.path.exists(self.outputfile):
errors.append("FILE_EXISTS")
return errors

View File

@@ -19,7 +19,7 @@ class libfilemanagertest(unittest.TestCase):
inputname = "test input"
outputname = "test output"
data = EncodeData(showname, inputname, outputname)
result = data.__str__()
result = str(data)
expected = "Show: {0}\nInput: {1}\nOutput: " \
"{2}\n".format(showname, inputname, outputname)
self.assertEqual(result, expected)