huge migration to flask layout.

This is overall done, but strings of grunt are still woven through it.

@antlong, this should be reviewed and tested by you before merging into master.