Rewrite scripts in Python

This is the first toward supporting Windows (#6).