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...
well, this also relates to `--from-pr`, which has nothing to do with `--try-X` or `tweak.py`... But I'll find a better location for this.