Skip to content

Commit

Permalink
[Chore] Unify interactive queries in tezos-setup
Browse files Browse the repository at this point in the history
Problem: Some interactive queries use step concept,
while others are done through `yes_or_no`. It's useful
to unify them by using steps only for logging
and for the #568 (non-interactive mode) issue.

Solution: Rewrite delete node data query using steps
instead of `yes_or_no`.
  • Loading branch information
krendelhoff2 committed Oct 18, 2023
1 parent c3c6e91 commit 166f307
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
15 changes: 15 additions & 0 deletions baking/src/tezos_baking/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,18 @@ def get_ledger_derivation_query(ledgers_derivations, node_endpoint, client_dir):
]
),
)


replace_key_options = {
"no": "Keep the existing key",
"yes": "Import a new key and replace the existing one",
}

replace_key_query = Step(
id="replace_key",
prompt="Would you like to import a new key and replace this one?",
help="It's possible to proceed with the existing baker key, instead of\n"
"importing new one.",
options=replace_key_options,
validator=Validator(validators.enum_range(replace_key_options)),
)
17 changes: 16 additions & 1 deletion baking/src/tezos_baking/tezos_setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,20 @@ def get_snapshot_mode_query(config):
)


delete_node_data_options = {
"no": "Keep the existing data",
"yes": "Remove the data under the tezos node data directory",
}

delete_node_data_query = Step(
id="delete_node_data",
prompt="Delete this data and bootstrap the node again?",
help="It's possible to proceed with bootstrapping the node using\n"
"the existing blockchain data, instead of importing fresh snapshot.",
options=delete_node_data_options,
validator=Validator(validators.enum_range(delete_node_data_options)),
)

snapshot_file_query = Step(
id="snapshot_file",
prompt="Provide the path to the node snapshot file.",
Expand Down Expand Up @@ -401,7 +415,8 @@ def check_blockchain_data(self):
)
print("The Tezos node data directory already has some blockchain data:")
print("\n".join(["- " + os.path.join(node_dir, path) for path in diff]))
if yes_or_no("Delete this data and bootstrap the node again? <y/N> ", "no"):
self.query_step(delete_node_data_query)
if self.config["delete_node_data"] == "yes":
# We first stop the node service, because it's possible that it
# will re-create some of the files while we go on with the wizard
print_and_log("Stopping node service")
Expand Down
5 changes: 2 additions & 3 deletions baking/src/tezos_baking/wizard_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,8 @@ def check_baker_account(self):
)
print("Its current address is", address)

return yes_or_no(
"Would you like to import a new key and replace this one? <y/N> ", "no"
)
self.query_step(replace_key_query)
return self.config["replace_key"] == "yes"
else:
return True

Expand Down

0 comments on commit 166f307

Please sign in to comment.