taotoolkit 2.0.3__tar.gz → 2.0.4__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taotoolkit
3
- Version: 2.0.3
3
+ Version: 2.0.4
4
4
  Summary: Tao ToolKit
5
5
  Author-email: taotaoli <taotaoli@asrmicro.com>
6
6
  License-Expression: MIT
@@ -19,7 +19,7 @@ Requires-Dist: beautifulsoup4>=4.10.0
19
19
  Requires-Dist: pyyaml>=6.0.3
20
20
  Requires-Dist: pywinpty>=3.0.5; platform_system == "Windows"
21
21
  Provides-Extra: uiautomator
22
- Requires-Dist: uiautomator2>=2.0.3; extra == "uiautomator"
22
+ Requires-Dist: uiautomator2>=2.0.4; extra == "uiautomator"
23
23
 
24
24
  # TAO - Toolkit
25
25
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "taotoolkit"
7
- version = "2.0.3"
7
+ version = "2.0.4"
8
8
  description = "Tao ToolKit"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -29,5 +29,5 @@ dependencies = [
29
29
 
30
30
  [project.optional-dependencies]
31
31
  uiautomator = [
32
- "uiautomator2>=2.0.3",
32
+ "uiautomator2>=2.0.4",
33
33
  ]
@@ -43,7 +43,7 @@ from .tao_camDvt import camDvtMain as camDvtMain, printHelp as camDvtHelp, CamDv
43
43
 
44
44
  from .asrVrf import Vrf
45
45
 
46
- __version__ = "2.0.3"
46
+ __version__ = "2.0.4"
47
47
 
48
48
  __all__ = [
49
49
  "debugCtrl",
@@ -47,6 +47,8 @@ from .tao_common import (
47
47
 
48
48
  CACHE_FILE = os.path.join(os.path.dirname(__file__), ".dev_cache.json")
49
49
  CACHE_TTL = 3600
50
+ # 匹配 "SERIAL\tdevice ..." 行;unauthorized/offline 不算可用设备
51
+ DEVICE_LINE_RE = re.compile(r"^\S+\s+device\b", re.MULTILINE)
50
52
 
51
53
 
52
54
  def _load_cache():
@@ -145,6 +147,7 @@ class DevOp:
145
147
  logd(f"serial = {serial} needroot ={needRoot}")
146
148
 
147
149
  self.adb = adb_path
150
+ self.serial = serial
148
151
  self._displays: Optional[List[DisplayInfo]] = None
149
152
  self.curScreenW = 0
150
153
  self.curScreenH = 0
@@ -159,8 +162,8 @@ class DevOp:
159
162
  self.soc = None
160
163
  self.chipId = None
161
164
 
162
- # 检查设备是否连接
163
- out, _ = pCmd("adb devices -l", waitDone=True, timeOut=5, logLevel="debug")
165
+ # 检查设备是否连接(adb server 冷启动较慢,首次易超时)
166
+ out = self._probeDevices()
164
167
  cache = _load_cache()
165
168
 
166
169
  # 判断缓存是否命中
@@ -243,6 +246,30 @@ class DevOp:
243
246
  except FileNotFoundError:
244
247
  return "", "adb not found in PATH"
245
248
 
249
+ def _probeDevices(self, timeout: int = 10) -> str:
250
+ """探测已连接设备。adb server 冷启动时,首次调用可能超时,
251
+ 也可能 server 已返回但 USB 设备尚未枚举完成(只返回表头),
252
+ 因此这里显式等待设备出现,避免第一次执行直接失败。"""
253
+ out, err = self._adb("devices", "-l", timeout=timeout)
254
+ if DEVICE_LINE_RE.search(out) or "unauthorized" in out or "offline" in out:
255
+ return out
256
+
257
+ # 冷启动:先确保 server 就绪,再等待设备枚举
258
+ logw("未发现设备,启动 adb server 并等待设备枚举")
259
+ try:
260
+ subprocess.run([self.adb, "start-server"], capture_output=True, timeout=30)
261
+ except (subprocess.TimeoutExpired, OSError) as e:
262
+ logw(f"adb start-server 失败: {e}")
263
+
264
+ deadline = time.monotonic() + timeout
265
+ while time.monotonic() < deadline:
266
+ time.sleep(0.5)
267
+ out, err = self._adb("devices", "-l", timeout=5)
268
+ if DEVICE_LINE_RE.search(out) or "unauthorized" in out or "offline" in out:
269
+ return out
270
+ loge(f"adb devices -l 未发现可用设备: {err}")
271
+ return out
272
+
246
273
  def _adb_shell(self, shell_cmd: str, timeout: int = 10) -> Tuple[str, str]:
247
274
  return self._adb("shell", shell_cmd, timeout=timeout)
248
275
 
@@ -273,7 +300,7 @@ class DevOp:
273
300
 
274
301
  def getConnectedDevices(self):
275
302
  try:
276
- out, error = pCmd("adb devices -l", showCmd=True, waitDone=True, timeOut=6, logLevel="debug")
303
+ out, error = self._adb("devices", "-l", timeout=5)
277
304
  if "offline" in out or "unauthorized" in out:
278
305
  tmp = out.split("\n")[1].split(" ")[0]
279
306
  eExit(f"{tmp} devices offline or unauthorized")
@@ -875,7 +875,7 @@ class asrCamOp(DevOp):
875
875
  )
876
876
  else:
877
877
  out, _ = rCmd(
878
- f"adb -s {self.serial} push {vrf} vendor/etc/camera/{vrf}",
878
+ f"adb -s {self.serial} push {vrf} vendor/etc/camera",
879
879
  showCmd=True,
880
880
  showRet=True,
881
881
  logLevel="info",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taotoolkit
3
- Version: 2.0.3
3
+ Version: 2.0.4
4
4
  Summary: Tao ToolKit
5
5
  Author-email: taotaoli <taotaoli@asrmicro.com>
6
6
  License-Expression: MIT
@@ -19,7 +19,7 @@ Requires-Dist: beautifulsoup4>=4.10.0
19
19
  Requires-Dist: pyyaml>=6.0.3
20
20
  Requires-Dist: pywinpty>=3.0.5; platform_system == "Windows"
21
21
  Provides-Extra: uiautomator
22
- Requires-Dist: uiautomator2>=2.0.3; extra == "uiautomator"
22
+ Requires-Dist: uiautomator2>=2.0.4; extra == "uiautomator"
23
23
 
24
24
  # TAO - Toolkit
25
25
 
@@ -14,4 +14,4 @@ pyyaml>=6.0.3
14
14
  pywinpty>=3.0.5
15
15
 
16
16
  [uiautomator]
17
- uiautomator2>=2.0.3
17
+ uiautomator2>=2.0.4
File without changes
File without changes