sdev 0.7.11__tar.gz → 0.7.12__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: sdev
3
- Version: 0.7.11
3
+ Version: 0.7.12
4
4
  Summary: 串口控制器工具包
5
5
  Home-page: https://github.com/klrc/sdev
6
6
  Author: klrc
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sdev"
7
- version = "0.7.11"
7
+ version = "0.7.12"
8
8
  description = "串口控制器工具包"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -493,97 +493,97 @@ def _handle_list(args: argparse.Namespace) -> int:
493
493
  scan_local = scope != "remote"
494
494
  scan_remote = scope != "local"
495
495
 
496
- # 本地与远程扫描分别封装为任务,由 spinner 展示进度。
497
- def _scan_local_task(ports: List[str]) -> List[Dict[str, Any]]:
498
- entries: List[Dict[str, Any]] = []
499
- if not ports:
500
- return entries
501
-
502
- def _check_one(port: str) -> Tuple[str, Dict[str, Any]]:
503
- r = check_port_alive_nonblock(port, baudrate=115200, timeout=1.5)
504
- return (port, r)
505
-
506
- alive_ports: List[str] = []
507
- results: List[Tuple[str, Dict[str, Any]]] = []
508
- fast_exit = False
509
- ex = ThreadPoolExecutor(max_workers=max(len(ports), 1))
510
- try:
511
- futs = {ex.submit(_check_one, p): p for p in ports}
512
- if fast:
513
- for fut in as_completed(futs):
514
- port, r = fut.result()
515
- results.append((port, r))
516
- if r.get("available"):
517
- fast_exit = True
518
- alive_ports = [port]
519
- break
520
- else:
521
- for fut in as_completed(futs):
522
- results.append(fut.result())
523
- results.sort(key=lambda x: x[0])
524
- for port, r in results:
525
- if r.get("available"):
526
- alive_ports.append(port)
527
- finally:
528
- ex.shutdown(wait=not fast_exit)
529
-
530
- def _model_one(port: str) -> Tuple[str, str]:
496
+ # 本地与远程扫描分别封装为任务,由 spinner 展示进度。
497
+ def _scan_local_task(ports: List[str]) -> List[Dict[str, Any]]:
498
+ entries: List[Dict[str, Any]] = []
499
+ if not ports:
500
+ return entries
501
+
502
+ def _check_one(port: str) -> Tuple[str, Dict[str, Any]]:
503
+ r = check_port_alive_nonblock(port, baudrate=115200, timeout=1.5)
504
+ return (port, r)
505
+
506
+ alive_ports: List[str] = []
507
+ results: List[Tuple[str, Dict[str, Any]]] = []
508
+ fast_exit = False
509
+ ex = ThreadPoolExecutor(max_workers=max(len(ports), 1))
531
510
  try:
532
- with SerialNotebook(device=port, baudrate=115200) as nb:
533
- return (port, nb.get_model_type(timeout=2.0, verbose=False) or "unknown")
534
- except Exception as e:
535
- return (port, f"error: {e}")
536
-
537
- if alive_ports:
538
- model_results: List[Tuple[str, str]] = []
539
- with ThreadPoolExecutor(max_workers=max(len(alive_ports), 1)) as ex2:
540
- futs = {ex2.submit(_model_one, p): p for p in alive_ports}
541
- for fut in as_completed(futs):
542
- model_results.append(fut.result())
543
- model_results.sort(key=lambda x: x[0])
544
- for port, device_type in model_results:
545
- entries.append({
546
- "host": "localhost",
547
- "device": port,
548
- "device_id": _device_id("localhost", port),
549
- "device_type": device_type if not device_type.startswith("error:") else "unknown",
550
- "last_update": now,
551
- })
552
- return entries
553
-
554
- def _scan_remote_task() -> List[Dict[str, Any]]:
555
- entries: List[Dict[str, Any]] = []
556
- hosts = get_remote_hosts()
557
- # print(f"[debug] remote hosts found by discovery: {hosts}")
558
- if not hosts:
559
- return entries
560
- for host, service_port in hosts:
561
- # print(f"[debug] fetching boards from {host}:{service_port}...")
562
- boards = fetch_boards_from_host(host, service_port, timeout=10.0)
563
- # print(f"[debug] host {host} returned {len(boards)} boards")
564
- for b in boards:
565
- if not b.get("available"):
566
- continue
567
- serial_dev = (b.get("device") or b.get("port") or "").strip()
568
- if not serial_dev:
569
- continue
570
- baud = int(b.get("baudrate") or 115200)
571
- device_type = "unknown"
511
+ futs = {ex.submit(_check_one, p): p for p in ports}
512
+ if fast:
513
+ for fut in as_completed(futs):
514
+ port, r = fut.result()
515
+ results.append((port, r))
516
+ if r.get("available"):
517
+ fast_exit = True
518
+ alive_ports = [port]
519
+ break
520
+ else:
521
+ for fut in as_completed(futs):
522
+ results.append(fut.result())
523
+ results.sort(key=lambda x: x[0])
524
+ for port, r in results:
525
+ if r.get("available"):
526
+ alive_ports.append(port)
527
+ finally:
528
+ ex.shutdown(wait=not fast_exit)
529
+
530
+ def _model_one(port: str) -> Tuple[str, str]:
572
531
  try:
