mcsmapi 0.1.6__tar.gz → 0.1.8__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.
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/PKG-INFO +10 -14
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/README.md +6 -12
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/mcsmapi/__init__.py +16 -11
- mcsmapi-0.1.8/mcsmapi/apis/daemon.py +109 -0
- mcsmapi-0.1.8/mcsmapi/apis/file.py +307 -0
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/mcsmapi/apis/image.py +28 -29
- mcsmapi-0.1.8/mcsmapi/apis/instance.py +281 -0
- mcsmapi-0.1.8/mcsmapi/apis/overview.py +21 -0
- mcsmapi-0.1.8/mcsmapi/apis/schedule.py +71 -0
- mcsmapi-0.1.8/mcsmapi/apis/user.py +82 -0
- mcsmapi-0.1.8/mcsmapi/models/common.py +30 -0
- mcsmapi-0.1.8/mcsmapi/models/daemon.py +181 -0
- mcsmapi-0.1.8/mcsmapi/models/file.py +237 -0
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/mcsmapi/models/image.py +93 -85
- mcsmapi-0.1.8/mcsmapi/models/instance.py +333 -0
- mcsmapi-0.1.8/mcsmapi/models/overview.py +203 -0
- mcsmapi-0.1.8/mcsmapi/models/schedule.py +80 -0
- mcsmapi-0.1.8/mcsmapi/models/user.py +102 -0
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/mcsmapi/pool.py +2 -0
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/mcsmapi/request.py +21 -18
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/mcsmapi.egg-info/PKG-INFO +10 -14
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/mcsmapi.egg-info/SOURCES.txt +3 -1
- mcsmapi-0.1.8/mcsmapi.egg-info/requires.txt +2 -0
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/pyproject.toml +4 -2
- mcsmapi-0.1.6/mcsmapi/apis/daemon.py +0 -97
- mcsmapi-0.1.6/mcsmapi/apis/file.py +0 -321
- mcsmapi-0.1.6/mcsmapi/apis/instance.py +0 -300
- mcsmapi-0.1.6/mcsmapi/apis/overview.py +0 -17
- mcsmapi-0.1.6/mcsmapi/apis/user.py +0 -82
- mcsmapi-0.1.6/mcsmapi/models/__init__.py +0 -0
- mcsmapi-0.1.6/mcsmapi/models/daemon.py +0 -182
- mcsmapi-0.1.6/mcsmapi/models/file.py +0 -228
- mcsmapi-0.1.6/mcsmapi/models/instance.py +0 -303
- mcsmapi-0.1.6/mcsmapi/models/overview.py +0 -112
- mcsmapi-0.1.6/mcsmapi/models/user.py +0 -110
- mcsmapi-0.1.6/mcsmapi.egg-info/requires.txt +0 -2
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/LICENSE +0 -0
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/mcsmapi/apis/__init__.py +0 -0
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/mcsmapi/exceptions.py +0 -0
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/mcsmapi.egg-info/dependency_links.txt +0 -0
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/mcsmapi.egg-info/top_level.txt +0 -0
- {mcsmapi-0.1.6 → mcsmapi-0.1.8}/setup.cfg +0 -0
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mcsmapi
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.8
|
|
4
4
|
Summary: Shortcut the pypi package of MCSM./快捷操作MCSM的pypi包
|
|
5
5
|
Author-email: molanp <molanpp@outlook.com>
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: Source, https://github.com/molanp/mcsmapi
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Requires-Python: >=3.10
|
|
9
11
|
Description-Content-Type: text/markdown
|
|
10
12
|
License-File: LICENSE
|
|
11
13
|
Requires-Dist: requests
|
|
12
|
-
Requires-Dist: pydantic
|
|
14
|
+
Requires-Dist: pydantic<3.0.0,>=2.0.0
|
|
13
15
|
Dynamic: license-file
|
|
14
16
|
|
|
15
17
|
# MCSM API
|
|
@@ -21,16 +23,9 @@ Dynamic: license-file
|
|
|
21
23
|
|
|
22
24
|
English|[Chinese Simplified](README_zh-cn.md)
|
|
23
25
|
|
|
24
|
-
> [!important]
|
|
25
|
-
> We need your help, the documentation for this project has not been written yet, if you are willing, please submit pr to help us write the documentation.
|
|
26
|
-
|
|
27
26
|
## Documentation
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
You can also find:
|
|
32
|
-
|
|
33
|
-
📄 Work-in-progress docs: [docs](docs)
|
|
28
|
+
📄 Docs: [docs](https://mcsmapi.awkchan.top/en/)
|
|
34
29
|
|
|
35
30
|
💡 Example: [example](example)
|
|
36
31
|
|
|
@@ -48,7 +43,7 @@ You can install `mcsmapi` using `pip`:
|
|
|
48
43
|
pip install mcsmapi
|
|
49
44
|
```
|
|
50
45
|
|
|
51
|
-
If you need the latest build files
|
|
46
|
+
If you need the latest build files, please visit
|
|
52
47
|
[Actions](https://github.com/molanp/mcsmapi/actions/workflows/auto-build.yml)
|
|
53
48
|
|
|
54
49
|
## Supported Features
|
|
@@ -63,8 +58,8 @@ If you need the latest build files (untested), please visit
|
|
|
63
58
|
## Supported MCSM Versions
|
|
64
59
|
|
|
65
60
|
| MCSM Version | Support Status |
|
|
66
|
-
|
|
|
67
|
-
|
|
|
61
|
+
| :----------: | :------------: |
|
|
62
|
+
| 10.x | ✅ |
|
|
68
63
|
|
|
69
64
|
### Quick Example
|
|
70
65
|
|
|
@@ -82,9 +77,10 @@ mcsm.login_with_apikey("apikey")
|
|
|
82
77
|
|
|
83
78
|
# Get dashboard data
|
|
84
79
|
overview = mcsm.overview()
|
|
80
|
+
overview_data = overview.overview()
|
|
85
81
|
|
|
86
82
|
# Get MCSM version
|
|
87
|
-
mcsm_version =
|
|
83
|
+
mcsm_version = overview_data.version
|
|
88
84
|
```
|
|
89
85
|
|
|
90
86
|
## Contributing
|
|
@@ -7,16 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
English|[Chinese Simplified](README_zh-cn.md)
|
|
9
9
|
|
|
10
|
-
> [!important]
|
|
11
|
-
> We need your help, the documentation for this project has not been written yet, if you are willing, please submit pr to help us write the documentation.
|
|
12
|
-
|
|
13
10
|
## Documentation
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
You can also find:
|
|
18
|
-
|
|
19
|
-
📄 Work-in-progress docs: [docs](docs)
|
|
12
|
+
📄 Docs: [docs](https://mcsmapi.awkchan.top/en/)
|
|
20
13
|
|
|
21
14
|
💡 Example: [example](example)
|
|
22
15
|
|
|
@@ -34,7 +27,7 @@ You can install `mcsmapi` using `pip`:
|
|
|
34
27
|
pip install mcsmapi
|
|
35
28
|
```
|
|
36
29
|
|
|
37
|
-
If you need the latest build files
|
|
30
|
+
If you need the latest build files, please visit
|
|
38
31
|
[Actions](https://github.com/molanp/mcsmapi/actions/workflows/auto-build.yml)
|
|
39
32
|
|
|
40
33
|
## Supported Features
|
|
@@ -49,8 +42,8 @@ If you need the latest build files (untested), please visit
|
|
|
49
42
|
## Supported MCSM Versions
|
|
50
43
|
|
|
51
44
|
| MCSM Version | Support Status |
|
|
52
|
-
|
|
|
53
|
-
|
|
|
45
|
+
| :----------: | :------------: |
|
|
46
|
+
| 10.x | ✅ |
|
|
54
47
|
|
|
55
48
|
### Quick Example
|
|
56
49
|
|
|
@@ -68,9 +61,10 @@ mcsm.login_with_apikey("apikey")
|
|
|
68
61
|
|
|
69
62
|
# Get dashboard data
|
|
70
63
|
overview = mcsm.overview()
|
|
64
|
+
overview_data = overview.overview()
|
|
71
65
|
|
|
72
66
|
# Get MCSM version
|
|
73
|
-
mcsm_version =
|
|
67
|
+
mcsm_version = overview_data.version
|
|
74
68
|
```
|
|
75
69
|
|
|
76
70
|
## Contributing
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import urllib.parse
|
|
2
|
-
from mcsmapi.models.overview import OverviewModel
|
|
3
2
|
from mcsmapi.pool import ApiPool
|
|
4
3
|
from mcsmapi.apis.file import File
|
|
5
4
|
from mcsmapi.apis.user import User
|
|
@@ -11,15 +10,15 @@ from mcsmapi.request import Request
|
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
class MCSMAPI:
|
|
14
|
-
|
|
13
|
+
|
|
14
|
+
def __init__(self, url: str, timeout: int = 5):
|
|
15
15
|
split_url = urllib.parse.urlsplit(url)
|
|
16
16
|
Request.set_mcsm_url(
|
|
17
17
|
urllib.parse.urljoin(f"{split_url.scheme}://{split_url.netloc}", "")
|
|
18
18
|
)
|
|
19
|
-
self.authentication = None
|
|
20
19
|
Request.set_timeout(timeout)
|
|
21
20
|
|
|
22
|
-
def login(self, username: str, password: str)
|
|
21
|
+
def login(self, username: str, password: str):
|
|
23
22
|
Request.set_token(
|
|
24
23
|
Request.send(
|
|
25
24
|
"POST",
|
|
@@ -35,20 +34,26 @@ class MCSMAPI:
|
|
|
35
34
|
self.authentication = "apikey"
|
|
36
35
|
return self
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
@property
|
|
38
|
+
def overview(self):
|
|
39
|
+
return Overview()
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
@property
|
|
42
|
+
def instance(self):
|
|
42
43
|
return Instance()
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
@property
|
|
46
|
+
def user(self) :
|
|
45
47
|
return User()
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
@property
|
|
50
|
+
def daemon(self):
|
|
48
51
|
return Daemon()
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
@property
|
|
54
|
+
def file(self):
|
|
51
55
|
return File()
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
@property
|
|
58
|
+
def image(self):
|
|
54
59
|
return Image()
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
from mcsmapi.pool import ApiPool
|
|
3
|
+
from mcsmapi.request import send
|
|
4
|
+
from mcsmapi.models.daemon import (
|
|
5
|
+
DaemonConfig,
|
|
6
|
+
DaemonInfo,
|
|
7
|
+
DaemonSystemInfo,
|
|
8
|
+
DaemonStatus,
|
|
9
|
+
DaemonUpdateConfig,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Daemon:
|
|
14
|
+
@staticmethod
|
|
15
|
+
def config() -> list[DaemonStatus]:
|
|
16
|
+
"""
|
|
17
|
+
获取全部节点配置信息
|
|
18
|
+
|
|
19
|
+
:returns: 节点的配置信息列表
|
|
20
|
+
"""
|
|
21
|
+
daemons = send(
|
|
22
|
+
"GET",
|
|
23
|
+
f"{ApiPool.SERVICE}/remote_services_list",
|
|
24
|
+
)
|
|
25
|
+
return [DaemonStatus(**daemon) for daemon in daemons]
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def info() -> list[DaemonInfo]:
|
|
29
|
+
"""
|
|
30
|
+
获取全部节点信息
|
|
31
|
+
|
|
32
|
+
:returns: 节点信息列表
|
|
33
|
+
"""
|
|
34
|
+
daemons = send(
|
|
35
|
+
"GET",
|
|
36
|
+
f"{ApiPool.SERVICE}/remote_services",
|
|
37
|
+
)
|
|
38
|
+
return [DaemonInfo(**daemon) for daemon in daemons]
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
def system() -> list[DaemonSystemInfo]:
|
|
42
|
+
"""
|
|
43
|
+
获取全部节点的系统信息
|
|
44
|
+
|
|
45
|
+
:returns: 节点系统信息列表
|
|
46
|
+
"""
|
|
47
|
+
daemons = send(
|
|
48
|
+
"GET",
|
|
49
|
+
f"{ApiPool.SERVICE}/remote_services_system",
|
|
50
|
+
)
|
|
51
|
+
return [DaemonSystemInfo(**daemon) for daemon in daemons]
|
|
52
|
+
|
|
53
|
+
@staticmethod
|
|
54
|
+
def add(config: DaemonConfig) -> str:
|
|
55
|
+
"""
|
|
56
|
+
新增一个节点
|
|
57
|
+
|
|
58
|
+
:params config: 节点的配置信息
|
|
59
|
+
|
|
60
|
+
:returns: 新增节点的UUID
|
|
61
|
+
"""
|
|
62
|
+
return send(
|
|
63
|
+
"POST",
|
|
64
|
+
f"{ApiPool.SERVICE}/remote_service",
|
|
65
|
+
data=config.model_dump(),
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
@staticmethod
|
|
69
|
+
def delete(daemonId: str) -> bool:
|
|
70
|
+
"""
|
|
71
|
+
删除一个节点
|
|
72
|
+
|
|
73
|
+
:params daemonId: 节点的UUID
|
|
74
|
+
|
|
75
|
+
:returns: 操作成功后返回True
|
|
76
|
+
"""
|
|
77
|
+
return send(
|
|
78
|
+
"DELETE", f"{ApiPool.SERVICE}/remote_service", params={"uuid": daemonId}
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
@staticmethod
|
|
82
|
+
def link(daemonId: str) -> bool:
|
|
83
|
+
"""
|
|
84
|
+
连接一个节点
|
|
85
|
+
|
|
86
|
+
:params daemonId: 节点的UUID
|
|
87
|
+
|
|
88
|
+
:returns: 操作成功后返回True
|
|
89
|
+
"""
|
|
90
|
+
return send(
|
|
91
|
+
"GET", f"{ApiPool.SERVICE}/link_remote_service", params={"uuid": daemonId}
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def update(daemonId: str, config: dict[str, Any]) -> bool:
|
|
96
|
+
"""
|
|
97
|
+
更新一个节点的配置
|
|
98
|
+
|
|
99
|
+
:params daemonId: 节点的UUID
|
|
100
|
+
:params config: 节点的配置信息,以字典形式提供,缺失内容由DaemonUpdateConfig模型补全
|
|
101
|
+
|
|
102
|
+
:returns: 操作成功后返回True
|
|
103
|
+
"""
|
|
104
|
+
return send(
|
|
105
|
+
"PUT",
|
|
106
|
+
f"{ApiPool.SERVICE}/remote_service",
|
|
107
|
+
params={"uuid": daemonId},
|
|
108
|
+
data=DaemonUpdateConfig(**config).model_dump(),
|
|
109
|
+
)
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
from mcsmapi.pool import ApiPool
|
|
3
|
+
from mcsmapi.request import Request, send, upload
|
|
4
|
+
from mcsmapi.models.file import FileDownloadConfig, FileList
|
|
5
|
+
import urllib.parse
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class File:
|
|
10
|
+
@staticmethod
|
|
11
|
+
def show(
|
|
12
|
+
daemonId: str,
|
|
13
|
+
uuid: str,
|
|
14
|
+
target: str = "",
|
|
15
|
+
page: int = 0,
|
|
16
|
+
page_size: int = 100,
|
|
17
|
+
file_name: str = "",
|
|
18
|
+
) -> FileList:
|
|
19
|
+
"""
|
|
20
|
+
获取文件列表
|
|
21
|
+
|
|
22
|
+
:params daemonId: 节点的UUID
|
|
23
|
+
:params uuid: 实例的UUID
|
|
24
|
+
:params target: 用于文件过滤的目标路径
|
|
25
|
+
:params page: 指定分页的页码
|
|
26
|
+
:params page_size: 指定每页的文件数量
|
|
27
|
+
:params file_name: 用于在文件列表中过滤出名称包含指定字符串的文件或文件夹
|
|
28
|
+
|
|
29
|
+
:returns: 包含文件列表信息和分页详情的FileList模型
|
|
30
|
+
"""
|
|
31
|
+
result = send(
|
|
32
|
+
"GET",
|
|
33
|
+
f"{ApiPool.FILE}/list",
|
|
34
|
+
params={
|
|
35
|
+
"daemonId": daemonId,
|
|
36
|
+
"uuid": uuid,
|
|
37
|
+
"target": target,
|
|
38
|
+
"page": page,
|
|
39
|
+
"page_size": page_size,
|
|
40
|
+
"file_name": file_name,
|
|
41
|
+
},
|
|
42
|
+
)
|
|
43
|
+
return FileList(**result, daemonId=daemonId, uuid=uuid)
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def content(daemonId: str, uuid: str, target: str) -> str:
|
|
47
|
+
"""
|
|
48
|
+
获取文件内容
|
|
49
|
+
|
|
50
|
+
:params daemonId: 节点的UUID
|
|
51
|
+
:params uuid: 实例的UUID
|
|
52
|
+
:params target: 文件的目标路径
|
|
53
|
+
|
|
54
|
+
:returns: 文件的内容信息
|
|
55
|
+
"""
|
|
56
|
+
return send(
|
|
57
|
+
"PUT",
|
|
58
|
+
f"{ApiPool.FILE}",
|
|
59
|
+
params={"daemonId": daemonId, "uuid": uuid},
|
|
60
|
+
data={"target": target},
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def update(daemonId: str, uuid: str, target: str, text: str) -> bool:
|
|
65
|
+
"""
|
|
66
|
+
更新文件内容
|
|
67
|
+
|
|
68
|
+
:params daemonId: 节点的UUID
|
|
69
|
+
:params uuid: 实例的UUID
|
|
70
|
+
:params target: 目标文件的路径
|
|
71
|
+
:params text: 新的文件内容
|
|
72
|
+
|
|
73
|
+
:returns: 操作成功后返回True
|
|
74
|
+
"""
|
|
75
|
+
return send(
|
|
76
|
+
"PUT",
|
|
77
|
+
f"{ApiPool.FILE}",
|
|
78
|
+
params={"daemonId": daemonId, "uuid": uuid},
|
|
79
|
+
data={"target": target, "text": text},
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def download(daemonId: str, uuid: str, file_name: str) -> str:
|
|
84
|
+
"""
|
|
85
|
+
下载文件
|
|
86
|
+
|
|
87
|
+
:params daemonId: 节点的UUID
|
|
88
|
+
:params uuid: 实例的UUID
|
|
89
|
+
:params file_name: 要下载的文件的实例内完整路径, eg: /backup/world.zip
|
|
90
|
+
|
|
91
|
+
:returns: 文件下载URL
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
result = send(
|
|
95
|
+
"POST",
|
|
96
|
+
f"{ApiPool.FILE}/download",
|
|
97
|
+
params={"daemonId": daemonId, "uuid": uuid, "file_name": file_name},
|
|
98
|
+
)
|
|
99
|
+
result = FileDownloadConfig(**result)
|
|
100
|
+
protocol = Request.mcsm_url.split("://")[0]
|
|
101
|
+
base_url = urllib.parse.urljoin(f"{protocol}://{result.addr}", "download")
|
|
102
|
+
return urllib.parse.urljoin(base_url, f"{result.password}/{file_name}")
|
|
103
|
+
|
|
104
|
+
@staticmethod
|
|
105
|
+
async def upload(daemonId: str, uuid: str, file: bytes, upload_dir: str) -> bool:
|
|
106
|
+
"""
|
|
107
|
+
上传文件
|
|
108
|
+
|
|
109
|
+
:params daemonId: 节点的UUID
|
|
110
|
+
:params uuid: 实例的UUID
|
|
111
|
+
:params file: 要上传的文件内容
|
|
112
|
+
:params upload_dir: 文件上传到的目标路径
|
|
113
|
+
|
|
114
|
+
:returns: 操作成功后返回True
|
|
115
|
+
"""
|
|
116
|
+
result = send(
|
|
117
|
+
"POST",
|
|
118
|
+
f"{ApiPool.FILE}/upload",
|
|
119
|
+
params={"daemonId": daemonId, "uuid": uuid, "upload_dir": upload_dir},
|
|
120
|
+
)
|
|
121
|
+
result = FileDownloadConfig(**result)
|
|
122
|
+
protocol = Request.mcsm_url.split("://")[0]
|
|
123
|
+
base_url = urllib.parse.urljoin(f"{protocol}://{result.addr}", "upload")
|
|
124
|
+
final_url = urllib.parse.urljoin(base_url, result.password)
|
|
125
|
+
await upload(final_url, file)
|
|
126
|
+
return True
|
|
127
|
+
|
|
128
|
+
@staticmethod
|
|
129
|
+
def copy_to(daemonId: str, uuid: str, copy_map: dict[str, str]) -> bool:
|
|
130
|
+
"""
|
|
131
|
+
复制多个文件夹或文件到指定位置
|
|
132
|
+
|
|
133
|
+
:params daemonId: 节点的UUID
|
|
134
|
+
:params uuid: 实例的UUID
|
|
135
|
+
:params copy_map: 复制映射,格式为 {源路径: 目标路径}
|
|
136
|
+
|
|
137
|
+
:returns: 操作成功后返回True
|
|
138
|
+
"""
|
|
139
|
+
targets = [[source, target] for source, target in copy_map.items()]
|
|
140
|
+
return send(
|
|
141
|
+
"POST",
|
|
142
|
+
f"{ApiPool.FILE}/copy",
|
|
143
|
+
params={"daemonId": daemonId, "uuid": uuid},
|
|
144
|
+
data={"targets": targets},
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
@staticmethod
|
|
148
|
+
def copyOne(daemonId: str, uuid: str, source: str, target: str) -> bool:
|
|
149
|
+
"""
|
|
150
|
+
复制单个文件或文件夹到指定位置
|
|
151
|
+
|
|
152
|
+
:params daemonId: 节点的UUID
|
|
153
|
+
:params uuid: 实例的UUID
|
|
154
|
+
:params source: 源文件或文件夹的路径
|
|
155
|
+
:params target: 目标文件或文件夹的路径
|
|
156
|
+
|
|
157
|
+
:returns: 操作成功后返回True
|
|
158
|
+
"""
|
|
159
|
+
return File.copy_to(daemonId, uuid, {source: target})
|
|
160
|
+
|
|
161
|
+
@staticmethod
|
|
162
|
+
def move(daemonId: str, uuid: str, copy_map: dict[str, str]) -> bool:
|
|
163
|
+
"""
|
|
164
|
+
移动多个文件或文件夹到指定位置
|
|
165
|
+
|
|
166
|
+
:params daemonId: 节点的UUID
|
|
167
|
+
:params uuid: 实例的UUID
|
|
168
|
+
:params copy_map: 移动映射,格式为 {源路径: 目标路径}
|
|
169
|
+
|
|
170
|
+
:returns: 操作成功后返回True
|
|
171
|
+
"""
|
|
172
|
+
targets = [[source, target] for source, target in copy_map.items()]
|
|
173
|
+
return send(
|
|
174
|
+
"PUT",
|
|
175
|
+
f"{ApiPool.FILE}/move",
|
|
176
|
+
params={"daemonId": daemonId, "uuid": uuid},
|
|
177
|
+
data={"targets": targets},
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
@staticmethod
|
|
181
|
+
def moveOne(daemonId: str, uuid: str, source: str, target: str) -> bool:
|
|
182
|
+
"""
|
|
183
|
+
从源路径移动单个文件或文件夹到目标路径
|
|
184
|
+
|
|
185
|
+
:params daemonId: 节点的UUID
|
|
186
|
+
:params uuid: 实例的UUID
|
|
187
|
+
:params source: 源文件或文件夹的路径
|
|
188
|
+
:params target: 目标文件或文件夹的路径
|
|
189
|
+
|
|
190
|
+
:returns: 操作成功后返回True
|
|
191
|
+
"""
|
|
192
|
+
return File.move(daemonId, uuid, {source: target})
|
|
193
|
+
|
|
194
|
+
@staticmethod
|
|
195
|
+
def rename(daemonId: str, uuid: str, source: str, new_name: str) -> bool:
|
|
196
|
+
"""
|
|
197
|
+
重命名单个文件或文件夹
|
|
198
|
+
|
|
199
|
+
:params daemonId: 节点的UUID
|
|
200
|
+
:params uuid: 实例的UUID
|
|
201
|
+
:params source: 源文件或文件夹的路径
|
|
202
|
+
:params new_name: 源文件或文件夹的新名字
|
|
203
|
+
|
|
204
|
+
:returns: 操作成功后返回True
|
|
205
|
+
"""
|
|
206
|
+
directory = os.path.dirname(source)
|
|
207
|
+
target = os.path.join(directory, new_name)
|
|
208
|
+
return File.moveOne(daemonId, uuid, source, target)
|
|
209
|
+
|
|
210
|
+
@staticmethod
|
|
211
|
+
def zip(daemonId: str, uuid: str, source: str, targets: list[str]) -> bool:
|
|
212
|
+
"""
|
|
213
|
+
压缩多个文件或文件夹到指定位置
|
|
214
|
+
|
|
215
|
+
:params daemonId: 节点的UUID
|
|
216
|
+
:params uuid: 实例的UUID
|
|
217
|
+
:params source: 要压缩到的目标文件的路径
|
|
218
|
+
:params targets: 需要压缩的文件路径
|
|
219
|
+
|
|
220
|
+
:returns: 操作成功后返回True
|
|
221
|
+
"""
|
|
222
|
+
return send(
|
|
223
|
+
"POST",
|
|
224
|
+
f"{ApiPool.FILE}/compress",
|
|
225
|
+
params={"daemonId": daemonId, "uuid": uuid},
|
|
226
|
+
data={"type": 1, "code": "utf-8", "source": source, "targets": targets},
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
@staticmethod
|
|
230
|
+
def unzip(
|
|
231
|
+
daemonId: str,
|
|
232
|
+
uuid: str,
|
|
233
|
+
source: str,
|
|
234
|
+
targets: str,
|
|
235
|
+
code: Literal["utf-8", "gbk", "big5"] = "utf-8",
|
|
236
|
+
) -> bool:
|
|
237
|
+
"""
|
|
238
|
+
解压缩指定的zip文件到目标位置
|
|
239
|
+
|
|
240
|
+
:params daemonId: 节点的UUID
|
|
241
|
+
:params uuid: 实例的UUID
|
|
242
|
+
:params source: 需要解压的zip文件路径
|
|
243
|
+
:params targets: 解压到的目标路径
|
|
244
|
+
:params code: 压缩文件的编码方式
|
|
245
|
+
|
|
246
|
+
:returns: 操作成功后返回True
|
|
247
|
+
"""
|
|
248
|
+
return send(
|
|
249
|
+
"POST",
|
|
250
|
+
f"{ApiPool.FILE}/compress",
|
|
251
|
+
params={"daemonId": daemonId, "uuid": uuid},
|
|
252
|
+
data={"type": 2, "code": code, "source": source, "targets": targets},
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
@staticmethod
|
|
256
|
+
def delete(daemonId: str, uuid: str, targets: list[str]) -> bool:
|
|
257
|
+
"""
|
|
258
|
+
删除多个文件或文件夹
|
|
259
|
+
|
|
260
|
+
:params daemonId: 节点的UUID
|
|
261
|
+
:params uuid: 实例的UUID
|
|
262
|
+
:params targets: 要删除的文件或文件夹的路径
|
|
263
|
+
|
|
264
|
+
:returns: 操作成功后返回True
|
|
265
|
+
"""
|
|
266
|
+
return send(
|
|
267
|
+
"DELETE",
|
|
268
|
+
ApiPool.FILE,
|
|
269
|
+
params={"daemonId": daemonId, "uuid": uuid},
|
|
270
|
+
data={"targets": targets},
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
@staticmethod
|
|
274
|
+
def createFile(daemonId: str, uuid: str, target: str) -> bool:
|
|
275
|
+
"""
|
|
276
|
+
创建文件
|
|
277
|
+
|
|
278
|
+
:params daemonId: 节点的UUID
|
|
279
|
+
:params uuid: 实例的UUID
|
|
280
|
+
:params target: 目标文件的路径,包含文件名
|
|
281
|
+
|
|
282
|
+
:returns: 操作成功后返回True
|
|
283
|
+
"""
|
|
284
|
+
return send(
|
|
285
|
+
"POST",
|
|
286
|
+
f"{ApiPool.FILE}/touch",
|
|
287
|
+
params={"daemonId": daemonId, "uuid": uuid},
|
|
288
|
+
data={"target": target},
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
@staticmethod
|
|
292
|
+
def createFolder(daemonId: str, uuid: str, target: str) -> bool:
|
|
293
|
+
"""
|
|
294
|
+
创建文件夹
|
|
295
|
+
|
|
296
|
+
:params daemonId: 节点的UUID
|
|
297
|
+
:params uuid: 实例的UUID
|
|
298
|
+
:params target: 目标文件夹的路径
|
|
299
|
+
|
|
300
|
+
:returns: 操作成功后返回True
|
|
301
|
+
"""
|
|
302
|
+
return send(
|
|
303
|
+
"POST",
|
|
304
|
+
f"{ApiPool.FILE}/mkdir",
|
|
305
|
+
params={"daemonId": daemonId, "uuid": uuid},
|
|
306
|
+
data={"target": target},
|
|
307
|
+
)
|