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...
if the build option specified not to retain all dependencies (i.e. `False`), the named argument can override this

this is used by the `dry_run` function for example, but also by the unit tests