From d24e61699af8c212546b65c702ba08df0c088b5b Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Thu, 24 Apr 2025 11:09:32 +0200 Subject: [PATCH] add option to delete output directory with user prompt if it exists --- examples/TEMPLATE.yml | 3 +++ ivas_processing_scripts/__init__.py | 28 +++++++++++++++++++++++++--- ivas_processing_scripts/constants.py | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/examples/TEMPLATE.yml b/examples/TEMPLATE.yml index 91c7d36b..65bf5bc5 100755 --- a/examples/TEMPLATE.yml +++ b/examples/TEMPLATE.yml @@ -15,6 +15,9 @@ ### Deletion of temporary directories containing ### intermediate processing files, bitstreams etc.; default = false # delete_tmp: true +### Deletion of output_path if it exists +### WARNING! Use with caution and only for debugging test setup issues!; default = false +# delete_output: false ### Master seed for random processes like bitstream error pattern generation; default = 0 # master_seed: 5 ### Additional seed to specify number of preruns (used for background noise delay and FER bitstream processing); default = 0 diff --git a/ivas_processing_scripts/__init__.py b/ivas_processing_scripts/__init__.py index 36014870..418ccfcc 100755 --- a/ivas_processing_scripts/__init__.py +++ b/ivas_processing_scripts/__init__.py @@ -34,6 +34,8 @@ import logging import sys from itertools import product from multiprocessing import Pool +from pathlib import Path +from shutil import rmtree from time import sleep from ivas_processing_scripts.audiotools.metadata import ( @@ -98,13 +100,33 @@ def main(args): # set up processing chains chains.init_processing_chains(cfg) + # set up logging + logger = logging_init(args, cfg) + + if cfg.delete_output: + deletion_list = [d for d in [*cfg.out_dirs, *cfg.tmp_dirs] if Path(d).exists()] + if deletion_list: + logger.warning( + "\nWARNING! The configuration key to delete output directories was specified!" + ) + logger.warning( + f"The following directories will be REMOVED from {cfg.output_path}:\n {', '.join([d.name for d in deletion_list])}\n" + ) + confirm = input( + "Are you sure you want to delete these? Type 'YES' in capitals to confirm deletion: " + ) + if confirm == "YES": + for dir in deletion_list: + rmtree(dir) + else: + logger.warning( + "Deletion was canceled. Please remove the output directories manually." + ) + # context manager to create output directories and clean up temporary directories with DirManager( cfg.out_dirs + cfg.tmp_dirs, cfg.tmp_dirs if cfg.delete_tmp else [] ): - # set up logging - logger = logging_init(args, cfg) - # Re-ordering items based on concatenation order if hasattr(cfg, "preprocessing_2"): if ( diff --git a/ivas_processing_scripts/constants.py b/ivas_processing_scripts/constants.py index 2119304b..4cae7dd5 100755 --- a/ivas_processing_scripts/constants.py +++ b/ivas_processing_scripts/constants.py @@ -61,6 +61,7 @@ DEFAULT_CONFIG = { "multiprocessing": True, "use_windows_codec_binaries": False, "delete_tmp": False, + "delete_output": False, "master_seed": 0, "prerun_seed": 0, "metadata_path": None, -- GitLab