From 837b90edbb1f42bba1a492f5810fa6f9b3bcec09 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Thu, 2 Nov 2023 15:16:33 +0100 Subject: [PATCH 1/2] add ovewrite option to save to folder --- src/spikeinterface/core/base.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/spikeinterface/core/base.py b/src/spikeinterface/core/base.py index b51bace55f..5c6a6d260c 100644 --- a/src/spikeinterface/core/base.py +++ b/src/spikeinterface/core/base.py @@ -788,7 +788,7 @@ def save_to_memory(self, **kwargs) -> "BaseExtractor": return cached # TODO rename to saveto_binary_folder - def save_to_folder(self, name=None, folder=None, verbose=True, **save_kwargs): + def save_to_folder(self, name=None, folder=None, ovewrite=False, verbose=True, **save_kwargs): """ Save extractor to folder. @@ -819,6 +819,8 @@ def save_to_folder(self, name=None, folder=None, verbose=True, **save_kwargs): folder: None str or Path Name of the folder. If "folder" is given, "name" must be None. + ovewrite: bool, default: False + If True, the folder is removed if it already exists Returns ------- @@ -839,7 +841,12 @@ def save_to_folder(self, name=None, folder=None, verbose=True, **save_kwargs): print(f"Use cache_folder={folder}") else: folder = Path(folder) - assert not folder.exists(), f"folder {folder} already exists, choose another name" + if ovewrite and folder.is_dir(): + import shutil + + shutil.rmtree(folder) + + assert not folder.exists(), f"folder {folder} already exists, choose another name or use ovewrite=True" folder.mkdir(parents=True, exist_ok=False) # dump provenance From ba908a5784fd0b5dd0fb3cac9024e7f93023b55b Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Fri, 3 Nov 2023 11:33:00 +0100 Subject: [PATCH 2/2] fix names --- src/spikeinterface/core/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/spikeinterface/core/base.py b/src/spikeinterface/core/base.py index 5c6a6d260c..1a8674697a 100644 --- a/src/spikeinterface/core/base.py +++ b/src/spikeinterface/core/base.py @@ -788,7 +788,7 @@ def save_to_memory(self, **kwargs) -> "BaseExtractor": return cached # TODO rename to saveto_binary_folder - def save_to_folder(self, name=None, folder=None, ovewrite=False, verbose=True, **save_kwargs): + def save_to_folder(self, name=None, folder=None, overwrite=False, verbose=True, **save_kwargs): """ Save extractor to folder. @@ -819,7 +819,7 @@ def save_to_folder(self, name=None, folder=None, ovewrite=False, verbose=True, * folder: None str or Path Name of the folder. If "folder" is given, "name" must be None. - ovewrite: bool, default: False + overwrite: bool, default: False If True, the folder is removed if it already exists Returns @@ -841,12 +841,12 @@ def save_to_folder(self, name=None, folder=None, ovewrite=False, verbose=True, * print(f"Use cache_folder={folder}") else: folder = Path(folder) - if ovewrite and folder.is_dir(): + if overwrite and folder.is_dir(): import shutil shutil.rmtree(folder) - assert not folder.exists(), f"folder {folder} already exists, choose another name or use ovewrite=True" + assert not folder.exists(), f"folder {folder} already exists, choose another name or use overwrite=True" folder.mkdir(parents=True, exist_ok=False) # dump provenance