Commit a48560d1 authored by Michaël Lauer's avatar Michaël Lauer
Browse files

refactor arguments parsing in a more elaborate function

parent e85a48d5
import argparse from argparse import ArgumentParser, SUPPRESS
import glob import glob
import os import os
...@@ -6,12 +6,6 @@ import numpy as np ...@@ -6,12 +6,6 @@ import numpy as np
import pandas as pd import pandas as pd
import scipy.io.wavfile import scipy.io.wavfile
parser = argparse.ArgumentParser()
parser.add_argument("--in_dir", type=str, help="input directory")
parser.add_argument("--out_dir", type=str, default="databases", help="output directory")
parser.add_argument("--database", type=str, default="IRCAM", help="name of the database to be generated")
parser.add_argument("--hrir_length", type=int, default=512,
help="length of hrir to be stored. hrir may be right zero padded (if shorter) or hann windowed and truncated (if longer)")
def load_ircam_database(path, hrir_length): def load_ircam_database(path, hrir_length):
...@@ -86,18 +80,38 @@ def is_valid_directory(dir): ...@@ -86,18 +80,38 @@ def is_valid_directory(dir):
raise RuntimeError(f"{dir} must be a directory") raise RuntimeError(f"{dir} must be a directory")
if __name__ == '__main__': def custom_parse_args():
parser = ArgumentParser(add_help=False)
required = parser.add_argument_group('required arguments')
optional = parser.add_argument_group('optional arguments')
# optional arguments
optional.add_argument('--help', action='help', default=SUPPRESS, help='show help and exit')
optional.add_argument('--out_dir', type=str, default="databases", help="output directory")
optional.add_argument('--database', type=str, default="IRCAM", help="name of the database to be generated")
optional.add_argument('--hrir_length', type=int, default=512,
help="length of hrir to be stored. hrir may be right zero padded (if shorter) or hann windowed and truncated (if longer)")
# required arguments
required.add_argument("--in_dir", type=str, help="input directory", required=True)
#check arguments
args = parser.parse_args() args = parser.parse_args()
is_valid_directory(args.in_dir)
is_valid_directory(args.out_dir)
# check args return args
if __name__ == '__main__':
# get args + sanity check
args = custom_parse_args()
# copy args
in_dir = args.in_dir in_dir = args.in_dir
out_dir = args.out_dir out_dir = args.out_dir
hrir_length = args.hrir_length hrir_length = args.hrir_length
database = args.database.upper() database = args.database.upper()
is_valid_directory(in_dir)
is_valid_directory(out_dir)
if not database in ['IRCAM']: if not database in ['IRCAM']:
raise ValueError('unknown dataset. Valid datasets are: {"IRCAM"}') raise ValueError('unknown dataset. Valid datasets are: {"IRCAM"}')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment