sdev 0.7.0__tar.gz → 0.7.2__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.0
3
+ Version: 0.7.2
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.0"
7
+ version = "0.7.2"
8
8
  description = "串口控制器工具包"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -8,5 +8,5 @@
8
8
  from importlib import metadata as _metadata
9
9
 
10
10
  __version__ = _metadata.version("sdev")
11
- from .modules import CTRL_C, SerialCore, SerialRunner, scan_serial_ports, check_port_alive_nonblock # noqa: F401
11
+ from .modules import SerialNotebook
12
12
 
@@ -1,14 +1,14 @@
1
1
  from __future__ import annotations
2
2
 
3
- from .serial_rw import SerialRW, SerialRunner, scan_serial_ports, check_port_alive_nonblock
3
+ from .serial_rw import SerialRW, scan_serial_ports, check_port_alive_nonblock
4
4
  from .serial_rw_server import SerialRWClient, SerialRWServer, DEFAULT_SERVICE_PORT
5
+ from .serial_notebook import SerialNotebook
5
6
 
6
7
  __all__ = [
7
8
  "SerialRW",
8
- "SerialRunner",
9
+ "SerialRWClient",
10
+ "SerialRWServer",
9
11
  "scan_serial_ports",
10
12
  "check_port_alive_nonblock",
11
13
  "DEFAULT_SERVICE_PORT",
12
- "SerialRWClient",
13
- "SerialRWServer",
14
14
  ]
@@ -1,9 +1,10 @@
1
1
 
2
2
  import sys
3
3
  import time
4
- from serial_rw import SerialRW, SerialLine, CTRL_C
5
4
  from loguru import logger
6
5
 
6
+ from .serial_rw import SerialRW, SerialLine, CTRL_C
7
+
7
8
  GREY = "\033[90m"
8
9
  YELLOW = "\033[33m"
9
10
  RED = "\033[31m"
@@ -259,59 +259,6 @@ class SerialRW():
259
259
  def serial_rw(device: str, baudrate: int = 115200):
260
260
  return SerialRW(device, baudrate)
261
261
 
262
-
263
- class SerialRunner:
264
- """基于 SerialRW 的运行控制器。"""
265
- def __init__(self, core: SerialRW):
266
- self._core = core
267
-
268
- def run(self, cmd, prompt_flag=" #", overall_timeout=None, response_timeout=None, wait_forever=False, stream=False, display=False):
269
- self._core.drain_buffer()
270
- YELLOW, GREY, RED, RESET = "\033[33m", "\033[90m", "\033[31m", "\033[0m"
271
-
272
- def _iter():
273
- try:
274
- if cmd and display:
275
- sys.stdout.write(f"{YELLOW}> {cmd}{RESET}\n")
276
- sys.stdout.flush()
277
- for line in self._core.forward(x=cmd, flag=prompt_flag, timeout=None if wait_forever else response_timeout):
278
- if line.kind == 'timeout': raise TimeoutError
279
- if display and line.kind == 'body':
280
- text = line.text
281
- if prompt_flag in text:
282
- text = text.replace(prompt_flag, f"\033[32m{prompt_flag}{RESET}{GREY}")
283
- sys.stdout.write(f"{GREY}{text}{RESET}")
284
- sys.stdout.flush()
285
- yield line.text
286
- if display:
287
- sys.stdout.write("\n\n")
288
- sys.stdout.flush()
289
- except TimeoutError:
290
- if display:
291
- sys.stdout.write(f"\n{RED}<sdev timeout>{RESET}\n")
292
- sys.stdout.flush()
293
- else: raise
294
-
295
- gen = _iter()
296
- return gen if stream else list(gen)
297
-
298
- def send_interrupt(self):
299
- try:
300
- self._core.dry_send(CTRL_C)
301
- except:
302
- pass
303
-
304
- def check_model_type(self, timeout=2.0):
305
- try:
306
- lines = self.run("cat /proc/device-tree/model 2>/dev/null; echo", prompt_flag=" #", response_timeout=timeout)
307
- for l in reversed(lines):
308
- s = l.strip().replace("\x00", "")
309
- if s and " #" not in s:
310
- return s.split("/")[0].strip()[:16].lower()
311
- except:
312
- pass
313
- return None
314
-
315
262
  if __name__ == "__main__":
316
263
  s = serial_rw("/dev/ttyUSB0", 115200)
317
264
  s.connect()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sdev
3
- Version: 0.7.0
3
+ Version: 0.7.2
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.0",
8
+ version="0.7.2",
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