diff --git a/src/electionguard_cli/cli_steps/cli_step_base.py b/src/electionguard_cli/cli_steps/cli_step_base.py index 777e40d5..c7a45643 100644 --- a/src/electionguard_cli/cli_steps/cli_step_base.py +++ b/src/electionguard_cli/cli_steps/cli_step_base.py @@ -1,6 +1,7 @@ from typing import Any, Optional +from electionguard_cli.print_utils import print_header, print_warning_utils #import click -from print_utils import Echo, Secho, Style +from print_utils import print_header_utils, print_message_utils, print_value_utils class CliStepBase: """ @@ -15,25 +16,22 @@ class CliStepBase: VERIFICATION_URL_NAME = "verification_url" def print_header(self, s: str) -> None: + print_header_utils(s) #click.echo("") - Echo("") #click.secho(f"{'-'*40}", fg=self.header_color) - Secho(f"{'-'*40}", fg=self.header_color) #click.secho(s, fg=self.header_color) - Secho(s, fg=self.header_color) #click.secho(f"{'-'*40}", fg=self.header_color) - Secho(f"{'-'*40}", fg=self.header_color) def print_section(self, s: Optional[str]) -> None: + print_message_utils(s) #click.echo("") - Echo("") #click.secho(s, fg=self.section_color, bold=True) - Secho(s, fg=self.section_color, bold=True) def print_value(self, name: str, value: Any) -> None: + print_value_utils(name, value) #click.echo(click.style(name + ": ") + click.style(value, fg=self.value_color)) - Echo(Style(name + ": ") + Style(value, fg=self.value_color)) def print_warning(self, s: str) -> None: + print_warning_utils(s) #click.secho(f"WARNING: {s}", fg=self.warning_color) - Secho(f"WARNING: {s}", fg=self.warning_color) + diff --git a/src/electionguard_cli/cli_steps/decrypt_step.py b/src/electionguard_cli/cli_steps/decrypt_step.py index ca2a72e0..ad526e14 100644 --- a/src/electionguard_cli/cli_steps/decrypt_step.py +++ b/src/electionguard_cli/cli_steps/decrypt_step.py @@ -1,6 +1,6 @@ from typing import List #import click -from print_utils import Echo +from print_utils import print_text_utils from electionguard.guardian import Guardian from electionguard.utils import get_optional from electionguard.ballot import SubmittedBallot @@ -56,7 +56,7 @@ def decrypt( decryption_mediator.announce(guardian_key, tally_share, ballot_shares) count += 1 #click.echo(f"Guardian Present: {guardian.id}") - Echo(f"Guardian Present: {guardian.id}") + print_text_utils(f"Guardian Present: {guardian.id}") lagrange_coefficients = self._get_lagrange_coefficients(decryption_mediator) diff --git a/src/electionguard_cli/cli_steps/election_builder_step.py b/src/electionguard_cli/cli_steps/election_builder_step.py index 2f10f820..5d29409d 100644 --- a/src/electionguard_cli/cli_steps/election_builder_step.py +++ b/src/electionguard_cli/cli_steps/election_builder_step.py @@ -1,6 +1,6 @@ from typing import Optional #import click -from print_utils import Echo +from print_utils import print_text_utils from electionguard.elgamal import ElGamalPublicKey from electionguard.group import ElementModQ from electionguard.utils import get_optional @@ -23,7 +23,7 @@ def _build_election( self.print_header("Building election") #click.echo("Initializing public key and commitment hash") - Echo("Initializing public key and commitment hash") + print_text_utils("Initializing public key and commitment hash") election_builder = ElectionBuilder( election_inputs.guardian_count, election_inputs.quorum, @@ -36,7 +36,7 @@ def _build_election( self.VERIFICATION_URL_NAME, verification_url ) #click.echo("Creating context and internal manifest") - Echo("Creating context and internal manifest") + print_text_utils("Creating context and internal manifest") build_result = election_builder.build() internal_manifest, context = get_optional(build_result) return BuildElectionResults(internal_manifest, context) diff --git a/src/electionguard_cli/cli_steps/encrypt_votes_step.py b/src/electionguard_cli/cli_steps/encrypt_votes_step.py index 08a21987..40304958 100644 --- a/src/electionguard_cli/cli_steps/encrypt_votes_step.py +++ b/src/electionguard_cli/cli_steps/encrypt_votes_step.py @@ -1,7 +1,7 @@ from typing import List, Tuple #import click -from print_utils import Echo +from print_utils import print_text_utils from electionguard.encrypt import EncryptionDevice, EncryptionMediator from electionguard.election import CiphertextElectionContext from electionguard.manifest import InternalManifest @@ -64,7 +64,7 @@ def _encrypt_ballots( ciphertext_ballots: List[CiphertextBallot] = [] for plaintext_ballot in plaintext_ballots: #click.echo(f"Encrypting ballot: {plaintext_ballot.object_id}") - Echo(f"Encrypting ballot: {plaintext_ballot.object_id}") + print_text_utils(f"Encrypting ballot: {plaintext_ballot.object_id}") encrypted_ballot = encrypter.encrypt(plaintext_ballot) ciphertext_ballots.append(get_optional(encrypted_ballot)) return ciphertext_ballots diff --git a/src/electionguard_cli/cli_steps/submit_ballots_step.py b/src/electionguard_cli/cli_steps/submit_ballots_step.py index 4cfa567a..7994ada8 100644 --- a/src/electionguard_cli/cli_steps/submit_ballots_step.py +++ b/src/electionguard_cli/cli_steps/submit_ballots_step.py @@ -1,7 +1,7 @@ from typing import List #import click -from print_utils import Echo +from print_utils import print_text_utils from electionguard.data_store import DataStore from electionguard.ballot_box import BallotBox from electionguard.ballot import CiphertextBallot @@ -29,11 +29,11 @@ def submit( for ballot in cast_ballots: ballot_box.cast(ballot) #click.echo(f"Cast Ballot Id: {ballot.object_id}") - Echo(f"Cast Ballot Id: {ballot.object_id}") + print_text_utils(f"Cast Ballot Id: {ballot.object_id}") for ballot in spoil_ballots: ballot_box.spoil(ballot) #click.echo(f"Spoilt Ballot Id: {ballot.object_id}") - Echo(f"Spoilt Ballot Id: {ballot.object_id}") + print_text_utils(f"Spoilt Ballot Id: {ballot.object_id}") return SubmitResults(ballot_store.all()) diff --git a/src/electionguard_cli/e2e/submit_votes_step.py b/src/electionguard_cli/e2e/submit_votes_step.py index ed0874f6..9be29267 100644 --- a/src/electionguard_cli/e2e/submit_votes_step.py +++ b/src/electionguard_cli/e2e/submit_votes_step.py @@ -1,7 +1,7 @@ from typing import List #import click -from print_utils import Echo +from print_utils import print_text_utils from electionguard.data_store import DataStore from electionguard.ballot_box import BallotBox from electionguard.election import CiphertextElectionContext @@ -57,7 +57,7 @@ def _cast_and_spoil( #f"Submitted Ballot Id: {ballot.object_id} state: {get_optional(submitted_ballot).state}" #) - Echo( + print_text_utils( f"Submitted Ballot Id: {ballot.object_id} state: {get_optional(submitted_ballot).state}" ) return ballot_store diff --git a/src/electionguard_cli/print_utils.py b/src/electionguard_cli/print_utils.py index b582e365..5bd00fb7 100644 --- a/src/electionguard_cli/print_utils.py +++ b/src/electionguard_cli/print_utils.py @@ -1,19 +1,26 @@ import click +from typing import Any -def print_header(text: str, header_color="green"): +def print_header_utils(text: str, header_color="green"): 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, underlined=False): +def print_message_utils(text: str, underlined=False): click.secho(f"{text}", fg="white", underline=underlined) -def print_warning(text: str, warning_color="bright_red") -> None: +def print_warning_utils(text: str, warning_color="bright_red") -> None: click.secho(f"WARNING: {text}", fg=warning_color, bold=True) -def print_error(text: str, error_color="bright_red"): +def print_error_utils(text: str, error_color="bright_red"): click.secho(f"Error: {text}", fg=error_color, bold=True, italic=True) -def cleanup(): +def print_value_utils(text: str, val: Any): + click.echo(click.style(text + ": ") + click.style(val, fg="yellow")) + +def print_text_utils(text: Any): + click.echo(text) + +def cleanup_utits(): click.clear() \ No newline at end of file