From 55cc512de52ee145a9b89bc1cd48aa72bf3106e2 Mon Sep 17 00:00:00 2001 From: Neel Redkar Date: Wed, 4 Dec 2019 12:47:59 -0800 Subject: [PATCH 1/3] added pretty logging and echo via pager --- evalai/utils/auth.py | 3 ++- evalai/utils/challenges.py | 42 +++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/evalai/utils/auth.py b/evalai/utils/auth.py index 2e38c20e1..18ef4b5cb 100644 --- a/evalai/utils/auth.py +++ b/evalai/utils/auth.py @@ -97,4 +97,5 @@ def get_host_url(): data = fr.read() return str(data) except (OSError, IOError) as e: - echo(e) + echo(style(e,bold=True, + fg="red")) diff --git a/evalai/utils/challenges.py b/evalai/utils/challenges.py index 8f2d86a7a..467ef5d00 100644 --- a/evalai/utils/challenges.py +++ b/evalai/utils/challenges.py @@ -4,7 +4,7 @@ from bs4 import BeautifulSoup from beautifultable import BeautifulTable -from click import echo, style +from click import echo, style, echo_via_pager from datetime import datetime from evalai.utils.auth import get_request_header, get_host_url @@ -43,7 +43,7 @@ def pretty_print_challenge_data(challenges): end_date = convert_UTC_date_to_local(challenge["end_date"]) values.extend([creator, start_date, end_date]) table.append_row(values) - echo(table) + echo_via_pager(style(table,fg="blue")) def display_challenges(url): @@ -57,7 +57,7 @@ def display_challenges(url): except requests.exceptions.HTTPError as err: if response.status_code == 401: validate_token(response.json()) - echo(err) + echo(style(err,fg="red",bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -76,7 +76,7 @@ def display_challenges(url): if len(challenges) != 0: pretty_print_challenge_data(challenges) else: - echo("Sorry, no challenges found.") + echo(style("Sorry, no challenges found.",fg="red",bold=True,)) def display_all_challenge_list(): @@ -108,7 +108,7 @@ def display_ongoing_challenge_list(): except requests.exceptions.HTTPError as err: if response.status_code == 401: validate_token(response.json()) - echo(err) + echo(style(err,fg="red",bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -138,7 +138,7 @@ def display_ongoing_challenge_list(): if len(challenges) != 0: pretty_print_challenge_data(challenges) else: - echo("Sorry, no challenges found.") + echo(style("Sorry, no challenges found.",fg="red",bold=True,)) def display_future_challenge_list(): @@ -161,7 +161,7 @@ def get_participant_or_host_teams(url): except requests.exceptions.HTTPError as err: if response.status_code == 401: validate_token(response.json()) - echo(err) + echo(style(err,fg="red",bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -192,7 +192,7 @@ def get_participant_or_host_team_challenges(url, teams): except requests.exceptions.HTTPError as err: if response.status_code == 401: validate_token(response.json()) - echo(err) + echo(style(err,fg="red",bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -295,7 +295,7 @@ def pretty_print_challenge_details(challenge): list(map(lambda item: clean_data(challenge[item]), attributes)) ) table.append_row(values) - echo(table) + echo_via_pager(style(table,fg="blue")) def display_challenge_details(challenge): @@ -328,7 +328,7 @@ def display_challenge_details(challenge): ) ) else: - echo(err) + echo(style(err,fg="red",bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -363,7 +363,7 @@ def pretty_print_all_challenge_phases(phases): description = clean_data(phase["description"]) values.append(description) table.append_row(values) - echo(table) + echo_via_pager(style(table,fg="blue")) def display_challenge_phase_list(challenge_id): @@ -402,7 +402,7 @@ def display_challenge_phase_list(challenge_id): ) ) else: - echo(err) + echo(style(err,fg="red",bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -478,7 +478,7 @@ def pretty_print_challenge_phase_data(phase): is_active, is_public, ) - echo(challenge_phase) + echo_via_pager(style(hallenge_phase,fg="blue")) def display_challenge_phase_detail(challenge_id, phase_id, is_json): @@ -507,7 +507,7 @@ def display_challenge_phase_detail(challenge_id, phase_id, is_json): ) ) else: - echo(err) + echo(style(err,fg="red",bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -525,7 +525,7 @@ def display_challenge_phase_detail(challenge_id, phase_id, is_json): phase = response if is_json: phase_json = json.dumps(phase, indent=4, sort_keys=True) - echo(phase_json) + echo_via_pager(phase_json) else: pretty_print_challenge_phase_data(phase) @@ -547,7 +547,7 @@ def pretty_print_challenge_phase_split_data(phase_splits): if split["visibility"] == 3: values = list(map(lambda item: split[item], attributes)) table.append_row(values) - echo(table) + echo(style(table,fg="blue")) def display_challenge_phase_split_list(challenge_id): @@ -575,7 +575,7 @@ def display_challenge_phase_split_list(challenge_id): ) ) else: - echo(err) + echo(style(err,fg="red",bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -592,7 +592,7 @@ def display_challenge_phase_split_list(challenge_id): if len(phase_splits) != 0: pretty_print_challenge_phase_split_data(phase_splits) else: - echo("Sorry, no Challenge Phase Splits found.") + echo(style("Sorry, no Challenge Phase Splits found.",fg="red",bold=True)) def pretty_print_leaderboard_data(attributes, results): @@ -614,7 +614,7 @@ def pretty_print_leaderboard_data(attributes, results): leaderboard_row = [rank, name] + scores + [last_submitted] leaderboard_table.append_row(leaderboard_row) - echo(leaderboard_table) + echo_via_pager(style(leaderboard_table,fg="blue")) def display_leaderboard(challenge_id, phase_split_id): @@ -638,7 +638,7 @@ def display_leaderboard(challenge_id, phase_split_id): ) ) else: - echo(err) + echo(style(err,fg="red",bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -658,4 +658,4 @@ def display_leaderboard(challenge_id, phase_split_id): attributes = results[0]["leaderboard__schema"]["labels"] pretty_print_leaderboard_data(attributes, results) else: - echo("Sorry, no Leaderboard results found.") + echo("Sorry, no Leaderboard results found.",bold=True,fg="red",) From aa0b1e7d4d20dc731bf6c1765c79dfe61efe3879 Mon Sep 17 00:00:00 2001 From: Neel Redkar Date: Wed, 4 Dec 2019 15:39:39 -0800 Subject: [PATCH 2/3] fix whitespace problems --- evalai/utils/auth.py | 3 +-- evalai/utils/challenges.py | 42 +++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/evalai/utils/auth.py b/evalai/utils/auth.py index 18ef4b5cb..75b93f222 100644 --- a/evalai/utils/auth.py +++ b/evalai/utils/auth.py @@ -97,5 +97,4 @@ def get_host_url(): data = fr.read() return str(data) except (OSError, IOError) as e: - echo(style(e,bold=True, - fg="red")) + echo(style(e, bold=True, fg="red")) diff --git a/evalai/utils/challenges.py b/evalai/utils/challenges.py index 467ef5d00..9fc7d8085 100644 --- a/evalai/utils/challenges.py +++ b/evalai/utils/challenges.py @@ -43,7 +43,7 @@ def pretty_print_challenge_data(challenges): end_date = convert_UTC_date_to_local(challenge["end_date"]) values.extend([creator, start_date, end_date]) table.append_row(values) - echo_via_pager(style(table,fg="blue")) + echo_via_pager(style(table, fg="blue")) def display_challenges(url): @@ -57,7 +57,7 @@ def display_challenges(url): except requests.exceptions.HTTPError as err: if response.status_code == 401: validate_token(response.json()) - echo(style(err,fg="red",bold=True)) + echo(style(err, fg="red", bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -76,7 +76,7 @@ def display_challenges(url): if len(challenges) != 0: pretty_print_challenge_data(challenges) else: - echo(style("Sorry, no challenges found.",fg="red",bold=True,)) + echo(style("Sorry, no challenges found.", fg="red", bold=True,)) def display_all_challenge_list(): @@ -108,7 +108,7 @@ def display_ongoing_challenge_list(): except requests.exceptions.HTTPError as err: if response.status_code == 401: validate_token(response.json()) - echo(style(err,fg="red",bold=True)) + echo(style(err, fg="red", bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -138,7 +138,7 @@ def display_ongoing_challenge_list(): if len(challenges) != 0: pretty_print_challenge_data(challenges) else: - echo(style("Sorry, no challenges found.",fg="red",bold=True,)) + echo(style("Sorry, no challenges found.", fg="red", bold=True,)) def display_future_challenge_list(): @@ -161,7 +161,7 @@ def get_participant_or_host_teams(url): except requests.exceptions.HTTPError as err: if response.status_code == 401: validate_token(response.json()) - echo(style(err,fg="red",bold=True)) + echo(style(err, fg="red", bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -192,7 +192,7 @@ def get_participant_or_host_team_challenges(url, teams): except requests.exceptions.HTTPError as err: if response.status_code == 401: validate_token(response.json()) - echo(style(err,fg="red",bold=True)) + echo(style(err, fg="red", bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -253,8 +253,8 @@ def display_participated_or_hosted_challenges( filter( lambda challenge: validate_date_format( challenge["end_date"] - ) - > datetime.now() + ) > + datetime.now() and challenge["approved_by_admin"] and challenge["published"], challenges, @@ -295,7 +295,7 @@ def pretty_print_challenge_details(challenge): list(map(lambda item: clean_data(challenge[item]), attributes)) ) table.append_row(values) - echo_via_pager(style(table,fg="blue")) + echo_via_pager(style(table, fg="blue")) def display_challenge_details(challenge): @@ -328,7 +328,7 @@ def display_challenge_details(challenge): ) ) else: - echo(style(err,fg="red",bold=True)) + echo(style(err, fg="red", bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -363,7 +363,7 @@ def pretty_print_all_challenge_phases(phases): description = clean_data(phase["description"]) values.append(description) table.append_row(values) - echo_via_pager(style(table,fg="blue")) + echo_via_pager(style(table, fg="blue")) def display_challenge_phase_list(challenge_id): @@ -402,7 +402,7 @@ def display_challenge_phase_list(challenge_id): ) ) else: - echo(style(err,fg="red",bold=True)) + echo(style(err, fg="red", bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -478,7 +478,7 @@ def pretty_print_challenge_phase_data(phase): is_active, is_public, ) - echo_via_pager(style(hallenge_phase,fg="blue")) + echo_via_pager(style(challenge_phase, fg="blue")) def display_challenge_phase_detail(challenge_id, phase_id, is_json): @@ -507,7 +507,7 @@ def display_challenge_phase_detail(challenge_id, phase_id, is_json): ) ) else: - echo(style(err,fg="red",bold=True)) + echo(style(err, fg="red", bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -547,7 +547,7 @@ def pretty_print_challenge_phase_split_data(phase_splits): if split["visibility"] == 3: values = list(map(lambda item: split[item], attributes)) table.append_row(values) - echo(style(table,fg="blue")) + echo(style(table, fg="blue")) def display_challenge_phase_split_list(challenge_id): @@ -575,7 +575,7 @@ def display_challenge_phase_split_list(challenge_id): ) ) else: - echo(style(err,fg="red",bold=True)) + echo(style(err, fg="red", bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -592,7 +592,7 @@ def display_challenge_phase_split_list(challenge_id): if len(phase_splits) != 0: pretty_print_challenge_phase_split_data(phase_splits) else: - echo(style("Sorry, no Challenge Phase Splits found.",fg="red",bold=True)) + echo(style("Sorry, no Challenge Phase Splits found.", fg="red", bold=True)) def pretty_print_leaderboard_data(attributes, results): @@ -614,7 +614,7 @@ def pretty_print_leaderboard_data(attributes, results): leaderboard_row = [rank, name] + scores + [last_submitted] leaderboard_table.append_row(leaderboard_row) - echo_via_pager(style(leaderboard_table,fg="blue")) + echo_via_pager(style(leaderboard_table, fg="blue")) def display_leaderboard(challenge_id, phase_split_id): @@ -638,7 +638,7 @@ def display_leaderboard(challenge_id, phase_split_id): ) ) else: - echo(style(err,fg="red",bold=True)) + echo(style(err, fg="red", bold=True)) sys.exit(1) except requests.exceptions.RequestException: echo( @@ -658,4 +658,4 @@ def display_leaderboard(challenge_id, phase_split_id): attributes = results[0]["leaderboard__schema"]["labels"] pretty_print_leaderboard_data(attributes, results) else: - echo("Sorry, no Leaderboard results found.",bold=True,fg="red",) + echo("Sorry, no Leaderboard results found.", bold=True, fg="red",) From a5a45ae1da92b6cdb13c1724942a98830dbdd448 Mon Sep 17 00:00:00 2001 From: Neel Redkar Date: Fri, 6 Dec 2019 17:05:58 -0800 Subject: [PATCH 3/3] add fixes --- 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 9fc7d8085..f965af578 100644 --- a/evalai/utils/challenges.py +++ b/evalai/utils/challenges.py @@ -43,7 +43,7 @@ def pretty_print_challenge_data(challenges): end_date = convert_UTC_date_to_local(challenge["end_date"]) values.extend([creator, start_date, end_date]) table.append_row(values) - echo_via_pager(style(table, fg="blue")) + echo_via_pager(table) def display_challenges(url): @@ -295,7 +295,7 @@ def pretty_print_challenge_details(challenge): list(map(lambda item: clean_data(challenge[item]), attributes)) ) table.append_row(values) - echo_via_pager(style(table, fg="blue")) + echo_via_pager(table) def display_challenge_details(challenge): @@ -363,7 +363,7 @@ def pretty_print_all_challenge_phases(phases): description = clean_data(phase["description"]) values.append(description) table.append_row(values) - echo_via_pager(style(table, fg="blue")) + echo_via_pager(table) def display_challenge_phase_list(challenge_id): @@ -478,7 +478,7 @@ def pretty_print_challenge_phase_data(phase): is_active, is_public, ) - echo_via_pager(style(challenge_phase, fg="blue")) + echo_via_pager(challenge_phase) def display_challenge_phase_detail(challenge_id, phase_id, is_json): @@ -614,7 +614,7 @@ def pretty_print_leaderboard_data(attributes, results): leaderboard_row = [rank, name] + scores + [last_submitted] leaderboard_table.append_row(leaderboard_row) - echo_via_pager(style(leaderboard_table, fg="blue")) + echo_via_pager(leaderboard_table) def display_leaderboard(challenge_id, phase_split_id):