artdam-cli 0.4.0__tar.gz → 0.4.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.
Files changed (37) hide show
  1. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/PKG-INFO +1 -1
  2. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/engine.py +87 -54
  3. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/update.py +16 -4
  4. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/main.py +1 -1
  5. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli.egg-info/PKG-INFO +1 -1
  6. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/pyproject.toml +1 -1
  7. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/README.md +0 -0
  8. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/__init__.py +0 -0
  9. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/client.py +0 -0
  10. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/__init__.py +0 -0
  11. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/comment.py +0 -0
  12. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/delete_cmd.py +0 -0
  13. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/download.py +0 -0
  14. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/favorite.py +0 -0
  15. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/folder_cmd.py +0 -0
  16. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/folders.py +0 -0
  17. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/get.py +0 -0
  18. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/login.py +0 -0
  19. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/project.py +0 -0
  20. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/projects.py +0 -0
  21. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/rate.py +0 -0
  22. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/restore.py +0 -0
  23. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/search.py +0 -0
  24. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/tag_cmd.py +0 -0
  25. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/tags.py +0 -0
  26. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/commands/upload.py +0 -0
  27. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/config.py +0 -0
  28. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/update_check.py +0 -0
  29. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli/uploader.py +0 -0
  30. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli.egg-info/SOURCES.txt +0 -0
  31. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli.egg-info/dependency_links.txt +0 -0
  32. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli.egg-info/entry_points.txt +0 -0
  33. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli.egg-info/requires.txt +0 -0
  34. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/artdam_cli.egg-info/top_level.txt +0 -0
  35. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/setup.cfg +0 -0
  36. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/tests/test_search_pagination.py +0 -0
  37. {artdam_cli-0.4.0 → artdam_cli-0.4.2}/tests/test_uploader.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: artdam-cli
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: ArtDAM 数字资产管理平台命令行工具
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  """`artdam engine` —— 本机引擎实时预览的安装/启停(取代旧的 irm install.ps1)。
2
2
 
3
- 美术装了 cli(`uv tool install artdam-cli`,自带 uv + Python)后,`artdam engine install`
3
+ 美术装了 cli(用 `uv tool install artdam-cli` 装,uv 会自动取独立 Python)后,`artdam engine install`
4
4
  一条命令在本机把引擎预览装好并起起来:从后端下载 agent + webserver + Unity 脚本 → 用 uv
5
5
  建独立 Python 环境装依赖 → 起 agent(127.0.0.1:8091) + 设开机自启 → 部署 Unity 脚本到工程。
6
6
 
@@ -50,7 +50,7 @@ def _install_dir() -> Path:
50
50
 
51
51
 
52
52
  def _find_uv() -> str:
53
- """定位 uv(装了 cli 的机器必有;PATH 找不到再查 Astral 默认安装路径)。"""
53
+ """定位 uv(需预先安装 uv;PATH 找不到再查 Astral 默认安装路径)。"""
54
54
  found = shutil.which("uv")
55
55
  if found:
56
56
  return found
@@ -62,20 +62,36 @@ def _find_uv() -> str:
62
62
  if p.is_file():
63
63
  return str(p)
64
64
  raise SystemExit(
65
- "找不到 uv —— 它本应随 artdam-cli 一起装好。"
66
- "请先 'irm https://astral.sh/uv/install.ps1 | iex' 装 uv 后重试。"
65
+ "找不到 uv —— 引擎预览需要 uv(cli 一般也用 uv 安装)。"
66
+ "请先 'irm https://astral.sh/uv/install.ps1 | iex' 装 uv 并确保在 PATH 后重试。"
67
67
  )
68
68
 
69
69
 
70
70
  def _download(base_url: str, name: str, dest: Path) -> None:
71
71
  """从后端 /api/engine/install/{name} 下载到 dest(内网无鉴权端点)。"""
72
72
  url = f"{base_url}/api/engine/install/{name}"
73
- with httpx.stream("GET", url, timeout=120, follow_redirects=True) as r:
74
- if r.status_code != 200:
75
- raise SystemExit(f"下载 {name} 失败:HTTP {r.status_code}({url})")
76
- with open(dest, "wb") as f:
77
- for chunk in r.iter_bytes(65536):
78
- f.write(chunk)
73
+ try:
74
+ with httpx.stream("GET", url, timeout=120, follow_redirects=True) as r:
75
+ if r.status_code != 200:
76
+ raise SystemExit(f"下载 {name} 失败:HTTP {r.status_code}({url})")
77
+ with open(dest, "wb") as f:
78
+ for chunk in r.iter_bytes(65536):
79
+ f.write(chunk)
80
+ except httpx.RequestError as e:
81
+ raise SystemExit(
82
+ f"下载 {name} 失败:网络错误({e})。请检查网络、或能否访问 {base_url}。"
83
+ ) from e
84
+
85
+
86
+ def _safe_extract(zip_path: Path, dest: Path) -> None:
87
+ """解压到 dest,并校验每个条目都落在 dest 内(防 Zip Slip:包内 `../` 越界写到目录外)。"""
88
+ dest = dest.resolve()
89
+ with zipfile.ZipFile(zip_path) as zf:
90
+ for member in zf.namelist():
91
+ target = (dest / member).resolve()
92
+ if target != dest and dest not in target.parents:
93
+ raise SystemExit(f"压缩包含越界路径,已中止解压:{member}")
94
+ zf.extractall(dest)
79
95
 
80
96
 
81
97
  def _run(cmd: list[str], err: str) -> None:
@@ -86,7 +102,7 @@ def _run(cmd: list[str], err: str) -> None:
86
102
  def _stop_running_agent() -> None:
87
103
  """按端口停掉在跑的旧 agent(重建 venv 前要先松开文件锁)。"""
88
104
  ps = (
89
- "$p=(Get-NetTCPConnection -LocalPort 8091 -State Listen "
105
+ f"$p=(Get-NetTCPConnection -LocalPort {AGENT_PORT} -State Listen "
90
106
  "-ErrorAction SilentlyContinue | Select-Object -First 1).OwningProcess; "
91
107
  "if ($p) { Stop-Process -Id $p -Force -ErrorAction SilentlyContinue }"
92
108
  )
@@ -112,20 +128,21 @@ def _write_autostart(install_dir: Path, venv_py: Path, webserver: Path) -> Path:
112
128
  )
113
129
  run_script.write_text("\r\n".join(lines), encoding="utf-8")
114
130
 
131
+ appdata = os.environ.get("APPDATA")
132
+ if not appdata:
133
+ raise SystemExit(
134
+ "找不到 %APPDATA%,无法创建开机自启项,请确认 Windows 账户配置正常。"
135
+ )
115
136
  startup = (
116
- Path(os.environ["APPDATA"])
117
- / "Microsoft"
118
- / "Windows"
119
- / "Start Menu"
120
- / "Programs"
121
- / "Startup"
137
+ Path(appdata) / "Microsoft" / "Windows" / "Start Menu" / "Programs" / "Startup"
122
138
  )
123
139
  startup.mkdir(parents=True, exist_ok=True)
124
140
  vbs = startup / "artdam-engine-agent.vbs"
125
141
  vbs.write_text(
126
142
  'CreateObject("WScript.Shell").Run '
127
143
  f'"powershell -ExecutionPolicy Bypass -NoProfile -WindowStyle Hidden -File ""{run_script}""", 0, False\r\n',
