import os

def generate_unique_logpath(logdir, raw_run_name):
    i = 0
    while(True):
        run_name = raw_run_name + "_" + str(i)
        log_path = os.path.join(logdir, run_name)
        if not os.path.isdir(log_path):
            return log_path
        i = i + 1

def create_unique_logpath(top_logdir, raw_run_name):
    if not os.path.exists(top_logdir):
        os.mkdir(top_logdir)
    logdir = generate_unique_logpath(top_logdir, raw_run_name)
    os.mkdir(logdir)
    return logdir