merged manders2600 pull request #140

This commit is contained in:
evilhero 2013-01-13 12:10:41 -05:00
parent 05e6cef5ca
commit a4081edb7e
4 changed files with 73 additions and 13 deletions

View File

@ -351,6 +351,14 @@
<div class="row checkbox left clearfix">
<input type="checkbox" name="rename_files" value="1" ${config['rename_files']} /><label>Rename files </label>
</div>
<div class="row checkbox left clearfix">
<input type="checkbox" name="enable_pre_scripts" value="1" ${config['enable_pre_scripts']} /><label>Use Extra Script BEFORE Post-Processing</label>
</div>
<div class="row">
<label>Pre - Script Location</label>
<input type="text" name="pre_scripts" value="${config['pre_scripts']}" size="30">
<small>enter in the absolute path to the script</small>
</div>
<div class="row checkbox left clearfix">
<input type="checkbox" name="enable_extra_scripts" value="1" ${config['enable_extra_scripts']} /><label>Use Extra Script AFTER Post-Processing</label>
</div>
@ -358,8 +366,7 @@
<label>Extra Script Location</label>
<input type="text" name="extra_scripts" value="${config['extra_scripts']}" size="30">
<small>enter in the absolute path to the script</small>
</div>
<div class="row">
</div>
</div>
</fieldset>
</td>

View File

