Convert detect from bash script to python script

Converts as much of the tool chain as possible to the language that this community understands best.