import time


def wait_for_install(tool, tsc, timeout=3600):
    """
    If nginx times out, we look into the list of installed repositories
    and try to determine if a tool of the same namer/owner is still installing.
    Returns True if install finished, returns False when timeout is exceeded.
    """
    def install_done(tool, tsc):
        itl = tsc.get_repositories()
        for it in itl:
            if (tool['name'] == it['name']) and (it['owner'] == tool['owner']):
                if it['status'] not in ['Installed', 'Error']:
                    return False
        return True

    finished = install_done(tool, tsc)
    while (not finished) and (timeout > 0):
        timeout = timeout - 10
        time.sleep(10)
        finished = install_done(tool, tsc)
    if timeout > 0:
        return True
    else:
        return False