refactor main.py, flesh out functions from main function

@stdweird, @wpoely86: please review?

The diff is going to look a bit messy, maybe you want to look at the actual new `main.py` instead...
fixed by changing back to original working dir in `EasyBlock` before handling extensions (which is exactly what was failing for me in the `toy_build` unit tests when they were run in isolation)