diff --git a/everyvoice/wizard/__init__.py b/everyvoice/wizard/__init__.py index fed56c58..3a034dd6 100644 --- a/everyvoice/wizard/__init__.py +++ b/everyvoice/wizard/__init__.py @@ -1,3 +1,4 @@ +import os import sys from enum import Enum from typing import Optional, Sequence @@ -42,6 +43,14 @@ def sanitize_input(self, response): """ return response + def sanitize_paths(self, response): + """For steps that return path, have sanitize_input call sanitize_paths""" + # Remove surrounding whitespace + response = response.strip() + # Support ~ and ~username path expansions + response = os.path.expanduser(response) + return response + def validate(self, response) -> bool: """Validate the response. diff --git a/everyvoice/wizard/basic.py b/everyvoice/wizard/basic.py index c47f6c5f..dc7dc2a8 100644 --- a/everyvoice/wizard/basic.py +++ b/everyvoice/wizard/basic.py @@ -138,8 +138,7 @@ def prompt(self): ).unsafe_ask() def sanitize_input(self, response): - response = super().sanitize_input(response) - return response.strip() + return self.sanitize_paths(response) def validate(self, response) -> bool: path = Path(response) diff --git a/everyvoice/wizard/dataset.py b/everyvoice/wizard/dataset.py index 797bd689..0d4e8428 100644 --- a/everyvoice/wizard/dataset.py +++ b/everyvoice/wizard/dataset.py @@ -91,8 +91,7 @@ def prompt(self): ).unsafe_ask() def sanitize_input(self, response): - response = super().sanitize_input(response) - return response.strip() + return self.sanitize_paths(response) def validate(self, response) -> bool: valid_path = validate_path(response, is_dir=True, exists=True) @@ -142,8 +141,7 @@ def prompt(self): ).unsafe_ask() def sanitize_input(self, response): - response = super().sanitize_input(response) - return response.strip() + return self.sanitize_paths(response) def validate(self, response) -> bool: return validate_path(response, is_file=True, exists=True)