From 69cf7fda62bce052e054a1c4405f2168f4a35569 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Thu, 7 Nov 2024 11:08:23 +0100 Subject: [PATCH 1/2] [fix] enable audiotools CLI format listing without required arguments --- .../audiotools/__init__.py | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/ivas_processing_scripts/audiotools/__init__.py b/ivas_processing_scripts/audiotools/__init__.py index 7cb4f06c..3d395527 100755 --- a/ivas_processing_scripts/audiotools/__init__.py +++ b/ivas_processing_scripts/audiotools/__init__.py @@ -55,14 +55,12 @@ def add_processing_args(group, input=True): f"-{ps}", f"--{p}", dest=f"{p}put", - required=True, type=Path, help="Path to *.{wav, pcm, raw} file or directory", ) group.add_argument( f"-{ps}f", f"--{p}_fmt", - required=input, type=str, help="Audio format (use -l, --list for a list / -L, --long for a detailed list)", default=None, @@ -132,7 +130,7 @@ def add_processing_args(group, input=True): ) -def get_args(): +def get_argparser(): parser = argparse.ArgumentParser( description="Audiotools: Convert/Manipulate spatial audio files." ) @@ -224,12 +222,15 @@ def get_args(): action="store_true", ) - return parser.parse_args() + return parser def main(): - args = get_args() + parser = get_argparser() + + args = parser.parse_args() + # special arguments for listing formats if args.list is True or args.long is True: for fmt in AUDIO_FORMATS: if args.long: @@ -239,6 +240,11 @@ def main(): else: print(", ".join(fmt.keys())) exit() + + # validate required arguments + if args.input is None or args.in_fmt is None or args.output is None: + parser.print_usage() + raise SystemExit("the following arguments are required: -i/--in, -if/--in_fmt, -o/--out") elif args.input is not None: if not args.out_fs: @@ -272,7 +278,12 @@ def main(): if len(in_files) == 1 and args.input.is_file(): out_files = [args.output] else: - args.output.mkdir(exist_ok=True) + # input was a dir so output should be a dir too + if args.output.is_file(): + raise NotADirectoryError(f"Input directory '{args.input}' specified with file output to '{args.output}' - please specify an output directory instead") + if not args.output.exists(): + args.output.mkdir() + print(f"Created output directory {args.output}") out_files = [args.output.joinpath(i.name) for i in in_files] # Multiprocessing -- GitLab From 7f21f5201ea5cc76853ca0efeb53e13f4b332ab0 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Thu, 7 Nov 2024 11:09:07 +0100 Subject: [PATCH 2/2] [fix] extra newline printed for progressbars --- ivas_processing_scripts/__init__.py | 2 +- ivas_processing_scripts/processing/processing.py | 4 ++-- ivas_processing_scripts/utils.py | 2 +- other/check_conditions.py | 2 +- other/lp16k.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ivas_processing_scripts/__init__.py b/ivas_processing_scripts/__init__.py index 7f6598bf..36014870 100755 --- a/ivas_processing_scripts/__init__.py +++ b/ivas_processing_scripts/__init__.py @@ -209,7 +209,7 @@ def main(args): spinner() sleep(0.1) progressbar_update(count, count, width) - print("\n", flush=True, file=sys.stdout) + print("", flush=True, file=sys.stdout) results.get() p.close() diff --git a/ivas_processing_scripts/processing/processing.py b/ivas_processing_scripts/processing/processing.py index a2e33160..4d96571f 100755 --- a/ivas_processing_scripts/processing/processing.py +++ b/ivas_processing_scripts/processing/processing.py @@ -345,7 +345,7 @@ def preprocess(cfg, logger): spinner() sleep(0.1) progressbar_update(count, count, width) - print("\n", flush=True, file=sys.stdout) + print("", flush=True, file=sys.stdout) results.get() p.close() @@ -441,7 +441,7 @@ def preprocess_2(cfg, logger): spinner() sleep(0.1) progressbar_update(count, count, width) - print("\n", flush=True, file=sys.stdout) + print("", flush=True, file=sys.stdout) results.get() p.close() diff --git a/ivas_processing_scripts/utils.py b/ivas_processing_scripts/utils.py index f71a6b5b..b1104096 100755 --- a/ivas_processing_scripts/utils.py +++ b/ivas_processing_scripts/utils.py @@ -296,7 +296,7 @@ def progressbar(iter: Iterable, width=80): for i, item in enumerate(iter): yield item progressbar_update(i + 1, count, width) - print("\n", flush=True, file=sys.stdout) + print("", flush=True, file=sys.stdout) def spinner(): diff --git a/other/check_conditions.py b/other/check_conditions.py index 7ec03c8c..74dfe8b4 100644 --- a/other/check_conditions.py +++ b/other/check_conditions.py @@ -231,7 +231,7 @@ def compare_dirs(ref_dir: Path, cut_dir: Path): spinner() sleep(0.1) progressbar_update(count, count, width) - print("\n", flush=True, file=sys.stdout) + print("", flush=True, file=sys.stdout) results.get() diff --git a/other/lp16k.py b/other/lp16k.py index 451b83b8..cec0394f 100755 --- a/other/lp16k.py +++ b/other/lp16k.py @@ -92,7 +92,7 @@ def main(args): spinner() sleep(0.1) progressbar_update(count, count, width) - print("\n", flush=True, file=sys.stdout) + print("", flush=True, file=sys.stdout) results.get() p.close() -- GitLab