573
- with SerialNotebook(device=serial_dev, baudrate=baud, host=host, port=service_port) as nb:
574
- device_type = nb.get_model_type(timeout=3.0, verbose=False) or "unknown"
532
+ with SerialNotebook(device=port, baudrate=115200) as nb:
533
+ return (port, nb.get_model_type(timeout=2.0, verbose=False) or "unknown")
575
534
  except Exception as e:
576
- # 如果报错,说明连接或者握手阶段就出问题了
577
- # print(f"[debug] failed to get model type from {host}:{serial_dev}: {e}")
535
+ return (port, f"error: {e}")
536
+
537
+ if alive_ports:
538
+ model_results: List[Tuple[str, str]] = []
539
+ with ThreadPoolExecutor(max_workers=max(len(alive_ports), 1)) as ex2:
540
+ futs = {ex2.submit(_model_one, p): p for p in alive_ports}
541
+ for fut in as_completed(futs):
542
+ model_results.append(fut.result())
543
+ model_results.sort(key=lambda x: x[0])
544
+ for port, device_type in model_results:
545
+ entries.append({
546
+ "host": "localhost",
547
+ "device": port,
548
+ "device_id": _device_id("localhost", port),
549
+ "device_type": device_type if not device_type.startswith("error:") else "unknown",
550
+ "last_update": now,
551
+ })
552
+ return entries
553
+
554
+ def _scan_remote_task() -> List[Dict[str, Any]]:
555
+ entries: List[Dict[str, Any]] = []
556
+ hosts = get_remote_hosts()
557
+ # print(f"[debug] remote hosts found by discovery: {hosts}")
558
+ if not hosts:
559
+ return entries
560
+ for host, service_port in hosts:
561
+ # print(f"[debug] fetching boards from {host}:{service_port}...")
562
+ boards = fetch_boards_from_host(host, service_port, timeout=10.0)
563
+ # print(f"[debug] host {host} returned {len(boards)} boards")
564
+ for b in boards:
565
+ if not b.get("available"):
566
+ continue
567
+ serial_dev = (b.get("device") or b.get("port") or "").strip()
568
+ if not serial_dev:
569
+ continue
570
+ baud = int(b.get("baudrate") or 115200)
578
571
  device_type = "unknown"
579
- entries.append({
580
- "host": host,
581
- "device": serial_dev,
582
- "device_id": _device_id(host, serial_dev),
583
- "device_type": device_type if not device_type.startswith("error:") else "unknown",
584
- "last_update": now,
585
- })
586
- return entries
572
+ try:
573
+ with SerialNotebook(device=serial_dev, baudrate=baud, host=host, port=service_port) as nb:
574
+ device_type = nb.get_model_type(timeout=3.0, verbose=False) or "unknown"
575
+ except Exception as e:
576
+ # 如果报错,说明连接或者握手阶段就出问题了
577
+ # print(f"[debug] failed to get model type from {host}:{serial_dev}: {e}")
578
+ device_type = "unknown"
579
+ entries.append({
580
+ "host": host,
581
+ "device": serial_dev,
582
+ "device_id": _device_id(host, serial_dev),
583
+ "device_type": device_type if not device_type.startswith("error:") else "unknown",
584
+ "last_update": now,
585
+ })
586
+ return entries
587
587
 
588
588
  specs: List[Tuple[str, Any]] = []
589
589
  local_entries: List[Dict[str, Any]] = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdev
3
- Version: 0.7.11
3
+ Version: 0.7.12
4
4
  Summary: 串口控制器工具包
5
5
  Home-page: https://github.com/klrc/sdev
6
6
  Author: klrc
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="sdev",
8
- version="0.7.11",
8
+ version="0.7.12",
9
9
  author="klrc",
10
10
  author_email="144069824@qq.com",
11
11
  description="串口控制器工具包",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes