Launch terminal via Python in different linux distros
I've recently switched to KDE Neon for different experience, and realize that my python scripts for executing commands via launching terminal stopped working. And it hits me that specifying "gnome-terminal" would limit the scripts to only work on distros that comes with "gnome-terminal", and KDE Neon doesn't have it.
As I looked into if there's a command that simply launches the default terminal program, I realize there may not be one. My journey takes me to a github code here, which loops through a list of terminal commands and launches one that's available. Referencing that and using methods listed here, I wrote a python function below that loops through the list of terminal commands, and return the first executable command.
Note that instead of using shutil.which, I'm using distutils.spawn.find_executable, which does not actually verify that the command is executable, merely verify that it is in PATH. That is because my intended use of this script is for The Foundry's Nuke, and it's still using python 2.7.3, which does not have shutil.which