77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from src.api.visual_watch import capture_visual_watch_snapshot
|
|
|
|
|
|
def main(env=None) -> int:
|
|
env = os.environ if env is None else env
|
|
output_json = _get_bool(env, "VISUAL_CAPTURE_OUTPUT_JSON", False)
|
|
payload = capture_visual_watch_snapshot(
|
|
watch_run_id=_get_optional_int(env, "VISUAL_CAPTURE_WATCH_RUN_ID"),
|
|
instrument_id=_get_optional_int(env, "VISUAL_CAPTURE_INSTRUMENT_ID"),
|
|
trigger_type=_get_optional_value(env, "VISUAL_CAPTURE_TRIGGER_TYPE"),
|
|
source_name=_get_optional_value(env, "VISUAL_CAPTURE_SOURCE_NAME"),
|
|
output_dir=_get_optional_value(env, "VISUAL_CAPTURE_OUTPUT_DIR"),
|
|
capture_url=_get_optional_value(env, "VISUAL_CAPTURE_URL"),
|
|
browser_capture_enabled=_get_optional_bool(env, "VISUAL_CAPTURE_BROWSER_ENABLED"),
|
|
)
|
|
if output_json:
|
|
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, default=str))
|
|
else:
|
|
print(f"Visual snapshot status: {payload.get('status')}")
|
|
print(f"Watch run: {payload.get('watch_run_id')}")
|
|
if payload.get("snapshot_id") is not None:
|
|
print(f"Snapshot id: {payload.get('snapshot_id')}")
|
|
if payload.get("image_path"):
|
|
print(f"Image path: {payload.get('image_path')}")
|
|
if payload.get("html_path"):
|
|
print(f"HTML path: {payload.get('html_path')}")
|
|
if payload.get("browser_capture_status"):
|
|
print(f"Browser capture: {payload.get('browser_capture_status')}")
|
|
if payload.get("artifact_path"):
|
|
print(f"Artifact path: {payload.get('artifact_path')}")
|
|
if payload.get("reason"):
|
|
print(f"Reason: {payload.get('reason')}")
|
|
return 0 if payload.get("status") not in {"failed"} else 2
|
|
|
|
|
|
def _get_bool(env, key: str, default: bool = False) -> bool:
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return default
|
|
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
def _get_optional_int(env, key: str):
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return None
|
|
return int(value)
|
|
|
|
|
|
def _get_optional_value(env, key: str):
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return None
|
|
return value
|
|
|
|
|
|
def _get_optional_bool(env, key: str):
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return None
|
|
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|