retry.py: make a more generic utility for retrying stuff

Also I've added a few more options:

  * a run limit (more useful with --invert)
  * --invert for continually trying something that succeeds