From 8370c8fba390ffb98441b0078fcd442e7c314f94 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Wed, 11 Apr 2018 10:48:49 +0100 Subject: [PATCH] target: timestamp for capture_screen Add an option to format an ISO8601 timestamp into the screenshot file name. --- devlib/platform/gem5.py | 5 +++++ devlib/target.py | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/devlib/platform/gem5.py b/devlib/platform/gem5.py index f70b980..0a6cf73 100644 --- a/devlib/platform/gem5.py +++ b/devlib/platform/gem5.py @@ -242,6 +242,11 @@ class Gem5SimulationPlatform(Platform): if '.bmp' in f: screen_caps.append(f) + if '{ts}' in filepath: + cmd = '{} date -u -Iseconds' + ts = self.target.execute(cmd.format(self.target.busybox)).strip() + filepath = filepath.format(ts=ts) + successful_capture = False if len(screen_caps) == 1: # Bail out if we do not have image, and resort to the slower, built diff --git a/devlib/target.py b/devlib/target.py index 4e018c7..bdcda4c 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -905,7 +905,9 @@ class LinuxTarget(Target): try: tmpfile = self.tempfile() - self.execute('DISPLAY=:0.0 scrot {}'.format(tmpfile)) + cmd = 'DISPLAY=:0.0 scrot {} && {} date -u -Iseconds' + ts = self.execute(cmd.format(tmpfile, self.busybox)).strip() + filepath = filepath.format(ts=ts) self.pull(tmpfile, filepath) self.remove(tmpfile) except TargetError as e: @@ -1144,7 +1146,9 @@ class AndroidTarget(Target): def capture_screen(self, filepath): on_device_file = self.path.join(self.working_directory, 'screen_capture.png') - self.execute('screencap -p {}'.format(on_device_file)) + cmd = 'screencap -p {} && {} date -u -Iseconds' + ts = self.execute(cmd.format(on_device_file, self.busybox)).strip() + filepath = filepath.format(ts=ts) self.pull(on_device_file, filepath) self.remove(on_device_file)