From 475df57fd1140466594b151615bc7e0ac5767470 Mon Sep 17 00:00:00 2001 From: KhalidRmb Date: Wed, 21 Aug 2019 19:05:18 +0530 Subject: [PATCH 1/2] Add option to verify challenge config file locally. --- evalai/challenges.py | 11 +++++++ evalai/utils/challenges.py | 59 ++++++++++++++++++++++++++++++++++++++ evalai/utils/urls.py | 1 + 3 files changed, 71 insertions(+) diff --git a/evalai/challenges.py b/evalai/challenges.py index 61017ebdf..31f6e8572 100644 --- a/evalai/challenges.py +++ b/evalai/challenges.py @@ -14,6 +14,7 @@ display_challenge_phase_detail, display_challenge_phase_split_list, display_leaderboard, + verify_config_file, ) from evalai.utils.submissions import display_my_submission_details from evalai.utils.teams import participate_in_a_challenge @@ -80,6 +81,16 @@ def challenge(ctx, challenge): display_challenge_details(challenge) +@challenges.command(context_settings={"ignore_unknown_options": True}) +@click.option("--file", type=click.File("rb"), required=True, help="Challenge Zip file.") +@click.argument("team", type=int) +def verify_challenge_config(file, team): + """ + Verify Challenge config zip file locally. Add file path and host team id. + """ + verify_config_file(file, team) + + @challenges.command() def ongoing(): """ diff --git a/evalai/utils/challenges.py b/evalai/utils/challenges.py index 8f2d86a7a..327947578 100644 --- a/evalai/utils/challenges.py +++ b/evalai/utils/challenges.py @@ -21,6 +21,65 @@ requests.packages.urllib3.disable_warnings() +def verify_config_file(file, team): + """ + Function to verify a challenge config file. + """ + url = "{}".format(get_host_url(), URLS.verify_challenge_config.value) + url = url.format(team) + + headers = get_request_header() + file = {"zip_configuration": file} + + try: + response = requests.post(url, headers=headers, files=file) + response.raise_for_status() + except requests.exceptions.HTTPError as err: + if response.status_code in EVALAI_ERROR_CODES: + validate_token(response.json()) + echo( + style( + "\nError: {}.".format(response.json()["error"]), + fg="red", + bold=True, + ) + ) + else: + echo(err) + sys.exit(1) + except requests.exceptions.RequestException: + echo( + style( + "\nCould not establish a connection to EvalAI." + " Please check the Host URL.", + bold=True, + fg="red", + ) + ) + sys.exit(1) + + response = response.json() + response = json.loads(response) + for e in response: + if e == "Success": + echo( + style( + "\n{}".format(response["Success"]), + fg="green", + bold=True, + ) + ) + else: + for m in response[e]: + echo( + style( + "\n{}: {}".format(e, m), + fg="red", + bold=False, + ) + ) + + def pretty_print_challenge_data(challenges): """ Function to print the challenge data diff --git a/evalai/utils/urls.py b/evalai/utils/urls.py index 059d33741..7c0b6e9b1 100644 --- a/evalai/utils/urls.py +++ b/evalai/utils/urls.py @@ -2,6 +2,7 @@ class URLS(Enum): + verify_challenge_config = "/api/challenges/challenge/challenge_host_team/{}/verify_challenge_config/" login = "/api/auth/login" challenge_list = "/api/challenges/challenge/all" past_challenge_list = "/api/challenges/challenge/past" From 3ceed27c0b890efd32ea167a1d5382465826767a Mon Sep 17 00:00:00 2001 From: KhalidRmb Date: Fri, 18 Oct 2019 22:06:17 +0530 Subject: [PATCH 2/2] Made requested changes --- evalai/utils/challenges.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/evalai/utils/challenges.py b/evalai/utils/challenges.py index 327947578..0943b660a 100644 --- a/evalai/utils/challenges.py +++ b/evalai/utils/challenges.py @@ -25,7 +25,7 @@ def verify_config_file(file, team): """ Function to verify a challenge config file. """ - url = "{}".format(get_host_url(), URLS.verify_challenge_config.value) + url = "{}{}".format(get_host_url(), URLS.verify_challenge_config.value) url = url.format(team) headers = get_request_header() @@ -60,8 +60,8 @@ def verify_config_file(file, team): response = response.json() response = json.loads(response) - for e in response: - if e == "Success": + for results in response: + if results == "Success": echo( style( "\n{}".format(response["Success"]), @@ -70,10 +70,10 @@ def verify_config_file(file, team): ) ) else: - for m in response[e]: + for m in response[results]: echo( style( - "\n{}: {}".format(e, m), + "\n{}: {}".format(results, m), fg="red", bold=False, )