Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for enhancement#1001: Google Code-in Task to update the error message #189

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
18 changes: 18 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# EvalAI-CLI

<b>Command Line utility - Download_file</b>
Download_file - The below steps define the usage for Download_file.

## Pre-Req:
1. Setup the development environment for EvalAI and make sure that it is running perfectly. Check the Instruction under evalai-cli/readme.md file

## Download_file:

1. In terminal with the Eval-CLI platform running, enter evalai download_file command with the entire host url you are using as shown in the below example.

```bash
evalai download_file https://evalai.cloudcv.org/web/submission-files?bucket=<s3_bucket_name>&key=<file_path_in_bucket>
```
2. If url is host and has bucket and key, url will be downloaded as a file

3. If url does not have a bucket or key, error will flash - please check url or check with admin to get AWS s3 bucket name and key information
35 changes: 35 additions & 0 deletions evalai/display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import click
import sys
import os

from click import echo, style

from evalai.utils.config import STDOUT_FILE_PATH
import json


@click.group(invoke_without_command=True)
def display():
"""
Display stdout file.
"""
if not os.path.exists(STDOUT_FILE_PATH):
echo(
style(
"\nThe stdout file doesn't exist at the required path. "
"Please create it at ~/.evalai/stdout.txt or use cat ~/.evalai/stdout.txt to add it.\n\n",
bold=True,
fg="red",
)
)
else:
with open(STDOUT_FILE_PATH, "r") as fr:
try:
file_contents = fr.read()
print (file_contents)
fr.close()
# data = fr.read()
# tokendata = json.loads(data)
# echo("Current token is {}".format(tokendata["token"]))
except (OSError, IOError) as e:
echo(e)
2 changes: 2 additions & 0 deletions evalai/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .teams import teams
from .get_token import get_token
from .login import login
from .display import display


@click.version_option()
Expand Down Expand Up @@ -43,3 +44,4 @@ def main(ctx):
main.add_command(teams)
main.add_command(get_token)
main.add_command(login)
main.add_command(display)
4 changes: 3 additions & 1 deletion evalai/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ def download_file(url):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
parsed_host_url
),
bold=True,
fg="red",
)
Expand Down
5 changes: 4 additions & 1 deletion evalai/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_user_auth_token_by_login(username, password):
Returns user auth token by login.
"""
url = "{}{}".format(get_host_url(), URLS.login.value)
host_url = get_host_url()
try:
payload = {"username": username, "password": password}
response = requests.post(url, data=payload)
Expand All @@ -39,7 +40,9 @@ def get_user_auth_token_by_login(username, password):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down
45 changes: 36 additions & 9 deletions evalai/utils/challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def display_challenges(url):
Function to fetch & display the challenge list based on API
"""
header = get_request_header()
host_url = get_host_url()
try:
response = requests.get(url, headers=header)
response.raise_for_status()
Expand All @@ -63,7 +64,9 @@ def display_challenges(url):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down Expand Up @@ -100,6 +103,7 @@ def display_ongoing_challenge_list():
Displays the list of ongoing challenges from the backend
"""
url = "{}{}".format(get_host_url(), URLS.challenge_list.value)
host_url = get_host_url()

header = get_request_header()
try:
Expand All @@ -114,7 +118,9 @@ def display_ongoing_challenge_list():
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down Expand Up @@ -154,6 +160,7 @@ def get_participant_or_host_teams(url):
Returns the participant or host teams corresponding to the user
"""
header = get_request_header()
host_url = get_host_url()

try:
response = requests.get(url, headers=header)
Expand All @@ -167,7 +174,9 @@ def get_participant_or_host_teams(url):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand All @@ -186,6 +195,7 @@ def get_participant_or_host_team_challenges(url, teams):
challenges = []
for team in teams:
header = get_request_header()
host_url = get_host_url()
try:
response = requests.get(url.format(team["id"]), headers=header)
response.raise_for_status()
Expand All @@ -198,7 +208,9 @@ def get_participant_or_host_team_challenges(url, teams):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down Expand Up @@ -307,6 +319,7 @@ def display_challenge_details(challenge):
url = url.format(challenge)

