refactor handling of the python source command. document it and more limits.

This commit is contained in:
Axel Kohlmeyer
2022-11-10 16:03:06 -05:00
parent dd8c1df9c2
commit 34a5093229
3 changed files with 141 additions and 117 deletions

View File

@ -130,19 +130,17 @@ void PythonImpl::command(int narg, char **arg)
return;
}
// if source is only keyword, execute the python code
// if source is only keyword, execute the python code in file
if (narg == 3 && strcmp(arg[1], "source") == 0) {
int err;
if ((narg > 1) && (strcmp(arg[0], "source") == 0)) {
int err = -1;
FILE *fp = fopen(arg[2], "r");
if (fp == nullptr)
if ((narg > 2) && (strcmp(arg[1], "inline") == 0)) {
err = execute_string(arg[2]);
else
err = execute_file(arg[2]);
if (fp) fclose(fp);
if (err) error->all(FLERR, "Could not process Python source command");
} else {
if (platform::file_is_readable(arg[1])) err = execute_file(arg[1]);
}
if (err) error->warning(FLERR, "Could not process Python source command. Error code: {}", err);
return;
}