Skip to content

Commit a860180

Browse files
committed
options: change timeout value format
Change the way we handle timeout format, introducing <value> + suffix that can be: - s: seconds - m: minutes - h: hours - d: days For example, '30m' means '30 minutes'. If no suffix is given, we threat the input value in seconds. Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
1 parent 1cbb46f commit a860180

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

libkirk/main.py

+31-4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,33 @@ def _iterate_config(value: str) -> int:
149149
return ret
150150

151151

152+
def _time_config(data: str) -> int:
153+
"""
154+
Return the time in seconds from '30s', '4m', '5h', '20d' format.
155+
If no suffix is specified, value is considered in seconds.
156+
"""
157+
indata = data.strip()
158+
159+
match = re.search(r'^(?P<value>\d+)\s*(?P<suffix>[smhd]?)$', indata)
160+
if not match:
161+
raise argparse.ArgumentTypeError(f"Incorrect time format '{indata}'")
162+
163+
value = int(match.group('value'))
164+
suffix = match.group('suffix')
165+
166+
if not suffix or suffix == 's':
167+
return value
168+
169+
if suffix == 'm':
170+
value *= 60
171+
elif suffix == 'h':
172+
value *= 3600
173+
elif suffix == 'd':
174+
value *= 3600 * 24
175+
176+
return value
177+
178+
152179
def _discover_sut(path: str) -> None:
153180
"""
154181
Discover new SUT implementations.
@@ -428,14 +455,14 @@ def run(cmd_args: list = None) -> None:
428455
parser.add_argument(
429456
"--suite-timeout",
430457
"-T",
431-
type=int,
432-
default=3600,
458+
type=_time_config,
459+
default="1h",
433460
help="Timeout before stopping the suite")
434461
parser.add_argument(
435462
"--exec-timeout",
436463
"-t",
437-
type=int,
438-
default=3600,
464+
type=_time_config,
465+
default="1h",
439466
help="Timeout before stopping a single execution")
440467
parser.add_argument(
441468
"--suite-iterate",

0 commit comments

Comments
 (0)