header = get_request_header()
host_url = get_host_url()
try:
response = requests.get(url, headers=header)
response.raise_for_status()
Expand Down Expand Up @@ -334,7 +347,9 @@ def display_challenge_details(challenge):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down Expand Up @@ -374,6 +389,7 @@ def display_challenge_phase_list(challenge_id):
url = "{}{}".format(get_host_url(), url)
url = url.format(challenge_id)
headers = get_request_header()
host_url = get_host_url()
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
Expand Down Expand Up @@ -408,7 +424,9 @@ def display_challenge_phase_list(challenge_id):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down Expand Up @@ -489,6 +507,7 @@ def display_challenge_phase_detail(challenge_id, phase_id, is_json):
url = "{}{}".format(get_host_url(), url)
url = url.format(challenge_id, phase_id)
headers = get_request_header()
host_url = get_host_url()

try:
response = requests.get(url, headers=headers)
Expand All @@ -513,7 +532,9 @@ def display_challenge_phase_detail(challenge_id, phase_id, is_json):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down Expand Up @@ -558,6 +579,7 @@ def display_challenge_phase_split_list(challenge_id):
url = "{}{}".format(get_host_url(), url)
url = url.format(challenge_id)
headers = get_request_header()
host_url = get_host_url()
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
Expand All @@ -581,7 +603,9 @@ def display_challenge_phase_split_list(challenge_id):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down Expand Up @@ -624,6 +648,7 @@ def display_leaderboard(challenge_id, phase_split_id):
url = "{}{}".format(get_host_url(), URLS.leaderboard.value)
url = url.format(phase_split_id)
headers = get_request_header()
host_url = get_host_url()
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
Expand All @@ -644,7 +669,9 @@ def display_leaderboard(challenge_id, phase_split_id):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down
6 changes: 6 additions & 0 deletions evalai/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@

AUTH_TOKEN_FILE_NAME = "token.json"

STDOUT_FILE_NAME = "stdout.txt"

STDOUT_FILE_DIR = expanduser("~/.evalai/")

HOST_URL_FILE_NAME = "host_url"

AUTH_TOKEN_DIR = expanduser("~/.evalai/")

AUTH_TOKEN_PATH = os.path.join(AUTH_TOKEN_DIR, AUTH_TOKEN_FILE_NAME)

STDOUT_FILE_PATH = os.path.join(STDOUT_FILE_DIR, STDOUT_FILE_NAME)

API_HOST_URL = os.environ.get("EVALAI_API_URL", "https://evalapi.cloudcv.org")

EVALAI_ERROR_CODES = [400, 401, 406]
Expand Down
9 changes: 7 additions & 2 deletions evalai/utils/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
def make_request(path, method, files=None, data=None):
url = "{}{}".format(get_host_url(), path)
headers = get_request_header()
host_url = get_host_url()

if method == "GET":
try:
Expand All @@ -35,7 +36,9 @@ def make_request(path, method, files=None, data=None):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down Expand Up @@ -73,7 +76,9 @@ def make_request(path, method, files=None, data=None):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down
15 changes: 12 additions & 3 deletions evalai/utils/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def make_submission(challenge_id, phase_id, file, submission_metadata={}):
"""
url = "{}{}".format(get_host_url(), URLS.make_submission.value)
url = url.format(challenge_id, phase_id)
host_url = get_host_url()

headers = get_request_header()
input_file = {"input_file": file}
Expand Down Expand Up @@ -57,7 +58,9 @@ def make_submission(challenge_id, phase_id, file, submission_metadata={}):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down Expand Up @@ -148,6 +151,7 @@ def display_my_submission_details(
url = "{}{}".format(get_host_url(), url)
url = url.format(challenge_id, phase_id)
headers = get_request_header()
host_url = get_host_url()

try:
response = requests.get(url, headers=headers)
Expand All @@ -172,7 +176,9 @@ def display_my_submission_details(
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down Expand Up @@ -220,6 +226,7 @@ def submission_details_request(submission_id):
url = "{}{}".format(get_host_url(), URLS.get_submission.value)
url = url.format(submission_id)
headers = get_request_header()
host_url = get_host_url()
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
Expand All @@ -244,7 +251,9 @@ def submission_details_request(submission_id):
echo(
style(
"\nCould not establish a connection to EvalAI."
" Please check the Host URL.\n",
" Please check the Host URL: {}\n".format(
host_url
),
bold=True,
fg="red",
)
Expand Down
Loading