use common create_destination

instead of duplicate code in both copylink and extractor
This commit is contained in:
Joel Kåberg 2013-03-01 11:10:10 +01:00
commit 9c34ac2a35
2 changed files with 13 additions and 17 deletions

View file

@ -124,22 +124,23 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
def is_sample(filePath, inputName): def is_sample(filePath, inputName):
# 200 MB in bytes # 200 MB in bytes
# Maybe let the users change this?
SIZE_CUTOFF = minSampleSize * 1024 * 1024 SIZE_CUTOFF = minSampleSize * 1024 * 1024
# Ignore 'sample' in files unless 'sample' in Torrent Name # Ignore 'sample' in files unless 'sample' in Torrent Name
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 copy_link(source, target, useLink, outputDestination): def create_destination(outputDestination)
# Create destination folder
if not os.path.exists(outputDestination): if not os.path.exists(outputDestination):
try: try:
Logger.info("COPYLINK: Creating destination folder: %s", outputDestination) Logger.info("CREATE DESTINATION: Creating destination folder: %s", outputDestination)
os.makedirs(outputDestination) os.makedirs(outputDestination)
except Exception, e: except Exception, e:
Logger.error("COPYLINK: Not possible to create destination folder: %s", e) Logger.error("CREATE DESTINATION: Not possible to create destination folder: %s", e)
return False return False
def copy_link(source, target, useLink, outputDestination):
create_destination(outputDestination)
if useLink: if useLink:
try: try:
Logger.info("COPYLINK: Linking %s to %s", source, target) Logger.info("COPYLINK: Linking %s to %s", source, target)
@ -340,20 +341,20 @@ else:
# Hardlink solution with uTorrent # Hardlink solution with uTorrent
if inputHash and useLink: if inputHash and useLink:
try: try:
Logger.debug("Connecting to uTorrent: %s", uTorrentWEBui) Logger.debug("MAIN: Connecting to uTorrent: %s", uTorrentWEBui)
utorrentClass = UTorrentClient(uTorrentWEBui, uTorrentUSR, uTorrentPWD) utorrentClass = UTorrentClient(uTorrentWEBui, uTorrentUSR, uTorrentPWD)
except: except:
Logger.error("Failed to connect to uTorrent") Logger.error("MAIN: Failed to connect to uTorrent")
Logger.debug("MAIN: Stoping torrent %s in uTorrent while processing", inputName) Logger.debug("MAIN: Stoping torrent %s in uTorrent while processing", videofile)
utorrentClass.stop(inputHash) utorrentClass.stop(inputHash)
time.sleep(5) # Give uTorrent some time to catch up with the change time.sleep(5) # Give uTorrent some time to catch up with the change
# Now we pass off to CouchPotato or Sick-Beard # Now we pass off to CouchPotato or Sick-Beard
if inputCategory == movieCategory: if inputCategory == movieCategory:
Logger.info("MAIN: Calling CouchPotatoServer to post-process: %s", inputName) # can we use logger while logfile open? Logger.info("MAIN: Calling CouchPotatoServer to post-process: %s", videofile) # can we use logger while logfile open?
autoProcessMovie.process(outputDestination, inputName, status) autoProcessMovie.process(outputDestination, inputName, status)
elif inputCategory == tvCategory: elif inputCategory == tvCategory:
Logger.info("MAIN: Calling Sick-Beard to post-process: %s", inputName) # can we use logger while logfile open? Logger.info("MAIN: Calling Sick-Beard to post-process: %s", videofile) # can we use logger while logfile open?
autoProcessTV.processEpisode(outputDestination, inputName, status) autoProcessTV.processEpisode(outputDestination, inputName, status)
# Check if the file still exists in the post-process directory # Check if the file still exists in the post-process directory

View file

@ -100,13 +100,8 @@ def extract(dirpath, file, outputDestination):
return False return False
# Create outputDestination folder # Create outputDestination folder
if not os.path.exists(outputDestination): create_destination(outputDestination)
try:
Logger.debug("EXTRACTOR: Creating destination folder: %s", outputDestination)
os.makedirs(outputDestination)
except Exception, e:
Logger.error("EXTRACTOR: Not possible to create destination folder: %s", e)
return False
Logger.info("Extracting %s to %s", filePath, outputDestination) Logger.info("Extracting %s to %s", filePath, outputDestination)
Logger.debug("Extracting %s %s %s %s", cmd[0], cmd[1], filePath, outputDestination) Logger.debug("Extracting %s %s %s %s", cmd[0], cmd[1], filePath, outputDestination)
pwd = os.getcwd() # Get our Present Working Directory pwd = os.getcwd() # Get our Present Working Directory