128
- encoding="ascii",
144
+ # mbcs=系统 ANSI 代码页:支持中文用户名等非 ASCII 的 %LOCALAPPDATA% 路径(ascii 会 UnicodeEncodeError)
145
+ encoding="mbcs",
129
146
  )
130
147
  return vbs
131
148
 
@@ -153,8 +170,7 @@ def _deploy_overlay(install_dir: Path, base_url: str, project_path: str) -> None
153
170
  # 先整目录删 _ArtdamPreview(Expand 只覆盖不删,旧文件如 asmdef 会残留报错)
154
171
  if preview_dir.exists():
155
172
  shutil.rmtree(preview_dir, ignore_errors=True)
156
- with zipfile.ZipFile(overlay_zip) as zf:
157
- zf.extractall(assets)
173
+ _safe_extract(overlay_zip, assets)
158
174
  overlay_zip.unlink(missing_ok=True)
159
175
  console.print(f" overlay → {preview_dir}")
160
176
 
@@ -165,56 +181,35 @@ def _deploy_overlay(install_dir: Path, base_url: str, project_path: str) -> None
165
181
  return
166
182
  rs_zip = install_dir / "renderstreaming.zip"
167
183
  _download(base_url, "renderstreaming.zip", rs_zip)
168
- with zipfile.ZipFile(rs_zip) as zf:
169
- zf.extractall(Path(project_path) / "Packages")
184
+ _safe_extract(rs_zip, Path(project_path) / "Packages")
170
185
  rs_zip.unlink(missing_ok=True)
171
186
  console.print(f" RenderStreaming → {pkg_dir}")
172
187
 
173
188
 
174
- @click.group()
175
- def engine() -> None:
176
- """本机引擎实时预览:安装 / 启停。"""
177
-
178
-
179
- @engine.command()
180
- @click.argument("project")
181
- def install(project: str) -> None:
182
- """安装并启动某项目的引擎实时预览(仅 Windows)。
183
-
184
- PROJECT 为项目代号,如 heartopia(心动小镇)。不同项目用不同代号;
185
- 认不出的代号会被拒,避免给错项目装错引擎。
186
- """
187
- _require_windows()
188
- if project not in _SUPPORTED_PROJECTS:
189
- raise SystemExit(
190
- f"暂不支持的项目代号:{project}。"
191
- f"目前支持:{', '.join(sorted(_SUPPORTED_PROJECTS))}。"
192
- )
193
- base_url = config.require("base_url")
194
- install_dir = _install_dir()
195
- uv = _find_uv()
196
- console.print(f"[cyan]→[/cyan] 安装目录:{install_dir}")
197
- console.print(f"[cyan]→[/cyan] uv:{uv}")
198
-
199
- # 1. agent 源码
189
+ def _download_agent_sources(install_dir: Path, base_url: str) -> None:
190
+ """Step 1: 下载 agent.zip 并解压(先清旧 .py 防残留)。"""
200
191
  console.print("[cyan]→[/cyan] 下载 agent...")
201
192
  agent_zip = install_dir / "agent.zip"
202
193
  _download(base_url, "agent.zip", agent_zip)
203
194
  for f in install_dir.glob("*.py"):
204
195
  f.unlink(missing_ok=True)
205
- with zipfile.ZipFile(agent_zip) as zf:
206
- zf.extractall(install_dir)
196
+ _safe_extract(agent_zip, install_dir)
207
197
  agent_zip.unlink(missing_ok=True)
208
198
 
209
- # 2. webserver.exe(已存在跳过:静态二进制,运行中会被占用)
199
+
200
+ def _ensure_webserver(install_dir: Path, base_url: str) -> Path:
201
+ """Step 2: 取 webserver.exe 路径;已存在则跳过下载(静态二进制,运行中会被占用)。"""
210
202
  webserver = install_dir / "webserver.exe"
211
203
  if webserver.is_file():
212
204
  console.print(" webserver.exe 已存在,跳过下载")
213
205
  else:
214
206
  console.print("[cyan]→[/cyan] 下载 webserver.exe...")
215
207
  _download(base_url, "webserver.exe", webserver)
208
+ return webserver
216
209
 
217
- # 3. uv 建独立 Python 环境 + 装依赖(先停旧 agent 松开 .venv 文件锁)
210
+
211
+ def _setup_venv(install_dir: Path, uv: str) -> Path:
212
+ """Step 3: 先停旧 agent 松开文件锁,再用 uv 建独立 Python 环境并装依赖。"""
218
213
  _stop_running_agent()
219
214
  console.print("[cyan]→[/cyan] uv 准备 Python 环境 + 装依赖...")
220
215
  venv_dir = install_dir / ".venv"
@@ -233,13 +228,18 @@ def install(project: str) -> None:
233
228
  ],
234
229
  "uv pip install 失败",
235
230
  )
231
+ return venv_py
232
+
236
233
 
237
- # 4. 开机自启 + 立即启动(隐藏窗口)
234
+ def _start_autostart(install_dir: Path, venv_py: Path, webserver: Path) -> None:
235
+ """Step 4: 写开机自启脚本并立即以隐藏窗口启动 agent。"""
238
236
  console.print("[cyan]→[/cyan] 配置开机自启并启动 agent...")
239
237
  vbs = _write_autostart(install_dir, venv_py, webserver)
240
238
  subprocess.run(["wscript", str(vbs)])
241
239
 
242
- # 5. 健康校验 + 取工程路径 → 部署 Unity 脚本
240
+
241
+ def _verify_and_deploy(install_dir: Path, base_url: str) -> None:
242
+ """Step 5: 轮询 agent 健康、取工程路径,再部署 Unity 脚本。"""
243
243
  console.print("[cyan]→[/cyan] 等 agent 就绪...")
244
244
  health = _poll_health()
245
245
  console.print(f" agent 在线(v{health.get('agent_version', '?')})")
@@ -253,6 +253,38 @@ def install(project: str) -> None:
253
253
  console.print(f"[cyan]→[/cyan] 部署 Unity 脚本到工程:{project_path}")
254
254
  _deploy_overlay(install_dir, base_url, project_path)
255
255
 
