licos-platform-cli 0.1.0__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.
- licos_platform_cli-0.1.0/.gitignore +44 -0
- licos_platform_cli-0.1.0/PKG-INFO +6 -0
- licos_platform_cli-0.1.0/pyproject.toml +18 -0
- licos_platform_cli-0.1.0/src/licos_platform_cli/__init__.py +1 -0
- licos_platform_cli-0.1.0/src/licos_platform_cli/main.py +95 -0
- licos_platform_cli-0.1.0/tests/test_cli.py +54 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Rust
|
|
2
|
+
/target/
|
|
3
|
+
**/*.rs.bk
|
|
4
|
+
Cargo.lock
|
|
5
|
+
|
|
6
|
+
# Node
|
|
7
|
+
node_modules/
|
|
8
|
+
packages/*/dist/
|
|
9
|
+
|
|
10
|
+
# IDE
|
|
11
|
+
.idea/
|
|
12
|
+
.vscode/
|
|
13
|
+
*.swp
|
|
14
|
+
*.swo
|
|
15
|
+
|
|
16
|
+
# OS
|
|
17
|
+
.DS_Store
|
|
18
|
+
Thumbs.db
|
|
19
|
+
|
|
20
|
+
# Environment
|
|
21
|
+
.env
|
|
22
|
+
.env.local
|
|
23
|
+
|
|
24
|
+
# Workspace
|
|
25
|
+
/workspace/
|
|
26
|
+
|
|
27
|
+
# Test runtime data
|
|
28
|
+
/test/licos-data/
|
|
29
|
+
/test/screenshots/
|
|
30
|
+
/test/vue-app/
|
|
31
|
+
|
|
32
|
+
# Build
|
|
33
|
+
*.log
|
|
34
|
+
.licos
|
|
35
|
+
|
|
36
|
+
/tmp
|
|
37
|
+
|
|
38
|
+
/Docs/hermes-agent
|
|
39
|
+
/Docs/OpenCode
|
|
40
|
+
/Docs/平台API
|
|
41
|
+
|
|
42
|
+
*.codex-*
|
|
43
|
+
|
|
44
|
+
project-20260423_130440
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "licos-platform-cli"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "LICOS platform CLI for storage operations"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"licos-platform-sdk>=0.1.0",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[project.scripts]
|
|
15
|
+
licos-platform = "licos_platform_cli.main:main"
|
|
16
|
+
|
|
17
|
+
[tool.hatch.build.targets.wheel]
|
|
18
|
+
packages = ["src/licos_platform_cli"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__all__ = ["main"]
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Sequence
|
|
7
|
+
|
|
8
|
+
from licos_platform_sdk import download, download_url, preview_url, upload_project, upload_user
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
12
|
+
parser = argparse.ArgumentParser(prog="licos-platform")
|
|
13
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
14
|
+
|
|
15
|
+
storage = subparsers.add_parser("storage", help="Platform storage operations")
|
|
16
|
+
storage_subparsers = storage.add_subparsers(dest="storage_command", required=True)
|
|
17
|
+
|
|
18
|
+
upload_user_cmd = storage_subparsers.add_parser("upload-user", help="Upload into the user bucket")
|
|
19
|
+
upload_user_cmd.add_argument("file", help="File path to upload")
|
|
20
|
+
|
|
21
|
+
upload_project_cmd = storage_subparsers.add_parser(
|
|
22
|
+
"upload-project",
|
|
23
|
+
help="Upload into the current user's project bucket",
|
|
24
|
+
)
|
|
25
|
+
upload_project_cmd.add_argument("file", help="File path to upload")
|
|
26
|
+
upload_project_cmd.add_argument("--project-id", help="Override LICOS_PROJECT_ID")
|
|
27
|
+
upload_project_cmd.add_argument("--user-id", help="Override LICOS_USER_ID")
|
|
28
|
+
|
|
29
|
+
preview_url_cmd = storage_subparsers.add_parser("preview-url", help="Build a public preview URL")
|
|
30
|
+
preview_url_cmd.add_argument("bucket", help="Bucket name")
|
|
31
|
+
preview_url_cmd.add_argument("object_key", help="Object key")
|
|
32
|
+
|
|
33
|
+
download_url_cmd = storage_subparsers.add_parser("download-url", help="Build a public download URL")
|
|
34
|
+
download_url_cmd.add_argument("bucket", help="Bucket name")
|
|
35
|
+
download_url_cmd.add_argument("object_key", help="Object key")
|
|
36
|
+
|
|
37
|
+
download_cmd = storage_subparsers.add_parser("download", help="Download a public file URL to disk")
|
|
38
|
+
download_cmd.add_argument("url", help="Public storage URL")
|
|
39
|
+
download_cmd.add_argument("--output", required=True, help="Destination path")
|
|
40
|
+
|
|
41
|
+
return parser
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _print_json(payload: dict) -> None:
|
|
45
|
+
print(json.dumps(payload, ensure_ascii=False))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
49
|
+
parser = _build_parser()
|
|
50
|
+
args = parser.parse_args(argv)
|
|
51
|
+
|
|
52
|
+
if args.command != "storage":
|
|
53
|
+
parser.error(f"Unsupported command: {args.command}")
|
|
54
|
+
|
|
55
|
+
if args.storage_command == "upload-user":
|
|
56
|
+
result = upload_user(args.file)
|
|
57
|
+
_print_json(result.to_dict())
|
|
58
|
+
return 0
|
|
59
|
+
|
|
60
|
+
if args.storage_command == "upload-project":
|
|
61
|
+
result = upload_project(
|
|
62
|
+
args.file,
|
|
63
|
+
project_id=args.project_id,
|
|
64
|
+
user_id=args.user_id,
|
|
65
|
+
)
|
|
66
|
+
_print_json(result.to_dict())
|
|
67
|
+
return 0
|
|
68
|
+
|
|
69
|
+
if args.storage_command == "preview-url":
|
|
70
|
+
_print_json(
|
|
71
|
+
{
|
|
72
|
+
"preview_url": preview_url(args.bucket, args.object_key),
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
return 0
|
|
76
|
+
|
|
77
|
+
if args.storage_command == "download-url":
|
|
78
|
+
_print_json(
|
|
79
|
+
{
|
|
80
|
+
"download_url": download_url(args.bucket, args.object_key),
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
return 0
|
|
84
|
+
|
|
85
|
+
if args.storage_command == "download":
|
|
86
|
+
saved_path = download(args.url, Path(args.output))
|
|
87
|
+
_print_json({"path": str(saved_path)})
|
|
88
|
+
return 0
|
|
89
|
+
|
|
90
|
+
parser.error(f"Unsupported storage command: {args.storage_command}")
|
|
91
|
+
return 2
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
if __name__ == "__main__":
|
|
95
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
import tempfile
|
|
8
|
+
import unittest
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PlatformCliTests(unittest.TestCase):
|
|
13
|
+
def test_upload_project_command_prints_json(self) -> None:
|
|
14
|
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
15
|
+
file_path = Path(tmp_dir) / "demo.txt"
|
|
16
|
+
file_path.write_text("hello world", encoding="utf-8")
|
|
17
|
+
env = os.environ.copy()
|
|
18
|
+
env["PYTHONPATH"] = os.pathsep.join(
|
|
19
|
+
[
|
|
20
|
+
str(Path(__file__).resolve().parents[2] / "licos-platform-sdk" / "src"),
|
|
21
|
+
str(Path(__file__).resolve().parents[1] / "src"),
|
|
22
|
+
env.get("PYTHONPATH", ""),
|
|
23
|
+
]
|
|
24
|
+
).strip(os.pathsep)
|
|
25
|
+
env["LICOS_ORCHESTRATOR_API_BASE_URL"] = "http://127.0.0.1:9"
|
|
26
|
+
env["LICOS_USER_TOKEN"] = "jwt-token"
|
|
27
|
+
env["LICOS_USER_ID"] = "demo-user"
|
|
28
|
+
env["LICOS_PROJECT_ID"] = "demo-project"
|
|
29
|
+
|
|
30
|
+
proc = subprocess.run(
|
|
31
|
+
[
|
|
32
|
+
sys.executable,
|
|
33
|
+
"-m",
|
|
34
|
+
"licos_platform_cli.main",
|
|
35
|
+
"storage",
|
|
36
|
+
"preview-url",
|
|
37
|
+
"demo-bucket",
|
|
38
|
+
"folder/report.txt",
|
|
39
|
+
],
|
|
40
|
+
capture_output=True,
|
|
41
|
+
check=True,
|
|
42
|
+
text=True,
|
|
43
|
+
env=env,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
payload = json.loads(proc.stdout)
|
|
47
|
+
self.assertEqual(
|
|
48
|
+
payload["preview_url"],
|
|
49
|
+
"http://127.0.0.1:9/api/v1/public/storage/demo-bucket/folder/report.txt",
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if __name__ == "__main__":
|
|
54
|
+
unittest.main()
|