From d1c61e4f3f974f06268836e191b3ffe33a4d0ac7 Mon Sep 17 00:00:00 2001 From: "ViX.neSS" Date: Fri, 6 Mar 2026 16:25:49 +0800 Subject: [PATCH] Refactor logging in CLI for NanoKVM devices - Replaced print statements with logger.info for better logging management in main.py and __main__.py. - Added a new logging utility module (_logger.py) to handle logger configuration. - Updated .gitignore to include additional cache and environment files. --- .gitignore | 14 ++++++++++---- docs/API.md | 2 +- main.py | 15 +++++++++------ nanokvm/__init__.py | 2 +- nanokvm/__main__.py | 15 +++++++++------ nanokvm/_logger.py | 11 +++++++++++ pyproject.toml | 2 +- uv.lock | 2 +- 8 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 nanokvm/_logger.py diff --git a/.gitignore b/.gitignore index e0164e2..a98fcf6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,13 @@ .venv/ __pycache__/ *.pyc -*.pyo -*.pyd -*.pyw -*.pyz \ No newline at end of file +.pytest_cache/ +.ruff_cache/ +.vscode/ +.idea/ +.DS_Store +.env +.env.local +.env.development.local +.env.test.local +.env.production.local \ No newline at end of file diff --git a/docs/API.md b/docs/API.md index 89cd480..9a2ae5a 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1,6 +1,6 @@ # nanokvm API Reference -**Version:** 0.1.2 +**Version:** 0.1.3 **License:** MIT **Python:** >= 3.12 diff --git a/main.py b/main.py index 9bc2740..474932f 100644 --- a/main.py +++ b/main.py @@ -1,26 +1,29 @@ """Quick CLI to list available NanoKVM devices and test connectivity.""" from nanokvm import SerialConnection, VideoCapture +from nanokvm._logger import get_logger + +logger = get_logger(__name__) def main() -> None: - print("=== Available Serial Ports ===") + logger.info("=== Available Serial Ports ===") ports = SerialConnection.list_ports() if ports: for p in ports: - print(f" {p.device}: {p.description} [{p.hwid}]") + logger.info(f" {p.device}: {p.description} [{p.hwid}]") else: - print(" (none found)") + logger.info(" (none found)") - print("\n=== Available Video Devices ===") + logger.info("\n=== Available Video Devices ===") devices = VideoCapture.list_devices() if devices: for d in devices: - print( + logger.info( f" Index {d['index']}: {d['width']}x{d['height']} @ {d['fps']}fps ({d['backend']})" ) else: - print(" (none found)") + logger.info(" (none found)") if __name__ == "__main__": diff --git a/nanokvm/__init__.py b/nanokvm/__init__.py index 3ea2e0b..adcbb94 100644 --- a/nanokvm/__init__.py +++ b/nanokvm/__init__.py @@ -26,7 +26,7 @@ from .serial_conn import SerialConnection from .video import VideoCapture -__version__ = "0.1.2" +__version__ = "0.1.3" __all__ = [ "NanoKVM", diff --git a/nanokvm/__main__.py b/nanokvm/__main__.py index 9bc2740..474932f 100644 --- a/nanokvm/__main__.py +++ b/nanokvm/__main__.py @@ -1,26 +1,29 @@ """Quick CLI to list available NanoKVM devices and test connectivity.""" from nanokvm import SerialConnection, VideoCapture +from nanokvm._logger import get_logger + +logger = get_logger(__name__) def main() -> None: - print("=== Available Serial Ports ===") + logger.info("=== Available Serial Ports ===") ports = SerialConnection.list_ports() if ports: for p in ports: - print(f" {p.device}: {p.description} [{p.hwid}]") + logger.info(f" {p.device}: {p.description} [{p.hwid}]") else: - print(" (none found)") + logger.info(" (none found)") - print("\n=== Available Video Devices ===") + logger.info("\n=== Available Video Devices ===") devices = VideoCapture.list_devices() if devices: for d in devices: - print( + logger.info( f" Index {d['index']}: {d['width']}x{d['height']} @ {d['fps']}fps ({d['backend']})" ) else: - print(" (none found)") + logger.info(" (none found)") if __name__ == "__main__": diff --git a/nanokvm/_logger.py b/nanokvm/_logger.py new file mode 100644 index 0000000..5cb9b07 --- /dev/null +++ b/nanokvm/_logger.py @@ -0,0 +1,11 @@ +import logging + + +def get_logger(name: str) -> logging.Logger: + logger = logging.getLogger(name) + if not logger.handlers: + logging.basicConfig( + level=logging.INFO, + format="%(name)s: %(message)s", + ) + return logger diff --git a/pyproject.toml b/pyproject.toml index 227ffb3..9ae156a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nanokvm" -version = "0.1.2" +version = "0.1.3" description = "Python library for controlling machines via NanoKVM-USB — serial HID + UVC video capture for AI agents" readme = "README.md" requires-python = ">=3.12" diff --git a/uv.lock b/uv.lock index 41ef10b..1f70d05 100644 --- a/uv.lock +++ b/uv.lock @@ -22,7 +22,7 @@ wheels = [ [[package]] name = "nanokvm" -version = "0.1.2" +version = "0.1.3" source = { editable = "." } dependencies = [ { name = "numpy" },