Fix batchprocessor IOError. Resolve #1814.

This commit is contained in:
Griatch 2019-04-07 14:13:49 +02:00
parent e3a96426bc
commit aaea53f46d
2 changed files with 26 additions and 10 deletions

View file

@ -260,9 +260,13 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS):
caller.msg(_UTF8_ERROR % (python_path, err)) caller.msg(_UTF8_ERROR % (python_path, err))
return return
except IOError as err: except IOError as err:
string = "'%s' not found.\nYou have to supply the python path\n" \ if err:
"using one of the defined batch-file directories\n (%s)." err = "{}\n".format(str(err))
caller.msg(string % (python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS))) else:
err = ""
string = "%s'%s' could not load. You have to supply python paths " \
"from one of the defined batch-file directories\n (%s)."
caller.msg(string % (err, python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS)))
return return
if not commands: if not commands:
caller.msg("File %s seems empty of valid commands." % python_path) caller.msg("File %s seems empty of valid commands." % python_path)
@ -288,7 +292,8 @@ class CmdBatchCommands(_COMMAND_DEFAULT_CLASS):
caller.msg("\nBatch-command processor - Interactive mode for %s ..." % python_path) caller.msg("\nBatch-command processor - Interactive mode for %s ..." % python_path)
show_curr(caller) show_curr(caller)
else: else:
caller.msg("Running Batch-command processor - Automatic mode for %s (this might take some time) ..." caller.msg("Running Batch-command processor - Automatic mode "
"for %s (this might take some time) ..."
% python_path) % python_path)
procpool = False procpool = False
@ -370,10 +375,14 @@ class CmdBatchCode(_COMMAND_DEFAULT_CLASS):
except UnicodeDecodeError as err: except UnicodeDecodeError as err:
caller.msg(_UTF8_ERROR % (python_path, err)) caller.msg(_UTF8_ERROR % (python_path, err))
return return
except IOError: except IOError as err:
string = "'%s' not found.\nYou have to supply the python path\n" \ if err:
err = "{}\n".format(str(err))
else:
err = ""
string = "%s'%s' could not load. You have to supply python paths " \
"from one of the defined batch-file directories\n (%s)." "from one of the defined batch-file directories\n (%s)."
caller.msg(string % (python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS))) caller.msg(string % (err, python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS)))
return return
if not codes: if not codes:
caller.msg("File %s seems empty of functional code." % python_path) caller.msg("File %s seems empty of functional code." % python_path)

View file

@ -215,7 +215,7 @@ def read_batchfile(pythonpath, file_ending='.py'):
# find all possible absolute paths # find all possible absolute paths
abspaths = utils.pypath_to_realpath(pythonpath, file_ending, settings.BASE_BATCHPROCESS_PATHS) abspaths = utils.pypath_to_realpath(pythonpath, file_ending, settings.BASE_BATCHPROCESS_PATHS)
if not abspaths: if not abspaths:
raise IOError raise IOError("Absolute batchcmd paths could not be found.")
text = None text = None
decoderr = [] decoderr = []
for abspath in abspaths: for abspath in abspaths:
@ -273,7 +273,11 @@ class BatchCommandProcessor(object):
def replace_insert(match): def replace_insert(match):
"""Map replace entries""" """Map replace entries"""
return "\n#\n".join(self.parse_file(match.group(1))) try:
path = match.group(1)
return "\n#\n".join(self.parse_file(path))
except IOError as err:
raise IOError("#INSERT {} failed.".format(path))
text = _RE_INSERT.sub(replace_insert, text) text = _RE_INSERT.sub(replace_insert, text)
commands = _RE_CMD_SPLIT.split(text) commands = _RE_CMD_SPLIT.split(text)
@ -339,7 +343,10 @@ class BatchCodeProcessor(object):
def replace_insert(match): def replace_insert(match):
"""Run parse_file on the import before sub:ing it into this file""" """Run parse_file on the import before sub:ing it into this file"""
path = match.group(1) path = match.group(1)
return "# batchcode insert (%s):" % path + "\n".join(self.parse_file(path)) try:
return "# batchcode insert (%s):" % path + "\n".join(self.parse_file(path))
except IOError as err:
raise IOError("#INSERT {} failed.".format(path))
# process and then insert code from all #INSERTS # process and then insert code from all #INSERTS
text = _RE_INSERT.sub(replace_insert, text) text = _RE_INSERT.sub(replace_insert, text)