sdev 0.7.4__tar.gz → 0.7.5__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.4
3
+ Version: 0.7.5
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.4"
7
+ version = "0.7.5"
8
8
  description = "串口控制器工具包"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -350,11 +350,13 @@ def _handle_run(args: argparse.Namespace) -> int:
350
350
  response_timeout=response_timeout,
351
351
  stream=False,
352
352
  verbose=False,
353
+ keep_type=True,
353
354
  )
354
355
  for line in ret:
355
356
  if line.kind == 'body' or line.kind == 'error':
356
357
  sys.stdout.write(line.text)
357
358
  sys.stdout.flush()
359
+ print()
358
360
  except KeyboardInterrupt:
359
361
  # 捕获本地 Ctrl-C:向开发板发送一次中断信号(Ctrl-C),尽量中断远端前台命令。
360
362
  nb.send_interrupt()
@@ -105,17 +105,15 @@ class Demoboard:
105
105
  response_timeout = None if wait_forever else timeout
106
106
 
107
107
  def _iter_cmd() -> Generator[str, None, None]:
108
- for line in self._nb.run(
108
+ return self._nb.run(
109
109
  cmd=cmd,
110
110
  end_flag=flag,
111
111
  overall_timeout=timeout,
112
112
  response_timeout=response_timeout,
113
113
  stream=True,
114
114
  verbose=True,
115
- ):
116
- text = getattr(line, "text", str(line))
117
- yield text
118
-
115
+ )
116
+
119
117
  if stream:
120
118
  return _iter_cmd()
121
119
  return list(_iter_cmd())
@@ -102,10 +102,7 @@ def sdev_run(cmd: str, device_id: str = None, timeout: float = 10.0) -> str:
102
102
 
103
103
  with nb:
104
104
  lines = nb.run(cmd, overall_timeout=timeout, stream=False, verbose=False)
105
- output = []
106
- for line in lines:
107
- output.append(line.text)
108
- return "".join(output).strip()
105
+ return "".join(lines).strip()
109
106
  except Exception as e:
110
107
  return f"执行失败:{e}"
111
108
 
@@ -3,7 +3,7 @@ import sys
3
3
  import time
4
4
  from loguru import logger
5
5
 
6
- from .serial_rw import SerialRW, SerialLine, CTRL_C
6
+ from .serial_rw import SerialLine, CTRL_C
7
7
 
8
8
  GREY = "\033[90m"
9
9
  YELLOW = "\033[33m"
@@ -41,7 +41,7 @@ class SerialNotebook():
41
41
  def __exit__(self, exc_type, exc_value, traceback):
42
42
  self._core.disconnect()
43
43
 
44
- def run(self, cmd: str, end_flag=None, allow_fold=True, max_fold_lines=4, strip_echo=True, stream=False, verbose=True, overall_timeout=None, response_timeout=None):
44
+ def run(self, cmd: str, end_flag=None, allow_fold=True, max_fold_lines=4, strip_echo=True, stream=False, verbose=True, overall_timeout=None, response_timeout=None, keep_type=False):
45
45
  # 先清理残留输出,避免前一次命令的尾巴影响本次结果。
46
46
  assert cmd is not None
47
47
  self._core.drain_buffer()
@@ -79,7 +79,10 @@ class SerialNotebook():
79
79
  # print(line.kind, line.line, show_log, isinstance(line, SerialLine), line.kind == 'body')
80
80
  if show_log and isinstance(line, SerialLine) and line.kind == 'body':
81
81
  self._write_raw(f"{GREY}{line.text}{RESET}")
82
- yield line
82
+ if keep_type:
83
+ yield line
84
+ else:
85
+ yield line.text
83
86
  # 整个命令结束后,如启用 display,则额外输出一个空行(两个换行),
84
87
  # 便于与后续命令在视觉上明显隔离。
85
88
  if show_log:
@@ -157,13 +160,8 @@ class SerialNotebook():
157
160
  response_timeout=timeout,
158
161
  verbose=verbose,
159
162
  )
160
- # lines: [cmd, body, next_prompt]
161
163
  if lines and len(lines) >= 2:
162
- # 倒数第二行通常是型号内容(因为最后一行是新提示符)
163
- for line in reversed(lines[:-1]):
164
- text = line.text.strip()
165
- if text and not text.startswith("cat /proc"):
166
- return text
164
+ return lines[-2].strip()
167
165
  except Exception:
168
166
  pass
169
167
  return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdev
3
- Version: 0.7.4
3
+ Version: 0.7.5
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.4",
8
+ version="0.7.5",
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