Rewrote prepare_files in Python.

* I extended it quite a bit. It's shiny now.