From 9e81dc8ff39d8f511d7affd0e5b56b711c5c5b4f Mon Sep 17 00:00:00 2001 From: Eric Joanis Date: Mon, 23 Sep 2024 11:15:50 -0400 Subject: [PATCH] feat: implementing some of the undo/redo for wizard steps --- everyvoice/wizard/dataset.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/everyvoice/wizard/dataset.py b/everyvoice/wizard/dataset.py index 0de7c2a0..d9a7a7a3 100644 --- a/everyvoice/wizard/dataset.py +++ b/everyvoice/wizard/dataset.py @@ -1,3 +1,4 @@ +import copy import glob import os import random @@ -55,6 +56,9 @@ def effect(self): f"Great! The Configuration Wizard 🧙 finished the configuration for your dataset named '{self.response}'" ) + def is_reversible(self): + return True + class DatasetPermissionStep(Step): DEFAULT_NAME = StepNames.dataset_permission_step @@ -106,6 +110,9 @@ def validate(self, response) -> bool: ) return valid_path and contains_wavs + def is_reversible(self): + return True + class SampleRateConfigStep(Step): DEFAULT_NAME = StepNames.sample_rate_config_step @@ -131,6 +138,9 @@ def validate(self, response): ) return False + def is_reversible(self): + return True + class FilelistStep(Step): DEFAULT_NAME = StepNames.filelist_step @@ -146,6 +156,9 @@ def sanitize_input(self, response): def validate(self, response) -> bool: return validate_path(response, is_file=True, exists=True) + def is_reversible(self): + return True + class FilelistFormatStep(Step): DEFAULT_NAME = StepNames.filelist_format_step @@ -410,9 +423,19 @@ def effect(self): # Rename the filelist header with the standard header name if "selected_headers" not in self.state: self.state["selected_headers"] = [] + self.saved_state = { + "selected_headers": copy.copy(self.state["selected_headers"]), + "filelist_headers": copy.copy(self.state["filelist_headers"]), + } self.state["selected_headers"].append(self.response) self.state["filelist_headers"][self.response] = self.header_name + def is_reversible(self): + return True + + def undo(self): + self.state.update(self.saved_state) + class LanguageHeaderStep(HeaderStep): def effect(self): @@ -438,6 +461,9 @@ def effect(self): ) ) + def is_reversible(self): + return False + class HasHeaderLineStep(Step): """Check if the data set has a header line, and insert one if not. @@ -557,6 +583,9 @@ def effect(self): f"Great! '{self.response}' will be used as the speaker ID for this dataset." ) + def is_reversible(self): + return True + class HasLanguageStep(Step): DEFAULT_NAME = StepNames.data_has_language_value_step