added logging

This commit is contained in:
2013-07-19 22:36:46 +10:00
parent c06d43b3e7
commit be97271559
7 changed files with 75 additions and 5 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.pyc
.spyderproject

View File

@@ -13,6 +13,7 @@ import libhandbrake
from libtvdatasource import TVData
from collections import namedtuple
from termcolor import colored
import logging
def showhelp():
@@ -103,6 +104,12 @@ def main(argv):
settings = Settings("settings.cfg")
filemanager = FileManager(settings)
logging.basicConfig(level=logging.DEBUG)
generallogger = createlogger("general", settings.generallogfile,
logging.debug)
actionlogger = createlogger("action", settings.actionlogfile,
logging.info)
if inputoptions.readonly:
if inputoptions.doencode:
#Generate the list of files that would be encoded
@@ -117,24 +124,52 @@ def main(argv):
if inputoptions.doencode:
#Encode the files and move them to their final destination
showdata = filemanager.getencodingfiles(inputoptions.readonly)
generallogger.info("There are {0} files to process."
.format(len(showdata)))
for show in showdata:
generallogger.info("========================================")
generallogger.info("Processing {0} of {1}, {2}".format(
showdata.index(show) + 1, len(showdata), str(show)))
if filemanager.checkfileexists(show.outputfile):
print "File {0} already exists. Cannot process." \
.format(show.outputfile)
message = "File {0} already exists. Cannot process." \
.format(show.outputfile)
generallogger.warning(message)
actionlogger.warning(message)
else:
result = libhandbrake.encode(settings.handbrakecommand(),
show.inputfile,
show.outputfile)
# TODO do something with the result
generallogger.info("Encode finished with result: {0}"
.format(result))
filemanager.performpostencodefileoperations(
show.inputfile, show.outputfile)
generallogger.info("Processing finished.")
generallogger.info("==========================="
"=============\n\n")
else:
# Process files for encoding
shows = filemanager.getfilestoprepare(inputoptions.numfiles)
print "Preparing {0} files".format(len(shows))
tvdata = TVData(settings)
tvdata.prepareepisodes(shows)
def createlogger(name, filename, level):
"""
Create a logger named <name> that will write to the file <filename>
"""
logger = logging.getLogger(name)
handler = logging.FileHandler(filename)
formatter = logging.Formatter('%(asctime)s %(message)s')
handler.setFormatter(formatter)
handler.setLevel(level)
logger.addHandler(handler)
return logger
if __name__ == "__main__":
main(sys.argv[1:])

View File

@@ -48,11 +48,26 @@ class Settings:
return self.__config["HandbrakeCommand"]
def illegalcharacters(self):
"""Get a list of illegal characters for filenames
"""
Get a list of illegal characters for filenames
"""
return self.__config["IllegalCharacters"]
def generallogfile(self):
"""
Get the filename to save general log messages to
"""
return self.__config["Logging"]["General"]
def actionlogfile(self):
"""
Get the filename to save the action log messages to
"""
return self.__config["Logging"]["Action"]
def mythtvaddress(self):
"""
Get the MythTV/address setting

View File

@@ -134,4 +134,11 @@ class TVData:
"""
for showdata in showsdata:
print "========================================"
print "Copying {0} to {1}".format(showdata.inputfile,
showdata.outputfile)
self.processepisode(showdata.inputfile, showdata.outputfile)
print "Finished copy"
print "========================================\n\n"

3
pep8.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
pep8 TVEncoder.py libfilemanager.py libhandbrake.py libmythtv.py libsettings.py libsickbeard.py libtvdatasource.py libtvshow.py

3
pylint.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
pylint TVEncoder.py libfilemanager.py libhandbrake.py libmythtv.py libsettings.py libsickbeard.py libtvdatasource.py libtvshow.py

View File

@@ -2,6 +2,10 @@ TVRecordings = "/Volumes/TV Recordings/"
HandbrakeCommand = "HandBrakeCLI", "--verbose", "-i", "SUBSTITUTE WITH INPUT FILE", "-o", "SUBSTITUDE WITH OUTPUT FILE", "-f", "mkv", "-e", "x264", "-x264-preset", "slower", "-x264-tune", "animation", "-q", "20", "--loose-anamorphic", "--decomb", "--detelecine", '--denoise="2:1:2:3"', "--deblock"
IllegalCharacters = "?"
[ "Logging" ]
General = "logs/encoding.log"
Action = "logs/needsaction.log"
[ "MythTV" ]
address = 192.168.0.2
user = script