Skip to content

Commit 6fb65b3

Browse files
author
Thinh Nguyen
committed
fix removing outdated files/directory
1 parent 7c6dc37 commit 6fb65b3

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

element_array_ephys/readers/kilosort_triggering.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,15 @@ def _update_module_status(self, updated_module_status={}):
310310
modules_status = json.load(f)
311311
modules_status = {**modules_status, **updated_module_status}
312312
else:
313-
# handle cases where hash is changed(different paramset) and trying to rerun processing
314-
# delete all files in kilosort output folder, all will be regenerated when kilosort is rerun
315-
# recreate /json_configs directory after all kilosort output files are deleted
316-
shutil.rmtree(self._ks_output_dir)
317-
self._json_directory.mkdir(parents=True, exist_ok=True)
313+
# handle cases of processing rerun on different parameters (the hash changes)
314+
# delete outdated files
315+
outdated_files = [
316+
f
317+
for f in self._json_directory.glob("*")
318+
if f.is_file() and f.name != self._module_input_json.name
319+
]
320+
for f in outdated_files:
321+
f.unlink()
318322

319323
modules_status = {
320324
module: {"start_time": None, "completion_time": None, "duration": None}
@@ -608,11 +612,15 @@ def _update_module_status(self, updated_module_status={}):
608612
modules_status = json.load(f)
609613
modules_status = {**modules_status, **updated_module_status}
610614
else:
611-
# handle cases where hash is changed(different paramset) and trying to rerun processing
612-
# delete all files in kilosort output folder, all will be regenerated when kilosort is rerun
613-
# recreate /json_configs directory after all kilosort output files are deleted
614-
shutil.rmtree(self._ks_output_dir)
615-
self._json_directory.mkdir(parents=True, exist_ok=True)
615+
# handle cases of processing rerun on different parameters (the hash changes)
616+
# delete outdated files
617+
outdated_files = [
618+
f
619+
for f in self._json_directory.glob("*")
620+
if f.is_file() and f.name != self._module_input_json.name
621+
]
622+
for f in outdated_files:
623+
f.unlink()
616624

617625
modules_status = {
618626
module: {"start_time": None, "completion_time": None, "duration": None}

0 commit comments

Comments
 (0)