Files
romm/backend/handler/device_install/policy.py
Georges-Antoine Assi 673c1b1052 refactor(device): nest device endpoints, responses and install handler in packages
- endpoints/device.py, device_install.py -> endpoints/device/__init__.py, install.py
- endpoints/responses/device.py, device_install.py -> endpoints/responses/device/__init__.py, install.py
- handler/device_install_handler.py, device_install_policy.py -> handler/device_install/__init__.py, policy.py

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 15:55:42 -04:00

43 lines
1.4 KiB
Python

"""Which roms, and which of their files, a user may push to a device."""
from collections.abc import Sequence
from typing import Final
from config import DEVICE_INSTALL_EXCLUDED_PLATFORM_SLUGS
from models.rom import RomFile, RomFileCategory
# None is an uncategorized root file. Documents reach a device through its own
# manual/walkthrough download.
INSTALLABLE_FILE_CATEGORIES: Final = frozenset(
{None, RomFileCategory.GAME, RomFileCategory.UPDATE, RomFileCategory.DLC}
)
REMOTE_INSTALL_CAPABILITY: Final = "remote_install"
class InstallNotAllowedError(Exception):
"""The rom has nothing that can be pushed to a device."""
def is_installable_platform(platform_slug: str) -> bool:
return platform_slug.lower() not in DEVICE_INSTALL_EXCLUDED_PLATFORM_SLUGS
def accepts_remote_install(capabilities: dict[str, bool] | None) -> bool:
return (capabilities or {}).get(REMOTE_INSTALL_CAPABILITY) is True
def select_install_files(files: Sequence[RomFile]) -> list[int]:
"""The ids of the rom's game, update and DLC files on disk, ascending.
Raises:
InstallNotAllowedError: None of the rom's files qualify.
"""
selected = sorted(
f.id
for f in files
if f.category in INSTALLABLE_FILE_CATEGORIES and not f.missing_from_fs
)
if not selected:
raise InstallNotAllowedError("This rom has no installable files")
return selected