Fixed create_destination

This commit is contained in:
Berkona 2013-03-01 17:29:38 -05:00
commit 3e952ba035
3 changed files with 24 additions and 20 deletions

View file

@ -129,16 +129,6 @@ def is_sample(filePath, inputName, minSampleSize):
return ('sample' in filePath.lower()) and (not 'sample' in inputName) and (os.path.getsize(filePath) < SIZE_CUTOFF) return ('sample' in filePath.lower()) and (not 'sample' in inputName) and (os.path.getsize(filePath) < SIZE_CUTOFF)
def create_destination(outputDestination):
if not os.path.exists(outputDestination):
try:
Logger.info("CREATE DESTINATION: Creating destination folder: %s", outputDestination)
os.makedirs(outputDestination)
except Exception, e:
Logger.error("CREATE DESTINATION: Not possible to create destination folder: %s. Exiting", e)
sys.exit(-1)
def copy_link(source, target, useLink, outputDestination): def copy_link(source, target, useLink, outputDestination):
create_destination(outputDestination) create_destination(outputDestination)
if useLink: if useLink:
@ -332,7 +322,7 @@ if status == 0: #### Maybe we should move this to a more appropriate place?
Logger.info("MAIN: Successful run") Logger.info("MAIN: Successful run")
Logger.debug("MAIN: Calling autoProcess script for successful download.") Logger.debug("MAIN: Calling autoProcess script for successful download.")
elif failed_extract == 1 and failed_link == 0: # failed to extract files only. elif failed_extract == 1 and failed_link == 0: # failed to extract files only.
Logger.info("MAIN: Failed to extract a compressed archive") Logger.info("MAIN: Failed to extract a compressed archive")
Logger.debug("MAIN: Assume this to be password protected file.") Logger.debug("MAIN: Assume this to be password protected file.")
Logger.debug("MAIN: Calling autoProcess script for failed download.") Logger.debug("MAIN: Calling autoProcess script for failed download.")
else: else:

View file

@ -2,6 +2,7 @@ import os
import sys import sys
import logging import logging
from subprocess import call from subprocess import call
from nzbToMediaUtil import create_destination
Logger = logging.getLogger() Logger = logging.getLogger()
@ -99,7 +100,10 @@ def extract(dirpath, file, outputDestination):
else: else:
Logger.debug("EXTRACTOR: Unknown file type: %s", ext[1]) Logger.debug("EXTRACTOR: Unknown file type: %s", ext[1])
return False return False
# Create outputDestination folder
create_destination(outputDestination)
Logger.info("Extracting %s to %s", filePath, outputDestination) Logger.info("Extracting %s to %s", filePath, outputDestination)
Logger.debug("Extracting %s %s %s", cmd, filePath, outputDestination) Logger.debug("Extracting %s %s %s", cmd, filePath, outputDestination)
pwd = os.getcwd() # Get our Present Working Directory pwd = os.getcwd() # Get our Present Working Directory
@ -112,6 +116,6 @@ def extract(dirpath, file, outputDestination):
else: else:
Logger.error("EXTRACTOR: Extraction failed for %s. 7zip result was %s", filePath, res) Logger.error("EXTRACTOR: Extraction failed for %s. 7zip result was %s", filePath, res)
except: except:
Logger.error("EXTRACTOR: Extraction failed for %s. Could not call command %s", filePath, cmd) Logger.error("EXTRACTOR: Extraction failed for %s. Could not call command %s", filePath, cmd)
os.chdir(pwd) # Go back to our Original Working Directory os.chdir(pwd) # Go back to our Original Working Directory
return True return True

View file

@ -5,12 +5,22 @@ import sys
def nzbtomedia_configure_logging(dirname): def nzbtomedia_configure_logging(dirname):
logFile = os.path.join(dirname, "postprocess.log") logFile = os.path.join(dirname, "postprocess.log")
logging.config.fileConfig(os.path.join(dirname, "autoProcessMedia.cfg")) logging.config.fileConfig(os.path.join(dirname, "autoProcessMedia.cfg"))
fileHandler = logging.FileHandler(logFile, encoding='utf-8', delay=True) fileHandler = logging.FileHandler(logFile, encoding='utf-8', delay=True)
fileHandler.formatter = logging.Formatter('%(asctime)s|%(levelname)-7.7s %(message)s', '%H:%M:%S') fileHandler.formatter = logging.Formatter('%(asctime)s|%(levelname)-7.7s %(message)s', '%H:%M:%S')
fileHandler.level = logging.DEBUG fileHandler.level = logging.DEBUG
logging.getLogger().addHandler(fileHandler) logging.getLogger().addHandler(fileHandler)
def create_destination(outputDestination):
if not os.path.exists(outputDestination):
try:
Logger.info("CREATE DESTINATION: Creating destination folder: %s", outputDestination)
os.makedirs(outputDestination)
except Exception, e:
Logger.error("CREATE DESTINATION: Not possible to create destination folder: %s. Exiting", e)
sys.exit(-1)
def parse_other(args): def parse_other(args):
@ -29,7 +39,7 @@ def parse_utorrent(args):
inputHash = args[4] inputHash = args[4]
except: except:
inputHash = '' inputHash = ''
return inputDirectory, inputName, inputCategory, inputHash return inputDirectory, inputName, inputCategory, inputHash