import pprint
import time


def remote_setup_loop(remote, up=None, force_update=False):
  """Waits until the remote build system is up."""
  while True:
    response = remote.connect(up, force_update=force_update)
    status = response["status"]
    pprint.pprint(status)
    if (status["remote_executor"] != "NULL" and
        status["running_workers"] > 0 and
        status["server_status"] == "Response.UpToDate" and
        status["workers_status"] == "Response.UpToDate"):
      return (status, response.get("auth_info"))
    time.sleep(5)