feat(python): use DebugLinkRecordScreen.refresh_index when restarting emulator

During each restart, Emulator will transfer the original screen-recording directory
to the new emulator/client and will change the refresh_index so that older screenshots
are not being overwritten by new ones.

[no changelog]
pull/2951/head
grdddj 1 year ago committed by Jiří Musil
parent 0381faffb1
commit abeb34454c

@ -82,6 +82,9 @@ class Emulator:
self.auto_interact = auto_interact self.auto_interact = auto_interact
self.extra_args = list(extra_args) self.extra_args = list(extra_args)
# To save all screenshots properly in one directory between restarts
self.restart_amount = 0
@property @property
def client(self) -> TrezorClientDebugLink: def client(self) -> TrezorClientDebugLink:
"""So that type-checkers do not see `client` as `Optional`. """So that type-checkers do not see `client` as `Optional`.
@ -112,7 +115,7 @@ class Emulator:
if transport._ping(): if transport._ping():
break break
if self.process.poll() is not None: if self.process.poll() is not None:
raise RuntimeError("Emulator proces died") raise RuntimeError("Emulator process died")
elapsed = time.monotonic() - start elapsed = time.monotonic() - start
if elapsed >= timeout: if elapsed >= timeout:
@ -200,8 +203,15 @@ class Emulator:
self.process = None self.process = None
def restart(self) -> None: def restart(self) -> None:
# preserving the recording directory between restarts
self.restart_amount += 1
prev_screenshot_dir = self.client.debug.screenshot_recording_dir
self.stop() self.stop()
self.start() self.start()
if prev_screenshot_dir:
self.client.debug.start_recording(
prev_screenshot_dir, refresh_index=self.restart_amount
)
def __enter__(self) -> "Emulator": def __enter__(self) -> "Emulator":
return self return self

@ -195,6 +195,9 @@ class DebugLink:
# To be set by TrezorClientDebugLink (is not known during creation time) # To be set by TrezorClientDebugLink (is not known during creation time)
self.model: Optional[str] = None self.model: Optional[str] = None
# Where screenshots are being saved
self.screenshot_recording_dir: Optional[str] = None
# For T1 screenshotting functionality in DebugUI # For T1 screenshotting functionality in DebugUI
self.t1_take_screenshots = False self.t1_take_screenshots = False
self.t1_screenshot_directory: Optional[Path] = None self.t1_screenshot_directory: Optional[Path] = None
@ -411,16 +414,24 @@ class DebugLink:
def reseed(self, value: int) -> protobuf.MessageType: def reseed(self, value: int) -> protobuf.MessageType:
return self._call(messages.DebugLinkReseedRandom(value=value)) return self._call(messages.DebugLinkReseedRandom(value=value))
def start_recording(self, directory: str) -> None: def start_recording(
self, directory: str, refresh_index: Optional[int] = None
) -> None:
self.screenshot_recording_dir = directory
# Different recording logic between TT and T1 # Different recording logic between TT and T1
if self.model == "T": if self.model == "T":
self._call(messages.DebugLinkRecordScreen(target_directory=directory)) self._call(
messages.DebugLinkRecordScreen(
target_directory=directory, refresh_index=refresh_index
)
)
else: else:
self.t1_screenshot_directory = Path(directory) self.t1_screenshot_directory = Path(directory)
self.t1_screenshot_counter = 0 self.t1_screenshot_counter = 0
self.t1_take_screenshots = True self.t1_take_screenshots = True
def stop_recording(self) -> None: def stop_recording(self) -> None:
self.screenshot_recording_dir = None
# Different recording logic between TT and T1 # Different recording logic between TT and T1
if self.model == "T": if self.model == "T":
self._call(messages.DebugLinkRecordScreen(target_directory=None)) self._call(messages.DebugLinkRecordScreen(target_directory=None))

Loading…
Cancel
Save