deepflow-opendesk-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.
- deepflow_opendesk_cli/__init__.py +3 -0
- deepflow_opendesk_cli/__main__.py +7 -0
- deepflow_opendesk_cli/batch.py +53 -0
- deepflow_opendesk_cli/cli.py +696 -0
- deepflow_opendesk_cli/client.py +323 -0
- deepflow_opendesk_cli/profiles.py +91 -0
- deepflow_opendesk_cli/schema.py +384 -0
- deepflow_opendesk_cli/workflows.py +37 -0
- deepflow_opendesk_cli-0.1.0.dist-info/METADATA +152 -0
- deepflow_opendesk_cli-0.1.0.dist-info/RECORD +13 -0
- deepflow_opendesk_cli-0.1.0.dist-info/WHEEL +5 -0
- deepflow_opendesk_cli-0.1.0.dist-info/entry_points.txt +2 -0
- deepflow_opendesk_cli-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""JSONL batch helpers for OpenDesk CLI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from .client import CliError, HttpResult
|
|
11
|
+
|
|
12
|
+
OperationRunner = Callable[[dict[str, Any]], HttpResult]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def load_jsonl(path: str | Path) -> list[dict[str, Any]]:
|
|
16
|
+
"""Load batch operations from a JSONL file."""
|
|
17
|
+
operations: list[dict[str, Any]] = []
|
|
18
|
+
for lineno, raw in enumerate(Path(path).read_text(encoding="utf-8").splitlines(), start=1):
|
|
19
|
+
line = raw.strip()
|
|
20
|
+
if not line or line.startswith("#"):
|
|
21
|
+
continue
|
|
22
|
+
try:
|
|
23
|
+
payload = json.loads(line)
|
|
24
|
+
except json.JSONDecodeError as exc:
|
|
25
|
+
raise CliError(f"Invalid JSONL at line {lineno}: {exc.msg}") from exc
|
|
26
|
+
if not isinstance(payload, dict):
|
|
27
|
+
raise CliError(f"Batch line {lineno} must be a JSON object")
|
|
28
|
+
operations.append(payload)
|
|
29
|
+
return operations
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def run_batch(
|
|
33
|
+
operations: list[dict[str, Any]],
|
|
34
|
+
runner: OperationRunner,
|
|
35
|
+
*,
|
|
36
|
+
continue_on_error: bool = False,
|
|
37
|
+
) -> list[dict[str, Any]]:
|
|
38
|
+
"""Run operations through a callback and return structured line results."""
|
|
39
|
+
results: list[dict[str, Any]] = []
|
|
40
|
+
for index, operation in enumerate(operations, start=1):
|
|
41
|
+
try:
|
|
42
|
+
result = runner(operation)
|
|
43
|
+
item = {"index": index, **result.to_dict()}
|
|
44
|
+
except Exception as exc: # noqa: BLE001 - batch output should capture user-facing failures.
|
|
45
|
+
item = {"index": index, "ok": False, "error": str(exc), "operation": operation}
|
|
46
|
+
results.append(item)
|
|
47
|
+
if not continue_on_error:
|
|
48
|
+
break
|
|
49
|
+
continue
|
|
50
|
+
results.append(item)
|
|
51
|
+
if not result.ok and not continue_on_error:
|
|
52
|
+
break
|
|
53
|
+
return results
|