#!/usr/bin/python
# -*- coding: utf8 -*-

import os
import sys
import time
import subprocess

if os.environ.get('SSH_MASTER_CONN_ARCADIA', ''):
    os.environ["SVN_SSH"] = "ssh -S %s" % os.environ['SSH_MASTER_CONN_ARCADIA']

N_TRIES = 6
DELAY = 30

def main():
    if len(sys.argv) < 2:
        sys.exit("expected changelog arcadia url")

    for _ in range(N_TRIES):
        try:
            if subprocess.check_output(["svn", "ls", sys.argv[1]]):
                print "SUCCESS: changelog %s was found" % sys.argv[1]
                sys.exit(0)
        except Exception as e:
            print e, type(e)

        print "waiting for %d seconds..." % DELAY
        sys.stdout.flush()
        time.sleep(DELAY)

    sys.exit("ERROR: can't find changelog %s" % sys.argv[1])


if __name__ == '__main__':
    main()
