music-assistant-server

905 BPY
helpers.py
905 B33 lines • python
1"""Helpers/utils for Ariacast Receiver plugin."""
2
3from __future__ import annotations
4
5import os
6import platform
7import stat
8from pathlib import Path
9
10
11def _get_binary_path() -> str:
12    """Locate the correct binary for the current OS/Arch."""
13    base_dir = os.path.join(os.path.dirname(__file__), "bin")
14    system = platform.system().lower()
15    machine = platform.machine().lower()
16
17    if machine in ("x86_64", "amd64"):
18        arch = "amd64"
19    elif machine in ("aarch64", "arm64"):
20        arch = "arm64"
21    else:
22        raise RuntimeError(f"Unsupported architecture: {machine}")
23
24    binary_name = f"ariacast_{system}_{arch}"
25    binary_path = os.path.join(base_dir, binary_name)
26
27    if not os.path.exists(binary_path):
28        raise FileNotFoundError(f"Binary not found at {binary_path}")
29
30    Path(binary_path).chmod(Path(binary_path).stat().st_mode | stat.S_IEXEC)
31
32    return binary_path
33