#!/usr/bin/env python3

from __future__ import print_function

import argparse
import subprocess


def upload(directory):
    input(
        'Please run rvb-test-model or rvb-test-attack '
        'before submitting your model or attack. '
        'Press [Enter] to continue ...')

    print('Creating archive for submission in folder "{}"'.format(directory))
    subprocess.Popen(
        "tar czf submission.tar.gz {}".format(directory), shell=True).wait()

    print('Uploading submission')
    p = subprocess.Popen(
        "curl --upload-file ./submission.tar.gz "
        "https://transfer.sh/submission.tar.gz",
        shell=True, stdout=subprocess.PIPE)
    url = p.stdout.read().decode('UTF-8')

    print("Your submission has been uploaded to {}".format(url))
    print(
        "You can now go to https://robust.vision/benchmark/participate "
        "and submit the URL")


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "directory", help="The directory containing the Dockerfile.")
    args = parser.parse_args()
    upload(args.directory)
