Fix for manual runs with data from DB

This commit is contained in:
echel0n 2014-04-26 05:24:32 -07:00
commit 684e1c5545
2 changed files with 18 additions and 15 deletions

View file

@ -9,6 +9,7 @@ import nzbtomedia
from subprocess import Popen from subprocess import Popen
from nzbtomedia import logger, nzbToMediaDB from nzbtomedia import logger, nzbToMediaDB
DOWNLOADINFO = None
USER_SCRIPT_MEDIAEXTENSIONS = None USER_SCRIPT_MEDIAEXTENSIONS = None
USER_SCRIPT = None USER_SCRIPT = None
USER_SCRIPT_PARAM = None USER_SCRIPT_PARAM = None
@ -17,16 +18,15 @@ USER_SCRIPT_CLEAN = None
USER_DELAY = None USER_DELAY = None
USER_SCRIPT_RUNONCE = None USER_SCRIPT_RUNONCE = None
def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent): def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent):
global USER_DELAY, USER_SCRIPT, USER_SCRIPT_CLEAN, USER_SCRIPT_MEDIAEXTENSIONS, \
USER_SCRIPT_PARAM, USER_SCRIPT_RUNONCE, USER_SCRIPT_SUCCESSCODES, DOWNLOADINFO
status = 1 # 1 = failed | 0 = success status = 1 # 1 = failed | 0 = success
root = 0 root = 0
foundFile = 0 foundFile = 0
global USER_DELAY, USER_SCRIPT, USER_SCRIPT_CLEAN, USER_SCRIPT_MEDIAEXTENSIONS, \ if clientAgent != 'manual' and not DOWNLOADINFO:
USER_SCRIPT_PARAM, USER_SCRIPT_RUNONCE, USER_SCRIPT_SUCCESSCODES
if clientAgent != 'manual':
logger.debug('Adding TORRENT download info for directory %s to database' % (inputDirectory)) logger.debug('Adding TORRENT download info for directory %s to database' % (inputDirectory))
myDB = nzbToMediaDB.DBConnection() myDB = nzbToMediaDB.DBConnection()
@ -335,8 +335,8 @@ def main(args):
logger.info("Starting manual run for %s:%s - Folder:%s" % (section, subsection, dirName)) logger.info("Starting manual run for %s:%s - Folder:%s" % (section, subsection, dirName))
logger.info("Checking database for download info for %s ..." % (os.path.basename(dirName))) logger.info("Checking database for download info for %s ..." % (os.path.basename(dirName)))
downloadInfo = nzbtomedia.get_downloadInfo(os.path.basename(dirName), 0) DOWNLOADINFO = nzbtomedia.get_downloadInfo(os.path.basename(dirName), 0)
if downloadInfo: if DOWNLOADINFO:
logger.info( logger.info(
"Found download info for %s, setting variables now ..." % (os.path.basename(dirName))) "Found download info for %s, setting variables now ..." % (os.path.basename(dirName)))
else: else:
@ -346,19 +346,19 @@ def main(args):
) )
try: try:
clientAgent = str(downloadInfo[0]['client_agent']) clientAgent = str(DOWNLOADINFO[0]['client_agent'])
except: except:
clientAgent = 'manual' clientAgent = 'manual'
try: try:
inputHash = str(downloadInfo[0]['input_hash']) inputHash = str(DOWNLOADINFO[0]['input_hash'])
except: except:
inputHash = None inputHash = None
try: try:
inputID = str(downloadInfo[0]['input_id']) inputID = str(DOWNLOADINFO[0]['input_id'])
except: except:
inputID = None inputID = None
if not clientAgent.lower() in (nzbtomedia.TORRENT_CLIENTS,'manual'): if clientAgent.lower() not in (nzbtomedia.TORRENT_CLIENTS or ['manual']):
continue continue
results = processTorrent(dirName, os.path.basename(dirName), subsection, inputHash, inputID, results = processTorrent(dirName, os.path.basename(dirName), subsection, inputHash, inputID,

View file

@ -285,9 +285,12 @@ from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
from nzbtomedia.nzbToMediaUtil import getDirs, extractFiles, cleanDir, update_downloadInfoStatus, get_downloadInfo from nzbtomedia.nzbToMediaUtil import getDirs, extractFiles, cleanDir, update_downloadInfoStatus, get_downloadInfo
from nzbtomedia import logger, nzbToMediaDB from nzbtomedia import logger, nzbToMediaDB
DOWNLOADINFO = None
# post-processing # post-processing
def process(inputDirectory, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None): def process(inputDirectory, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None):
if clientAgent != 'manual': global DOWNLOADINFO
if clientAgent != 'manual' and not DOWNLOADINFO:
logger.debug('Adding NZB download info for directory %s to database' % (inputDirectory)) logger.debug('Adding NZB download info for directory %s to database' % (inputDirectory))
myDB = nzbToMediaDB.DBConnection() myDB = nzbToMediaDB.DBConnection()
@ -477,15 +480,15 @@ def main(args, section=None):
) )
try: try:
clientAgent = str(downloadInfo[0]['client_agent']) clientAgent = str(DOWNLOADINFO[0]['client_agent'])
except: except:
clientAgent = 'manual' clientAgent = 'manual'
try: try:
download_id = str(downloadInfo[0]['input_id']) download_id = str(DOWNLOADINFO[0]['input_id'])
except: except:
download_id = None download_id = None
if not clientAgent.lower() in (nzbtomedia.NZB_CLIENTS, 'manual'): if clientAgent.lower() not in (nzbtomedia.NZB_CLIENTS or ['manual']):
continue continue
results = process(dirName, os.path.basename(dirName), 0, clientAgent=clientAgent, results = process(dirName, os.path.basename(dirName), 0, clientAgent=clientAgent,