@ -83,6 +83,31 @@ class PostProcessor(object):
# logger.log(message, level)
self.log += message + '\n'
def _run_pre_scripts(self, nzb_name, nzb_folder, seriesmetadata):
"""
Executes any pre scripts defined in the config.
ep_obj: The object to use when calling the pre script
"""
self._log("initiating pre script detection.", logger.DEBUG)
self._log("mylar.PRE_SCRIPTS : " + mylar.PRE_SCRIPTS, logger.DEBUG)
# for currentScriptName in mylar.PRE_SCRIPTS:
currentScriptName = mylar.PRE_SCRIPTS
self._log("pre script detected...enabling: " + str(currentScriptName), logger.DEBUG)
# generate a safe command line string to execute the script and provide all the parameters
script_cmd = shlex.split(currentScriptName) + [str(nzb_name), str(nzb_folder), str(seriesmetadata)]
self._log("cmd to be executed: " + str(script_cmd), logger.DEBUG)
# use subprocess to run the command and capture output
self._log(u"Executing command "+str(script_cmd))
self._log(u"Absolute path to script: "+script_cmd[0], logger.DEBUG)
try:
p = subprocess.Popen(script_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=mylar.PROG_DIR)
out, err = p.communicate() #@UnusedVariable
self._log(u"Script result: "+str(out), logger.DEBUG)
except OSError, e:
self._log(u"Unable to run pre_script: " + str(script_cmd))
def _run_extra_scripts(self, nzb_name, nzb_folder, filen, folderp, seriesmetadata):
"""
Executes any extra scripts defined in the config.
@ -235,6 +260,28 @@ class PostProcessor(object):
self._log("Year: " + seriesyear, logger.DEBUG)
comlocation = comicnzb['ComicLocation']
self._log("Comic Location: " + comlocation, logger.DEBUG)
#Run Pre-script
if mylar.ENABLE_PRE_SCRIPTS:
nzbn = self.nzb_name #original nzb name
nzbf = self.nzb_folder #original nzb folder
#name, comicyear, comicid , issueid, issueyear, issue, publisher
#create the dic and send it.
seriesmeta = []
seriesmetadata = {}
seriesmeta.append({
'name': series,
'comicyear': seriesyear,
'comicid': comicid,
'issueid': issueid,
'issueyear': issueyear,
'issue': issuenum,
'publisher': publisher
})
seriesmetadata['seriesmeta'] = seriesmeta
self._run_pre_scripts(nzbn, nzbf, seriesmetadata )
#rename file and move to new path
#nfilename = series + " " + issueno + " (" + seriesyear + ")"
file_values = {'$Series': series,

View File

@ -150,6 +150,9 @@ QUAL_QUALITY = None
ENABLE_EXTRA_SCRIPTS = 1
EXTRA_SCRIPTS = None
ENABLE_PRE_SCRIPTS = 1
PRE_SCRIPTS = None
def CheckSection(sec):
""" Check if INI section exists, if not create it """
try:
@ -208,8 +211,8 @@ def initialize():
NZBSU, NZBSU_APIKEY, DOGNZB, DOGNZB_APIKEY, NZBX,\
NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS,\
RAW, RAW_PROVIDER, RAW_USERNAME, RAW_PASSWORD, RAW_GROUPS, EXPERIMENTAL, \
PREFERRED_QUALITY, MOVE_FILES, RENAME_FILES, CORRECT_METADATA, FOLDER_FORMAT, FILE_FORMAT, REPLACE_CHAR, REPLACE_SPACES, USE_MINSIZE, MINSIZE, USE_MAXSIZE, MAXSIZE, \
COMIC_LOCATION, QUAL_ALTVERS, QUAL_SCANNER, QUAL_TYPE, QUAL_QUALITY, ENABLE_EXTRA_SCRIPTS, EXTRA_SCRIPTS
PREFERRED_QUALITY, MOVE_FILES, RENAME_FILES, USE_MINSIZE, MINSIZE, USE_MAXSIZE, MAXSIZE, CORRECT_METADATA, FOLDER_FORMAT, FILE_FORMAT, REPLACE_CHAR, REPLACE_SPACES, \
COMIC_LOCATION, QUAL_ALTVERS, QUAL_SCANNER, QUAL_TYPE, QUAL_QUALITY, ENABLE_EXTRA_SCRIPTS, EXTRA_SCRIPTS, ENABLE_PRE_SCRIPTS, PRE_SCRIPTS
if __INITIALIZED__:
return False
@ -275,6 +278,9 @@ def initialize():
ENABLE_EXTRA_SCRIPTS = bool(check_setting_int(CFG, 'General', 'enable_extra_scripts', 0))
EXTRA_SCRIPTS = check_setting_str(CFG, 'General', 'extra_scripts', '')
ENABLE_PRE_SCRIPTS = bool(check_setting_int(CFG, 'General', 'enable_pre_scripts', 0))
PRE_SCRIPTS = check_setting_str(CFG, 'General', 'pre_scripts', '')
SAB_HOST = check_setting_str(CFG, 'SABnzbd', 'sab_host', '')
SAB_USERNAME = check_setting_str(CFG, 'SABnzbd', 'sab_username', '')
SAB_PASSWORD = check_setting_str(CFG, 'SABnzbd', 'sab_password', '')
@ -508,6 +514,8 @@ def config_write():
new_config['General']['enable_extra_scripts'] = int(ENABLE_EXTRA_SCRIPTS)
new_config['General']['extra_scripts'] = EXTRA_SCRIPTS
new_config['General']['enable_pre_scripts'] = int(ENABLE_PRE_SCRIPTS)
new_config['General']['pre_scripts'] = PRE_SCRIPTS
new_config['SABnzbd'] = {}
new_config['SABnzbd']['sab_host'] = SAB_HOST

View File

@ -585,7 +585,6 @@ class WebInterface(object):
"zero_level_n" : mylar.ZERO_LEVEL_N,
"enable_extra_scripts" : helpers.checked(mylar.ENABLE_EXTRA_SCRIPTS),
"extra_scripts" : mylar.EXTRA_SCRIPTS,
"log_dir" : mylar.LOG_DIR,
"branch" : version.MYLAR_VERSION,
"br_type" : mylar.INSTALL_TYPE,
"br_version" : mylar.versioncheck.getVersion(),
@ -593,8 +592,11 @@ class WebInterface(object):
"data_dir" : mylar.DATA_DIR,
"prog_dir" : mylar.PROG_DIR,
"cache_dir" : mylar.CACHE_DIR,
"config_file" : mylar.CONFIG_FILE
"config_file" : mylar.CONFIG_FILE,
# "branch_history" : br_hist
"enable_pre_scripts" : helpers.checked(mylar.ENABLE_PRE_SCRIPTS),
"pre_scripts" : mylar.PRE_SCRIPTS,
"log_dir" : mylar.LOG_DIR
}
return serve_template(templatename="config.html", title="Settings", config=config)
config.exposed = True
@ -617,12 +619,6 @@ class WebInterface(object):
if fuzzy_year == '0': fuzzy_string = "None"
elif fuzzy_year == '1': fuzzy_string = "Remove Year"
elif fuzzy_year == '2': fuzzy_string = "Fuzzy Year"
# "pref_qual_0" : helpers.radio(mylar.PREFERRED_QUALITY, 0),
# "pref_qual_1" : helpers.radio(mylar.PREFERRED_QUALITY, 1),
# "pref_qual_3" : helpers.radio(mylar.PREFERRED_QUALITY, 3),
# "pref_qual_2" : helpers.radio(mylar.PREFERRED_QUALITY, 2),
#--- this is for multipe search terms............
#--- works, just need to redo search.py to accomodate multiple search terms
@ -680,7 +676,7 @@ class WebInterface(object):
sab_host=None, sab_username=None, sab_apikey=None, sab_password=None, sab_category=None, sab_priority=None, log_dir=None, blackhole=0, blackhole_dir=None,
usenet_retention=None, nzbsu=0, nzbsu_apikey=None, dognzb=0, dognzb_apikey=None, nzbx=0, newznab=0, newznab_host=None, newznab_apikey=None, newznab_enabled=0,
raw=0, raw_provider=None, raw_username=None, raw_password=None, raw_groups=None, experimental=0,
preferred_quality=0, move_files=0, rename_files=0, folder_format=None, file_format=None, enable_extra_scripts=0, extra_scripts=None,
preferred_quality=0, move_files=0, rename_files=0, folder_format=None, file_format=None, enable_extra_scripts=0, extra_scripts=None, enable_pre_scripts=0, pre_scripts=None,
destination_dir=None, replace_spaces=0, replace_char=None, use_minsize=0, minsize=None, use_maxsize=0, maxsize=None, autowant_all=0, autowant_upcoming=0, comic_cover_local=0, zero_level=0, zero_level_n=None, interface=None, **kwargs):
mylar.HTTP_HOST = http_host
mylar.HTTP_PORT = http_port
@ -735,6 +731,8 @@ class WebInterface(object):
mylar.INTERFACE = interface
mylar.ENABLE_EXTRA_SCRIPTS = enable_extra_scripts
mylar.EXTRA_SCRIPTS = extra_scripts
mylar.ENABLE_PRE_SCRIPTS = enable_pre_scripts
mylar.PRE_SCRIPTS = pre_scripts
mylar.LOG_DIR = log_dir
# Handle the variable config options. Note - keys with False values aren't getting passed