From be9727155951a176dd262145abfa96a64e3c9e4c Mon Sep 17 00:00:00 2001 From: Shane Frischkorn Date: Fri, 19 Jul 2013 22:36:46 +1000 Subject: [PATCH] added logging --- .gitignore | 3 +++ TVEncoder.py | 43 +++++++++++++++++++++++++++++++++++++++---- libsettings.py | 17 ++++++++++++++++- libtvdatasource.py | 7 +++++++ pep8.sh | 3 +++ pylint.sh | 3 +++ settings.cfg | 4 ++++ 7 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100755 pep8.sh create mode 100755 pylint.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35755d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +.spyderproject + diff --git a/TVEncoder.py b/TVEncoder.py index f2142a5..fcf78ea 100644 --- a/TVEncoder.py +++ b/TVEncoder.py @@ -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 that will write to the file + """ + + 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:]) diff --git a/libsettings.py b/libsettings.py index 3cdedba..0a5c9fb 100644 --- a/libsettings.py +++ b/libsettings.py @@ -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 diff --git a/libtvdatasource.py b/libtvdatasource.py index 87ac3ba..ddffeec 100644 --- a/libtvdatasource.py +++ b/libtvdatasource.py @@ -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" diff --git a/pep8.sh b/pep8.sh new file mode 100755 index 0000000..73bdc68 --- /dev/null +++ b/pep8.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +pep8 TVEncoder.py libfilemanager.py libhandbrake.py libmythtv.py libsettings.py libsickbeard.py libtvdatasource.py libtvshow.py \ No newline at end of file diff --git a/pylint.sh b/pylint.sh new file mode 100755 index 0000000..60da4bf --- /dev/null +++ b/pylint.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +pylint TVEncoder.py libfilemanager.py libhandbrake.py libmythtv.py libsettings.py libsickbeard.py libtvdatasource.py libtvshow.py \ No newline at end of file diff --git a/settings.cfg b/settings.cfg index cf6505e..9ff8c44 100644 --- a/settings.cfg +++ b/settings.cfg @@ -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