Skip to content

Commit 04f06e4

Browse files
author
molanp
committed
🐛 修复无法获取实例文件列表问题,为部分模型增加注释
2 parents 7173f6a + f843417 commit 04f06e4

File tree

6 files changed

+58
-3
lines changed

6 files changed

+58
-3
lines changed

example/use_case/get_all_instance_info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ def get_all_instance_info(daemon_id: str):
4040

4141
# Optional: Save info to a file in the current directory
4242
with open("instance_info.json", "w") as f:
43-
json.dump(instance_info, f, indent=4)
43+
content = json.dump(instance_info, f, indent=4)
44+
f.write(content)

mcsmapi/apis/file.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def show(
1313
target: str = "",
1414
page: int = 0,
1515
page_size: int = 100,
16+
file_name: str = ""
1617
) -> FileList:
1718
"""
1819
获取文件列表
@@ -23,6 +24,7 @@ def show(
2324
- target (str, 可选): 用于文件过滤的目标路径。默认为空字符串,表示不按路径过滤。
2425
- page (int, 可选): 指定分页的页码。默认为0。
2526
- page_size (int, 可选): 指定每页的文件数量。默认为100。
27+
- file_name (str, 可选): 用于在文件列表中过滤出名称包含指定字符串的文件或文件夹
2628
2729
**返回:**
2830
- FileList: 包含文件列表信息和分页详情的FileList模型。
@@ -36,6 +38,7 @@ def show(
3638
"target": target,
3739
"page": page,
3840
"page_size": page_size,
41+
"file_name": file_name
3942
},
4043
)
4144
return FileList(**result, daemonId=daemonId, uuid=uuid)

mcsmapi/models/daemon.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,79 @@
44

55

66
class CpuMemChart(BaseModel):
7+
"""cpu使用率"""
78
cpu: float = 0
9+
"""内存使用率"""
810
mem: float = 0
911

1012

1113
class ProcessInfo(BaseModel):
14+
"""远程节点使用的cpu资源(单位: byte)"""
1215
cpu: int = 0
16+
"""远程节点使用的内存资源(单位: byte)"""
1317
memory: int = 0
18+
"""远程节点的工作路径"""
1419
cwd: str = ""
1520

1621

1722
class InstanceInfo(BaseModel):
23+
"""运行中实例数量"""
1824
running: int = 0
25+
"""全部实例数量"""
1926
total: int = 0
2027

2128

2229
class SystemInfo(BaseModel):
30+
"""系统类型"""
2331
type: str = ""
32+
"""主机名"""
2433
hostname: str = ""
34+
"""平台架构"""
2535
platform: str = ""
36+
"""系统版本"""
2637
release: str = ""
38+
"""系统运行时间(单位: sec)"""
2739
uptime: float = 0
40+
"""远程节点运行路径"""
2841
cwd: str = ""
42+
"""系统负载平均值(仅适用于 Linux 和 macOS),表示过去 **1 分钟、5 分钟、15 分钟** 内的 CPU 负载情况"""
2943
loadavg: List[float] = []
44+
"""可用内存(单位: byte)"""
3045
freemem: int = 0
46+
"""cpu使用率"""
3147
cpuUsage: float = 0
48+
"""内存使用率"""
3249
memUsage: float = 0
50+
"""内存总量(单位: byte)"""
3351
totalmem: int = 0
52+
"""未知,在MCSM代码中始终为0"""
3453
processCpu: int = 0
54+
"""未知,在MCSM代码中始终为0"""
3555
processMem: int = 0
3656

3757

3858
class DaemonModel(BaseModel):
59+
"""远程节点版本"""
3960
version: str = ""
61+
"""远程节点的基本信息"""
4062
process: ProcessInfo = ProcessInfo()
63+
"""远程节点实例基本信息"""
4164
instance: InstanceInfo = InstanceInfo()
65+
"""远程节点系统信息"""
4266
system: SystemInfo = SystemInfo()
67+
"""cpu和内存使用趋势"""
4368
cpuMemChart: List[CpuMemChart] = []
69+
"""远程节点的uuid"""
4470
uuid: str = ""
71+
"""远程节点的ip"""
4572
ip: str = ""
73+
"""远程节点的端口"""
4674
port: int = 24444
75+
"""远程节点的路径前缀"""
4776
prefix: str = ""
77+
"""远程节点的可用状态"""
4878
available: bool = False
79+
"""远程节点的备注"""
4980
remarks: str = ""
5081

5182
def delete(self) -> bool:

mcsmapi/models/file.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@
44

55

66
class FileItem(BaseModel):
7+
"""文件名称"""
78
name: str = "New File"
9+
"""文件大小(单位: byte)"""
810
size: int = 0 # byte
11+
"""文件修改时间"""
912
time: str = ""
13+
"""文件操作权限(仅适用于Linux)"""
1014
mode: int = 777 # Linux file permission
15+
"""文件类型,`0`为文件夹,`1`为文件"""
1116
type: int = 0 # 0 = Folder, 1 = File
17+
"""远程节点uuid"""
1218
daemonId: str = ""
19+
"""实例的uiid"""
1320
uuid: str = ""
21+
"""文件所在路径"""
1422
target: str = ""
23+
"""当前文件列表过滤条件"""
24+
file_name: str = ""
1525

1626
def rename(self, newName: str) -> bool:
1727
"""
@@ -139,13 +149,21 @@ def download(self) -> str:
139149

140150

141151
class FileList(BaseModel):
152+
"""文件信息列表"""
142153
items: List[FileItem]
154+
"""当前页数"""
143155
page: int = 0
156+
"""文件列表单页大小"""
144157
pageSize: int = 100
158+
"""总页数"""
145159
total: int = 0
160+
"""当前路径在远程节点的绝对路径"""
146161
absolutePath: str = "\\"
162+
"""远程节点uuid"""
147163
daemonId: str = ""
164+
"""实例uuid"""
148165
uuid: str = ""
166+
"""文件(名称或目录)路径"""
149167
target: str = ""
150168

151169
def __init__(self, **data: str):
@@ -200,5 +218,7 @@ def createFloder(self, target: str) -> bool:
200218

201219

202220
class CommonConfig(BaseModel):
221+
"""文件下载密码"""
203222
password: str = ""
223+
"""文件下载地址"""
204224
addr: str = ""

mcsmapi/models/instance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class InstanceDetail(BaseModel):
7373
daemonId: str = ""
7474
instanceUuid: str = ""
7575
processInfo: ProcessInfo = ProcessInfo()
76-
space: int = 0
76+
space: int = 0 # 在MCSM代码中,此项始终为0,意义不明
7777
started: int = 0 # 启动次数
7878
status: int = 0 # -1 = 忙碌, 0 = 停止, 1 = 停止中, 2 = 启动中, 3 = 运行中
7979

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires = ["setuptools", "wheel"]
44

55
[project]
66
name = "mcsmapi"
7-
version = "0.1.5.b1"
7+
version = "0.1.5.b2"
88
description = "Shortcut the pypi package of MCSM./快捷操作MCSM的pypi包"
99
readme = "README.md"
1010
authors = [

0 commit comments

Comments
 (0)