taotoolkit 2.0.8__tar.gz → 2.0.9__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.8
3
+ Version: 2.0.9
4
4
  Summary: Tao ToolKit
5
5
  Author-email: taotaoli <taotaoli@asrmicro.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "taotoolkit"
7
- version = "2.0.8"
7
+ version = "2.0.9"
8
8
  description = "Tao ToolKit"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -16,7 +16,6 @@ from .tao_common import (
16
16
  rCmdRealtime,
17
17
  exit,
18
18
  eExit,
19
- iExit,
20
19
  createFolder,
21
20
  fileExist,
22
21
  findFilesBySuffixKeyword,
@@ -43,7 +42,7 @@ from .tao_camDvt import camDvtMain as camDvtMain, printHelp as camDvtHelp, CamDv
43
42
 
44
43
  from .asrVrf import Vrf
45
44
 
46
- __version__ = "2.0.8"
45
+ __version__ = "2.0.9"
47
46
 
48
47
  __all__ = [
49
48
  "debugCtrl",
@@ -63,7 +62,6 @@ __all__ = [
63
62
  "rCmdRealtime",
64
63
  "exit",
65
64
  "eExit",
66
- "iExit",
67
65
  "createFolder",
68
66
  "fileExist",
69
67
  "findFilesBySuffixKeyword",
@@ -126,6 +126,7 @@ def logcatParseArgs(argsList):
126
126
  "-k", "--keywords", metavar="KEYWORD", nargs="*", default=[], help="过滤关键词(空格分隔,不指定则输出全部)"
127
127
  )
128
128
  parser.add_argument("-d", "--device", metavar="SERIAL", default=None, help="指定设备序列号(多设备时使用)")
129
+ parser.add_argument("-c", "--clear", action="store_true", help="抓取前先清空日志缓冲区(adb logcat -c)")
129
130
  parser.add_argument("--no-file", action="store_true", help="只输出到终端,不保存文件")
130
131
  return parser.parse_args(argsList)
131
132
 
@@ -166,11 +167,16 @@ def line_matches(line, keywords):
166
167
  def runLogcat(args):
167
168
  check_adb()
168
169
 
170
+ if args.clear:
171
+ clear_cmd = ["adb"] + (["-s", args.device] if args.device else []) + ["logcat", "-c"]
172
+ subprocess.run(clear_cmd, capture_output=True, text=True, timeout=10)
173
+ logi(f"{EMOJI['ok']} 已清空 logcat 缓冲区")
174
+
169
175
  # 确定日志文件名
170
176
  log_path = None
171
177
  if not args.no_file:
172
178
  if args.file:
173
- log_path = args.file
179
+ log_path = f"{args.file}.log"
174
180
  else:
175
181
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
176
182
  log_path = f"logcat_{timestamp}.log"
@@ -132,18 +132,13 @@ logCallHigh = _create_log_call_func("HIGH", default_callStack=2)
132
132
  logCallErr = _create_log_call_func("ERROR", default_callStack=2)
133
133
 
134
134
 
135
- def exit() -> None:
135
+ def exit() -> NoReturn:
136
136
  sys.exit(1)
137
137
 
138
138
 
139
139
  def eExit(msg: str) -> NoReturn:
140
- loge(msg)
141
- sys.exit(1)
142
-
143
-
144
- def iExit(msg: str) -> NoReturn:
145
- logi(msg)
146
- sys.exit(0)
140
+ logCallErr(msg)
141
+ exit()
147
142
 
148
143
 
149
144
  # ── 命令耗时埋点 ─────────────────────────────────────────
@@ -356,14 +351,16 @@ def refreshWait(msg, times, sleep_s, func, *args):
356
351
  print()
357
352
  return
358
353
  print()
359
- eExit(f"wait for {msg} timeout")
354
+ logCallErr(f"wait for {msg} timeout")
355
+ exit()
360
356
 
361
357
 
362
358
  def checkMsg(msg: str, *keywords: str) -> None:
363
359
  if msg:
364
360
  for kw in keywords:
365
361
  if kw in msg.lower():
366
- eExit(msg)
362
+ logCallErr(msg)
363
+ exit()
367
364
 
368
365
 
369
366
  def parseArgs(argument_string):
@@ -870,8 +870,8 @@ class DevOp:
870
870
 
871
871
  # ── 文件传输 ─────────────────────────────────────────
872
872
 
873
- def pushFile(self, local, target):
874
- out, err = self._adb("push", local, target)
873
+ def pushFile(self, local, target, timeout=10):
874
+ out, err = self._adb("push", local, target, timeout=timeout)
875
875
  logi(out)
876
876
  checkMsg(err, "failed", "device may need remount")
877
877
  if "Read-only" in out:
@@ -21,6 +21,7 @@ from .tao_common import (
21
21
  ErrCode,
22
22
  createFolder,
23
23
  eExit,
24
+ exit,
24
25
  fileExceptionNotFound,
25
26
  fileExceptionillegal,
26
27
  fileExist,
@@ -853,51 +854,75 @@ class asrCamOp(DevOp):
853
854
  self.facing = info.split(",")[3].split("ISP_Preview_")[1]
854
855
  return ret
855
856
 
856
- def pushVrf(self, path, id="rear_primary", renameVrf=False, ignoreTag=None, matchCase=True):
857
+ def pushVrf(self, path, id="rear_primary", renameVrf=False, ignoreTag=None, matchCase=True, incremental=False):
857
858
  # id: rear_primary, front, rear_secondary
859
+ # incremental=True: 用 adb push --sync, 设备上已存在且未修改的 vrf 跳过传输
858
860
  out = ""
859
861
  if not os.path.exists(path):
860
862
  loge(f"{path} not exist")
861
863
  return
862
- rCmd(f"adb -s {self.serial} shell rm vendor/etc/camera/*.vrf", showCmd=True, logLevel="info")
864
+ remoteDir = "/vendor/etc/camera"
865
+ # 非增量推送时先清空设备上的 vrf, 保证只剩本次推送的文件
866
+ if not (incremental and os.path.isdir(path)):
867
+ self._adb_shell(f"rm -f {remoteDir}/*.vrf")
863
868
  if self.soc == "dove":
864
869
  vrfEndName = "_sensor.vrf"
865
- out, _ = rCmd(f"adb -s {self.serial} push {path} vendor/etc/camera/{id}{vrfEndName}", showCmd=True, logLevel="info")
870
+ out, _ = self._adb("push", path, f"{remoteDir}/{id}{vrfEndName}", timeout=600)
866
871
  elif self.soc in ["lark", "larkl", "larkpro"]:
867
872
  if os.path.isfile(path):
868
873
  vrfEndName = "_sensor_0.vrf"
869
- out, _ = rCmd(
870
- f"adb -s {self.serial} push {path} vendor/etc/camera/{id}{vrfEndName}", showCmd=True, logLevel="info"
871
- )
874
+ out, _ = self._adb("push", path, f"{remoteDir}/{id}{vrfEndName}", timeout=600)
872
875
  elif os.path.isdir(path):
873
- index = 0
874
- shortIndex = 0
875
876
  vrfFiles = findFilesWithSuffix(path, ".vrf")
876
877
  if ignoreTag is not None:
877
878
  for tag in ignoreTag:
878
879
  vrfFiles = removeAnyContainStr(tag, vrfFiles, matchCase)
879
- vrfFiles.sort(key=lambda x: x.split("_")[0])
880
+ def vrfSortKey(f):
881
+ name = os.path.split(f)[1]
882
+ m = re.search(r"(\d+)\.vrf$", name)
883
+ num = int(m.group(1)) if m else 0
884
+ # hdr/short 帧单独一组, 排在普通帧之后, 各自从 0 编号
885
+ return ("hdr" in name or "short" in name, num)
886
+
887
+ vrfFiles.sort(key=vrfSortKey)
888
+ logi(f"push vrf to {remoteDir} ...")
889
+ for f in vrfFiles:
890
+ print(f)
891
+ # 先算出 本地文件 -> 设备文件名, 再一次性推送, 避免每个文件建一条 adb 连接
892
+ pairs = []
893
+ index = 0
894
+ shortIndex = 0
880
895
  for vrf in vrfFiles:
881
- if "short" in vrf:
896
+ if "short" in vrf or "hdr" in vrf:
882
897
  target = f"{id}_sensor_hdr_{shortIndex}.vrf"
883
898
  shortIndex += 1
884
899
  else:
885
900
  target = f"{id}_sensor_{index}.vrf"
886
901
  index += 1
887
- if renameVrf:
888
- out, _ = rCmd(
889
- f"adb -s {self.serial} push {vrf} vendor/etc/camera/{target}",
890
- showCmd=True,
891
- showRet=True,
892
- logLevel="info",
893
- )
894
- else:
895
- out, _ = rCmd(
896
- f"adb -s {self.serial} push {vrf} vendor/etc/camera",
897
- showCmd=True,
898
- showRet=True,
899
- logLevel="info",
900
- )
902
+ pairs.append((vrf, target if renameVrf else os.path.split(vrf)[1]))
903
+ if not pairs:
904
+ loge(f"{path} 中没有 .vrf 文件")
905
+ return
906
+
907
+ if incremental:
908
+ # 只删本次不会再生成的 vrf, 未改动的文件交给 --sync 跳过
909
+ exist = self.shell(f"ls {remoteDir}/*.vrf 2>/dev/null").split()
910
+ keep = {target for _, target in pairs}
911
+ stale = [f for f in exist if os.path.split(f)[1] not in keep]
912
+ if stale:
913
+ self._adb_shell("rm -f " + " ".join(stale))
914
+
915
+ pushArgs = ["push"] + (["--sync"] if incremental else [])
916
+ pushArgs += [src for src, _ in pairs] + [f"{remoteDir}/"]
917
+ out, _ = self._adb(*pushArgs, timeout=600)
918
+ # 需要改名时在设备端同分区 mv(瞬间完成), 避免为每个文件再多推一次
919
+ renames = [
920
+ (os.path.split(src)[1], target)
921
+ for src, target in pairs
922
+ if os.path.split(src)[1] != target
923
+ ]
924
+ if renames:
925
+ self._adb_shell(" && ".join(f"mv {remoteDir}/{s} {remoteDir}/{t}" for s, t in renames))
901
926
 
902
927
  if "Read-only" in out:
903
928
  eExit("device is Read-only, may need remount")
@@ -905,15 +930,44 @@ class asrCamOp(DevOp):
905
930
  sleep(2)
906
931
  self.tuningGetModuleGroup()
907
932
 
933
+ @staticmethod
934
+ def _tuningTargetName(fullName):
935
+ name = os.path.split(fullName)[1]
936
+ return name.split("asr_")[1] if "asr_" in fullName else name
937
+
908
938
  def pushTuningFile(self, fullName):
909
939
  if not os.path.exists(fullName):
910
940
  loge(f"{fullName} not exist")
911
941
  return
912
- if "asr_" in fullName:
913
- targetFile = os.path.split(fullName)[1].split("asr_")[1]
942
+ targetFile = self._tuningTargetName(fullName)
943
+ self.pushFile(fullName, f"/vendor/etc/camera/tuning_files/{targetFile}")
944
+
945
+ def pushTuningFiles(self, files):
946
+ # 一次 adb 调用推多个 .data: 小文件的耗时几乎全在 adb 连接/进程开销上
947
+ files = [f for f in files if os.path.isfile(f)]
948
+ remoteDir = "/vendor/etc/camera/tuning_files"
949
+ if not files:
950
+ loge("没有可push的tuning文件")
951
+ return
914
952
  else:
915
- targetFile = os.path.split(fullName)[1]
916
- self.pushFile(fullName, f"vendor/etc/camera/tuning_files/{targetFile}")
953
+ logi(f"push tuning data to {remoteDir}...")
954
+ for f in files:
955
+ print(f)
956
+
957
+ self._adb_shell(f"mkdir -p {remoteDir}")
958
+ pairs = [(f, self._tuningTargetName(f)) for f in files]
959
+ out, _ = self._adb("push", *files, f"{remoteDir}/", timeout=600)
960
+ logi(out.strip().splitlines()[-1] if out.strip() else "")
961
+ # 去掉 asr_ 前缀的文件在设备端同分区 mv 改名, 不再单独传一次
962
+ renames = [
963
+ (os.path.split(src)[1], target)
964
+ for src, target in pairs
965
+ if os.path.split(src)[1] != target
966
+ ]
967
+ if renames:
968
+ self._adb_shell(" && ".join(f"mv {remoteDir}/{s} {remoteDir}/{t}" for s, t in renames))
969
+ if "Read-only" in out:
970
+ eExit("device is Read-only, may need remount")
917
971
 
918
972
  def saveTuningFile(self, outPath, file, paramlist, delInfo):
919
973
  module = "m" + paramlist[0] + "_g" + paramlist[2]
@@ -1231,19 +1285,6 @@ def CLI_tuningRemoveInfo(argsList):
1231
1285
  loge(f"{inFile} is not a valid file or directory")
1232
1286
 
1233
1287
 
1234
- # def CLI_pushVrf(args):
1235
- # argsDict = {}
1236
- # if args:
1237
- # argsDict = parseArgs(" ".join(args))
1238
- # idx = argsDict.get("i", "0")
1239
- # rename = int(argsDict.get("r", 0))
1240
- # dev = asrCamOp()
1241
- # if os.path.exists(args[1]):
1242
- # dev.pushVrf(args[1], idx, rename)
1243
- # else:
1244
- # loge(f"cmd error, psvrf name.vrf/path [i=0,1,2]cameraId [r=0,1]renameVrf")
1245
-
1246
-
1247
1288
  def CLI_pushVrf(argsList):
1248
1289
  parser = argparse.ArgumentParser(prog="pushvrf", description="push vrf到设备")
1249
1290
  parser.add_argument("posPath", nargs="?", default=None, help="vrf文件名或路径, 可直接输入(psvrf xxx.vrf)")
@@ -1262,19 +1303,24 @@ def CLI_pushVrf(argsList):
1262
1303
  )
1263
1304
  parser.add_argument("--matchcase", action="store_true", dest="matchcase", help="是否区分tag大小写")
1264
1305
  parser.set_defaults(matchcase=False)
1306
+ parser.add_argument("--sync", action="store_true", dest="sync", help="增量推送: 设备上已存在且未修改的vrf跳过传输")
1307
+ parser.set_defaults(sync=False)
1265
1308
  args = parser.parse_args(argsList)
1266
1309
  if args.path is None:
1267
1310
  args.path = args.posPath
1268
1311
  if args.path is None:
1269
1312
  parser.error("至少需要指定vrf文件名或路径")
1270
1313
 
1271
- logi(f"psvrf {args.path} indxe={args.index}, rename={args.rename}, ignoreTag={args.tag}, matchcase={args.matchcase}")
1314
+ logi(
1315
+ f"psvrf {args.path} indxe={args.index}, rename={args.rename}, ignoreTag={args.tag}, "
1316
+ f"matchcase={args.matchcase}, sync={args.sync}"
1317
+ )
1272
1318
 
1273
- dev = asrCamOp()
1274
1319
  if os.path.exists(args.path):
1275
- dev.pushVrf(args.path, args.index, args.rename, args.tag, args.matchcase)
1320
+ dev = asrCamOp()
1321
+ dev.pushVrf(args.path, args.index, args.rename, args.tag, args.matchcase, args.sync)
1276
1322
  else:
1277
- loge(f"cmd error, psvrf name.vrf/path [i=0,1,2]cameraId [r=0,1]renameVrf")
1323
+ loge(f"{args.path} not exist")
1278
1324
 
1279
1325
 
1280
1326
  def CLI_capVrf(argsList):
@@ -1363,10 +1409,11 @@ def CLI_pushTuning(argsList):
1363
1409
  if os.path.isfile(inFile):
1364
1410
  asrCam.pushTuningFile(inFile)
1365
1411
  elif os.path.isdir(inFile):
1366
- for f in os.listdir(inFile):
1367
- if f.endswith(".data"):
1368
- raw_name = os.path.join(inFile, f)
1369
- asrCam.pushTuningFile(raw_name)
1412
+ dataFiles = sorted(os.path.join(inFile, f) for f in os.listdir(inFile) if f.endswith(".data"))
1413
+ if dataFiles:
1414
+ asrCam.pushTuningFiles(dataFiles)
1415
+ else:
1416
+ loge(f"{inFile} 中没有 .data 文件")
1370
1417
  else:
1371
1418
  loge(f"{inFile} is not a valid file or directory")
1372
1419
 
@@ -1386,7 +1433,7 @@ def CLI_tuning2c(argsList):
1386
1433
  sensorName = args.prefix
1387
1434
  if args.prefix is None and os.path.isdir(inFile):
1388
1435
  suffix = "_isp_preview.h"
1389
- for file in Path(inFile).rglob(f"*{suffix}"):
1436
+ for file in Path(inFile).glob(f"*{suffix}"):
1390
1437
  # file.name 是完整文件名,去掉后缀部分就是前面的字符串
1391
1438
  sensorName = file.name[:-len(suffix)]
1392
1439
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taotoolkit
3
- Version: 2.0.8
3
+ Version: 2.0.9
4
4
  Summary: Tao ToolKit
5
5
  Author-email: taotaoli <taotaoli@asrmicro.com>
6
6
  License-Expression: MIT
File without changes
File without changes