Merge pull request #299 from echel0n/dev

Bugfixes for auto fork feature
This commit is contained in:
Clinton Hall 2014-03-31 20:40:22 +10:30
commit 4e4bc03234
4 changed files with 35 additions and 53 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ autoProcessMedia.cfg
*.pyo
postprocess.log
/.idea/

View file

@ -1,18 +1,13 @@
import sys
import urllib
import os
import ConfigParser
import logging
import shutil
import time
import socket
import copy
import Transcoder
from nzbToMediaEnv import *
from nzbToMediaUtil import *
from nzbToMediaSceneExceptions import process_all_exceptions
from autoSickBeardFork import autoFork
from autoProcess.autoSickBeardFork import autoFork
Logger = logging.getLogger()
@ -69,22 +64,18 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
ssl = int(config.get(section, "ssl"))
except (ConfigParser.NoOptionError, ValueError):
ssl = 0
try:
web_root = config.get(section, "web_root")
except ConfigParser.NoOptionError:
web_root = ""
try:
watch_dir = config.get(section, "watch_dir")
except ConfigParser.NoOptionError:
watch_dir = ""
try:
transcode = int(config.get("Transcoder", "transcode"))
except (ConfigParser.NoOptionError, ValueError):
transcode = 0
try:
delete_failed = int(config.get(section, "delete_failed"))
except (ConfigParser.NoOptionError, ValueError):
@ -155,30 +146,26 @@ def processEpisode(dirName, nzbName=None, failed=False, clientAgent=None, inputC
if watch_dir != "" and (not host in ['localhost', '127.0.0.1'] or nzbName == "Manual Run"):
dirName = watch_dir
# don't have sickbeard display any output
# configure SB params to pass
params['quiet'] = 1
if nzbName is not None:
params['nzbName'] = nzbName
for param in copy.copy(params):
if param is "failed":
params[param] = failed
if param is "dirName":
if param is "dirName" or param is "dir":
params[param] = dirName
if param is "dir":
params[param] = dirName
if param is "process":
params["process"] = None
if param is "process_method":
if process_method:
params[param] = process_method
else:
del params[param]
if nzbName != None:
params['nzbName'] = nzbName
# delete any unused params so we don't pass them to SB by mistake
[params.pop(k) for k,v in params.iteritems() if v is None]
if status == 0:
Logger.info("The download succeeded. Sending process request to SickBeard's %s branch", fork)

View file

@ -49,11 +49,10 @@ def autoFork(fork=None):
web_root = ""
try:
fork = config.get(section, "fork")
except ConfigParser.NoOptionError:
fork = forks.items()[forks.keys().index(config.get(section, "fork"))]
except:
fork = "auto"
if fork in "auto":
myOpener = AuthURLOpener(username, password)
if ssl:
@ -61,26 +60,24 @@ def autoFork(fork=None):
else:
protocol = "http://"
detected = False
if fork is "auto":
Logger.info("Attempting to auto-detect SickBeard fork")
for f in forks.iteritems():
url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(f[1]['params'])
for fork in sorted(forks.iteritems()):
url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(fork[1])
# attempting to auto-detect fork
urlObj = myOpener.openit(url)
if urlObj.getcode() == 200:
Logger.info("SickBeard fork auto-detection successful. Fork set to %s", f[1]['name'])
return f[1]['name'], f[1]['params']
detected = True
break
# failed to auto-detect fork
if detected:
Logger.info("SickBeard fork auto-detection successful ...")
else:
Logger.info("SickBeard fork auto-detection failed")
fork = forks.items()[forks.keys().index(fork_default)]
else: #if not fork in "auto"
try:
fork = fork if fork in SICKBEARD_FAILED or fork in SICKBEARD_TORRENT else fork_default
fork = [f for f in forks.iteritems() if f[1]['name'] == fork][0]
except:
fork = [f for f in forks.iteritems() if f[1]['name'] == fork_default][0]
Logger.info("SickBeard fork set to %s", fork[1]['name'])
return fork[1]['name'], fork[1]['params']
Logger.info("SickBeard fork set to %s", fork[0])
return fork[0], fork[1]

View file

@ -10,18 +10,15 @@ SABNZB_0717_NO_OF_ARGUMENTS = 9
# Constants pertaining to SickBeard Branches:
fork_default = "default"
fork_default_new = "default-new"
fork_failed = "failed"
fork_failed_new = "failed-new"
fork_failed_torrent = "failed-torrent"
forks = {} # these need to be in order of most unique params first.
forks[1] = {'name': fork_failed_torrent, 'params': {"dir": None, "failed": None, "process_method": None}}
forks[2] = {'name': fork_failed, 'params': {"dirName": None, "failed": None}}
forks[3] = {'name': fork_failed_new, 'params': {"dir": None, "failed": None}}
forks[4] = {'name': fork_default_new, 'params': {"dir": None, "process": None}}
forks[5] = {'name': fork_default, 'params': {"dir": None}}
forks = {}
SICKBEARD_FAILED = [fork_failed, fork_failed_torrent, fork_failed_new]
forks[fork_default] = {"dir": None, "method": None}
forks[fork_failed] = {"dirName": None, "failed": None}
forks[fork_failed_torrent] = {"dir": None, "failed": None, "process_method": None}
SICKBEARD_FAILED = [fork_failed, fork_failed_torrent]
SICKBEARD_TORRENT = [fork_failed_torrent]