Skip to content
Snippets Groups Projects
Commit e71078b3 authored by ferrari's avatar ferrari
Browse files

Add input() style option parsing

parent 598683ab
No related branches found
No related tags found
No related merge requests found
......@@ -573,7 +573,6 @@ def reset(callback, in_path, channel, low=2e3, high=20e3):
callback.reset(song, sr, song_resample)
def main(args):
if args.out == '':
outpath = args.input.rsplit('.', 1)[0] + '.pred.h5'
......@@ -590,12 +589,42 @@ def main(args):
if __name__ == '__main__':
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
class ArgumentParser(argparse.ArgumentParser):
def error(self, message):
if message.startswith('the following arguments are required:'):
raise ValueError()
super(ArgumentParser, self).error(message)
parser = ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("input", type=str, help="Input file")
parser.add_argument("--out", type=str, default='', help="Output file. Default to the input_path'.pred.h5'")
parser.add_argument("--channel", type=int, default=0, help="Sound channel to be analysed. Indices start from 0.")
parser.add_argument("--erase", action='store_true', help="If out file exist and this option is not given,"
" the computation will be halted")
try:
args = parser.parse_args()
except ValueError as e:
print(f'Error while parsing the command line arguments: {e}')
def ask(string):
y = {'y', 'yes', 'o', 'oui'}
a = {'y', 'yes', 'o', 'oui', 'n', 'no', 'non'}
while True:
ans = input(string + ' [y/n] ').lower()
if ans in a:
return ans in y
if not ask('Do you want to manually specify them?'):
sys.exit(2) # exit code of invalid argparse
class VirtualArgParse(object):
def __init__(self):
self.input = input("What is the input file path? ")
self.out = input("What is the out file path? (Leave empty for default)")
self.channel = int(input("Which channel do you want to use starting from 0? "))
self.erase = ask("Do you want to erase the out file if it already exist?")
args = VirtualArgParse()
sys.exit(main(args))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment