From df9aba0c6e508f8bce92f6aa3e5aae436999659b Mon Sep 17 00:00:00 2001 From: carry Date: Tue, 15 Apr 2025 15:47:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor(tools):=20=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=B9=B6=E6=9B=B4=E6=96=B0=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 scan_doc_dir.py 重命名为 document.py - 将 socket.py 重命名为 port.py - 更新 __init__.py 中的导入语句 - 在 port.py 中添加测试代码,用于查找可用端口 --- tools/__init__.py | 4 ++-- tools/{scan_doc_dir.py => document.py} | 0 tools/{socket.py => port.py} | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) rename tools/{scan_doc_dir.py => document.py} (100%) rename tools/{socket.py => port.py} (68%) diff --git a/tools/__init__.py b/tools/__init__.py index cf8041c..fd42c11 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -1,5 +1,5 @@ from .parse_markdown import parse_markdown -from .scan_doc_dir import * +from .doc import * from .json_example import generate_example_json from .model import * -from .socket import * \ No newline at end of file +from .port import * \ No newline at end of file diff --git a/tools/scan_doc_dir.py b/tools/document.py similarity index 100% rename from tools/scan_doc_dir.py rename to tools/document.py diff --git a/tools/socket.py b/tools/port.py similarity index 68% rename from tools/socket.py rename to tools/port.py index 91199a9..e50952a 100644 --- a/tools/socket.py +++ b/tools/port.py @@ -7,4 +7,9 @@ def find_available_port(start_port): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: if s.connect_ex(('localhost', port)) != 0: # 端口未被占用 return port - port += 1 # 如果端口被占用,尝试下一个端口 \ No newline at end of file + port += 1 # 如果端口被占用,尝试下一个端口 + +if __name__ == "__main__": + start_port = 6006 # 起始端口号 + available_port = find_available_port(start_port) + print(f"Available port: {available_port}") \ No newline at end of file