see [here](http://pythonpaste.org/tempita/) might replace some of the manual code paths in `generate_code.py`