mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
some PyStatus
This commit is contained in:
parent
2562e0b8c9
commit
96f85d38bc
1 changed files with 31 additions and 6 deletions
|
@ -440,6 +440,7 @@ static int CmdScriptRun(const char *Cmd) {
|
||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
#else
|
#else
|
||||||
PyConfig py_conf;
|
PyConfig py_conf;
|
||||||
|
PyStatus status;
|
||||||
// We need to use Python mode instead of isolated to avoid breaking stuff.
|
// We need to use Python mode instead of isolated to avoid breaking stuff.
|
||||||
PyConfig_InitPythonConfig(&py_conf);
|
PyConfig_InitPythonConfig(&py_conf);
|
||||||
// Let's still make things bit safer by being as close as possible to isolated mode.
|
// Let's still make things bit safer by being as close as possible to isolated mode.
|
||||||
|
@ -465,8 +466,10 @@ static int CmdScriptRun(const char *Cmd) {
|
||||||
PySys_SetArgv(argc + 1, py_args);
|
PySys_SetArgv(argc + 1, py_args);
|
||||||
#else
|
#else
|
||||||
// The following line will implicitly pre-initialize Python
|
// The following line will implicitly pre-initialize Python
|
||||||
PyConfig_SetBytesArgv(&py_conf, argc + 1, argv);
|
status = PyConfig_SetBytesArgv(&py_conf, argc + 1, argv);
|
||||||
|
if (PyStatus_Exception(status)) {
|
||||||
|
goto pyexception;
|
||||||
|
}
|
||||||
// We disallowed in py_conf environment variables interfering with python interpreter's behavior.
|
// We disallowed in py_conf environment variables interfering with python interpreter's behavior.
|
||||||
// Let's manually enable the ones we truly need.
|
// Let's manually enable the ones we truly need.
|
||||||
const char *virtual_env = getenv("VIRTUAL_ENV");
|
const char *virtual_env = getenv("VIRTUAL_ENV");
|
||||||
|
@ -474,15 +477,27 @@ static int CmdScriptRun(const char *Cmd) {
|
||||||
size_t length = strlen(virtual_env) + strlen("/bin/python3") + 1;
|
size_t length = strlen(virtual_env) + strlen("/bin/python3") + 1;
|
||||||
char python_executable_path[length];
|
char python_executable_path[length];
|
||||||
snprintf(python_executable_path, length, "%s/bin/python3", virtual_env);
|
snprintf(python_executable_path, length, "%s/bin/python3", virtual_env);
|
||||||
PyConfig_SetBytesString(&py_conf, &py_conf.executable, python_executable_path);
|
status = PyConfig_SetBytesString(&py_conf, &py_conf.executable, python_executable_path);
|
||||||
|
if (PyStatus_Exception(status)) {
|
||||||
|
goto pyexception;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// This is required by Proxspace to work with an isolated Python configuration
|
// This is required by Proxspace to work with an isolated Python configuration
|
||||||
PyConfig_SetBytesString(&py_conf, &py_conf.home, getenv("PYTHONHOME"));
|
status = PyConfig_SetBytesString(&py_conf, &py_conf.home, getenv("PYTHONHOME"));
|
||||||
|
if (PyStatus_Exception(status)) {
|
||||||
|
goto pyexception;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// This is required for allowing `import pm3` in python scripts
|
// This is required for allowing `import pm3` in python scripts
|
||||||
PyConfig_SetBytesString(&py_conf, &py_conf.pythonpath_env, getenv("PYTHONPATH"));
|
status = PyConfig_SetBytesString(&py_conf, &py_conf.pythonpath_env, getenv("PYTHONPATH"));
|
||||||
|
if (PyStatus_Exception(status)) {
|
||||||
|
goto pyexception;
|
||||||
|
}
|
||||||
|
|
||||||
Py_InitializeFromConfig(&py_conf);
|
status = Py_InitializeFromConfig(&py_conf);
|
||||||
|
if (PyStatus_Exception(status)) {
|
||||||
|
goto pyexception;
|
||||||
|
}
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
PyConfig_Clear(&py_conf);
|
PyConfig_Clear(&py_conf);
|
||||||
|
@ -516,6 +531,16 @@ static int CmdScriptRun(const char *Cmd) {
|
||||||
PrintAndLogEx(SUCCESS, "\nfinished " _YELLOW_("%s"), filename);
|
PrintAndLogEx(SUCCESS, "\nfinished " _YELLOW_("%s"), filename);
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pyexception:
|
||||||
|
PyConfig_Clear(&py_conf);
|
||||||
|
if (PyStatus_IsExit(status)) {
|
||||||
|
PrintAndLogEx(WARNING, "\nPython initialization failed with exitcode=%i", status.exitcode);
|
||||||
|
}
|
||||||
|
if (PyStatus_IsError(status)) {
|
||||||
|
PrintAndLogEx(WARNING, "\nPython initialization failed with exception: %s", status.err_msg);
|
||||||
|
}
|
||||||
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue