def match_time_unit(val):
'''match some val against time shortcut inputs '''
match = re.match("^(\d+(\.\d+)?)([m|h]?)$", val)
if match:
digit = float(match.group(1))
unit = match.group(3)
if not unit:
return digit
elif unit == 'm':
return digit*60
else:
return digit*60*60
else:
raise argparse.ArgumentTypeError("Duration should be passed in the following format: \n"
"-d 100 : in sec \n"
"-d 10m : in min \n"
"-d 1h : in hours")
评论列表
文章目录