Kea2-python 0.0.1b2__py3-none-any.whl → 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of Kea2-python might be problematic. Click here for more details.

kea2/resultSyncer.py ADDED
@@ -0,0 +1,56 @@
1
+ import threading
2
+ from .adbUtils import adb_shell, pull_file
3
+ from .utils import getLogger
4
+
5
+ logger = getLogger(__name__)
6
+
7
+
8
+ class ResultSyncer:
9
+
10
+ def __init__(self, device_output_dir, output_dir):
11
+ self.device_output_dir = device_output_dir
12
+ self.output_dir = output_dir
13
+ self.running = False
14
+ self.thread = None
15
+ self.sync_event = threading.Event()
16
+
17
+ def run(self):
18
+ """Start a background thread to sync device data when triggered"""
19
+ self.running = True
20
+ self.thread = threading.Thread(target=self._sync_thread, daemon=True)
21
+ self.thread.start()
22
+
23
+ def _sync_thread(self):
24
+ """Thread function that waits for sync event and then syncs data"""
25
+ while self.running:
26
+ # Wait for sync event with a timeout to periodically check if still running
27
+ if self.sync_event.wait(timeout=3):
28
+ self._sync_device_data()
29
+ self.sync_event.clear()
30
+
31
+ def close(self):
32
+ self.running = False
33
+ self.sync_event.set()
34
+ if self.thread and self.thread.is_alive():
35
+ self.thread.join(timeout=10)
36
+ self._sync_device_data()
37
+ try:
38
+ logger.debug(f"Removing device output directory: {self.device_output_dir}")
39
+ remove_device_dir = ["rm", "-rf", self.device_output_dir]
40
+ adb_shell(remove_device_dir)
41
+ except Exception as e:
42
+ logger.error(f"Error removing device output directory: {e}", flush=True)
43
+
44
+ def _sync_device_data(self):
45
+ """
46
+ Sync the device data to the local directory.
47
+ """
48
+ try:
49
+ logger.debug("Syncing data")
50
+
51
+ pull_file(self.device_output_dir, str(self.output_dir))
52
+
53
+ remove_pulled_screenshots = ["find", self.device_output_dir, "-name", "\"*.png\"", "-delete"]
54
+ adb_shell(remove_pulled_screenshots)
55
+ except Exception as e:
56
+ logger.error(f"Error in data sync: {e}", flush=True)