tools/replay: Enter quits if there are no events

If we have no events in any of the recorded devices, state that this is the
case and make Enter simply quit instead of a pointless while loop.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2021-02-23 10:53:31 +10:00
parent f30342644a
commit ff87151764

View file

@ -26,6 +26,7 @@
import os
import sys
import time
import math
import multiprocessing
import argparse
from pathlib import Path
@ -218,8 +219,7 @@ def first_timestamp(device):
except YamlException:
pass
import math
return math.inf
return None
def wrap(func, *args):
@ -232,9 +232,12 @@ def wrap(func, *args):
def loop(args, recording):
devices = fetch(recording, "devices")
first_timestamps = tuple(
filter(lambda x: x is not None, [first_timestamp(d) for d in devices])
)
# All devices need to start replaying at the same time, so let's find
# the very first event and offset everything by that timestamp.
toffset = min([first_timestamp(d) for d in devices])
toffset = min(first_timestamps or [math.inf])
for idx, d in enumerate(devices):
uinput = create(d)
@ -243,6 +246,10 @@ def loop(args, recording):
d["__index"] = idx
d["__first_event_offset"] = toffset
if not first_timestamps:
input("No events in recording. Hit enter to quit")
return
while True:
input("Hit enter to start replaying")