licos-platform-cli 0.1.0__py3-none-any.whl
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.
|
@@ -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,6 @@
|
|
|
1
|
+
licos_platform_cli/__init__.py,sha256=fXR6_CuIYynV4wmoflnujz6yIvrCEDUcebsHQu4RxCY,19
|
|
2
|
+
licos_platform_cli/main.py,sha256=n27d929sC7S9ir_s3wb_RG1qKhXUC6vpSd8vv_H-1uo,3269
|
|
3
|
+
licos_platform_cli-0.1.0.dist-info/METADATA,sha256=Lkyc1iB4zooS08S4AEMn53h6ADen-bLxSxRH0lbw0ww,178
|
|
4
|
+
licos_platform_cli-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
5
|
+
licos_platform_cli-0.1.0.dist-info/entry_points.txt,sha256=MeUDDEVRJdEMDYpCPLxJ5NRjxiPL1oEtG1-1EBslDac,64
|
|
6
|
+
licos_platform_cli-0.1.0.dist-info/RECORD,,
|