-
Notifications
You must be signed in to change notification settings - Fork 104
#601 Creation of print_utils.py #716
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
8379684
be80856
8d2d198
45a01f8
9ed7a11
bf7d69f
df050d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| from os.path import isfile, isdir, join | ||
| from os import listdir | ||
| from io import TextIOWrapper | ||
| from click import echo | ||
|
|
||
| from electionguard.election import CiphertextElectionContext | ||
| from electionguard.manifest import InternationalizedText, Manifest | ||
|
|
@@ -16,7 +15,7 @@ | |
| _T = TypeVar("_T") | ||
|
|
||
|
|
||
| class InputRetrievalStepBase(CliStepBase): | ||
| class InputRetrievalStepBase("""CliStepBase"""): | ||
|
||
| """A common base class for all CLI commands that accept user input""" | ||
|
|
||
| def _get_manifest(self, manifest_file: TextIOWrapper) -> Manifest: | ||
|
|
@@ -67,5 +66,5 @@ def _get_ballots(ballots_path: str, ballot_type: Type[_T]) -> List[_T]: | |
| @staticmethod | ||
| def _get_ballot(ballots_dir: str, filename: str, ballot_type: Type[_T]) -> _T: | ||
| full_file = join(ballots_dir, filename) | ||
| echo(f"Importing {filename}") | ||
| print_message(f"Importing {filename}") | ||
| return from_file(ballot_type, full_file) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| from typing import List | ||
| import click | ||
| #import click | ||
|
||
|
|
||
| from electionguard.data_store import DataStore | ||
| from electionguard.ballot_box import BallotBox | ||
|
|
@@ -13,6 +13,8 @@ | |
| from ..cli_models import BuildElectionResults, EncryptResults | ||
| from ..cli_steps import CliStepBase | ||
| from .e2e_inputs import E2eInputs | ||
| from print_utils import print_message | ||
|
|
||
|
|
||
|
|
||
| class SubmitVotesStep(CliStepBase): | ||
|
|
@@ -52,7 +54,5 @@ def _cast_and_spoil( | |
| else: | ||
| submitted_ballot = ballot_box.cast(ballot) | ||
|
|
||
| click.echo( | ||
| f"Submitted Ballot Id: {ballot.object_id} state: {get_optional(submitted_ballot).state}" | ||
| ) | ||
| print_message(f"Submitted Ballot Id: {ballot.object_id} state: {get_optional(submitted_ballot).state}") | ||
| return ballot_store | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import click | ||
| from typing import Any, Optional | ||
|
|
||
| VERIFICATION_URL_NAME = "verification_url" | ||
|
|
||
| def print_header(text: str, header_color="green") -> None: | ||
| click.echo("") | ||
| click.secho(f"{'-'*40}", fg=header_color) | ||
| click.echo(text, fg=header_color) | ||
| click.echo(f"{'-'*40}", header_color) | ||
|
|
||
| def print_message(text: str, color="white", underlined=False, bolded=False) -> None: | ||
| click.secho(f"{text}", fg=color, underline=underlined, bold=bolded) | ||
|
|
||
| def print_warning(text: str, warning_color="bright_red") -> None: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you confirm that the warning color and error color are the same? |
||
| click.secho(f"WARNING: {text}", fg=warning_color, bold=True) | ||
|
|
||
| def print_error(text: str, error_color="bright_red"): | ||
| click.secho(f"Error: {text}", fg=error_color, bold=True, italic=True) | ||
|
|
||
| def print_value(name: str, value: Any, value_color="yellow") -> None: | ||
| click.echo(click.style(name + ": ") + click.style(value, fg=self.value_color)) | ||
|
|
||
| def print_section(text: Optional[str], section_color="bright-white") -> None: | ||
| click.echo("") | ||
| click.secho(text, fg=section_color, bold=True) | ||
|
|
||
| def cleanup() -> None: | ||
| click.clear() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the header_color and other colors that are unused in this file