Trying to understand what’s the purpose of doCommand. It appears to be a way to run python code in a different context, record a macro and to log executed Python code in the Python console. This is quite an unusual approach.
First of all, eval is evil. It is a major attack vector that predates modern computers. With FreeCAD’s ability to execute arbitrary code and add-on authors that might not be aware of “doCommand” threats, it’s a game over in a corporate environment. E.g. it would be at least an embarrassment if somebody targets CERN using FreeCAD’s vulnerability.
The second major reason is that its nearly impossible to refactor strings, check their syntax with tools, hard to debug, test in isolation, etc. How to be sure of anything if you don’t see the whole picture?
Isn’t there a different, safe, and as much powerful way to do what the doCommand provides without using eval?
Python’s contextlib might be a way to do it.
Alternatively, why not just use a function? doCommand(print, “Hello”) might be as powerful.
If you need source code and isolation, maybe put each command into a dedicated module (“import workbenchCommand; doCommand(workbenchCommand)”).
Anybody else thinking that doCommand is harmful?