256
+
257
+ @click.group()
258
+ def engine() -> None:
259
+ """本机引擎实时预览:安装 / 启停。"""
260
+
261
+
262
+ @engine.command()
263
+ @click.argument("project")
264
+ def install(project: str) -> None:
265
+ """安装并启动某项目的引擎实时预览(仅 Windows)。
266
+
267
+ PROJECT 为项目代号,如 heartopia(心动小镇)。不同项目用不同代号;
268
+ 认不出的代号会被拒,避免给错项目装错引擎。
269
+ """
270
+ _require_windows()
271
+ if project not in _SUPPORTED_PROJECTS:
272
+ raise SystemExit(
273
+ f"暂不支持的项目代号:{project}。"
274
+ f"目前支持:{', '.join(sorted(_SUPPORTED_PROJECTS))}。"
275
+ )
276
+ base_url = config.require("base_url")
277
+ install_dir = _install_dir()
278
+ uv = _find_uv()
279
+ console.print(f"[cyan]→[/cyan] 安装目录:{install_dir}")
280
+ console.print(f"[cyan]→[/cyan] uv:{uv}")
281
+
282
+ _download_agent_sources(install_dir, base_url)
283
+ webserver = _ensure_webserver(install_dir, base_url)
284
+ venv_py = _setup_venv(install_dir, uv)
285
+ _start_autostart(install_dir, venv_py, webserver)
286
+ _verify_and_deploy(install_dir, base_url)
287
+
256
288
  console.print(
257
289
  "[green]✓ 引擎实时预览已安装并启动。打开 ArtDAM 点「引擎实时」即可。[/green]"
258
290
  )
@@ -269,6 +301,7 @@ def stop() -> None:
269
301
  @engine.command()
270
302
  def status() -> None:
271
303
  """看本机 agent 是否在线。"""
304
+ _require_windows()
272
305
  try:
273
306
  r = httpx.get(f"http://127.0.0.1:{AGENT_PORT}/health", timeout=3)
274
307
  if r.status_code == 200:
@@ -8,10 +8,17 @@ from artdam_cli import client
8
8
  @click.option("--name", "-n", default=None, help="新文件名")
9
9
  @click.option("--description", "-d", default=None, help="新描述")
10
10
  @click.option("--folder", "-f", type=int, default=None, help="目标文件夹 ID(0 = 移出文件夹)")
11
- def update(asset_id: int, name: str | None, description: str | None, folder: int | None) -> None:
12
- """更新资产:重命名、改描述、移动文件夹。"""
13
- if name is None and description is None and folder is None:
14
- raise SystemExit("请至少指定一个选项:--name / --description / --folder")
11
+ @click.option("--supplier", default=None, help="供应商真名(传空串 = 清空为 null)")
12
+ def update(
13
+ asset_id: int,
14
+ name: str | None,
15
+ description: str | None,
16
+ folder: int | None,
17
+ supplier: str | None,
18
+ ) -> None:
19
+ """更新资产:重命名、改描述、移动文件夹、改供应商。"""
20
+ if name is None and description is None and folder is None and supplier is None:
21
+ raise SystemExit("请至少指定一个选项:--name / --description / --folder / --supplier")
15
22
 
16
23
  if name is not None:
17
24
  client.patch(f"/api/assets/{asset_id}/rename", {"filename": name})
@@ -25,3 +32,8 @@ def update(asset_id: int, name: str | None, description: str | None, folder: int
25
32
  folder_id = folder if folder != 0 else None
26
33
  client.patch(f"/api/assets/{asset_id}/folder", {"folder_id": folder_id})
27
34
  click.echo(f"✓ 已移动到文件夹 {folder_id}")
35
+
36
+ if supplier is not None:
37
+ # 空串 → None:对齐 PATCH /supplier 契约的 null(清空供应商)
38
+ client.patch(f"/api/assets/{asset_id}/supplier", {"supplier_name": supplier or None})
39
+ click.echo("✓ 供应商已更新")
@@ -4,7 +4,7 @@ import sys
4
4
  import click
5
5
 
6
6
  # Windows 终端默认 GBK,强制 UTF-8 避免中文乱码
7
- if hasattr(sys.stdout, "buffer") and sys.stdout.encoding.lower() not in (
7
+ if hasattr(sys.stdout, "buffer") and (sys.stdout.encoding or "").lower() not in (
8
8
  "utf-8",
9
9
  "utf-8-sig",
10
10
  ):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: artdam-cli
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: ArtDAM 数字资产管理平台命令行工具
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "artdam-cli"
7
- version = "0.4.0"
7
+ version = "0.4.2"
8
8
  requires-python = ">=3.10"
9
9
  description = "ArtDAM 数字资产管理平台命令行工具"
10
10
  readme = "README.md"
File without changes
File without changes