File: //proc/25636/root/var/packages/SupportService/target/python_modules/action_handler/action_utils.py
import subprocess
import json
from typing import Tuple
def synowebapi(exec_type: str, api: str, version: int, method: str, params: dict = {}, check: bool = True) -> Tuple[int, object]:
cmd = ["/usr/syno/bin/synowebapi", exec_type, f"api={api}", f"version={version}", f"method={method}"]
for param_key, param_value in params.items():
cmd.append(f"{param_key}={json.dumps(param_value)}")
completed_process = subprocess.run(cmd, capture_output=True, check=check)
return completed_process.returncode, json.loads(completed_process.stdout)
def synowebapi_exec(api: str, version: int, method: str, params: dict = {}, check: bool = True) -> Tuple[int, object]:
return synowebapi("--exec", api, version, method, params, check)
def synowebapi_exec_fastwebapi(api: str, version: int, method: str, params: dict = {}, check: bool = True) -> Tuple[int, object]:
return synowebapi("--exec-fastwebapi", api, version, method, params, check)