Coverage for src/ph/targets.py: 100.0%

18 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-28 08:17 +0000

1"""Linux distribution targets supported by the portable application core.""" 

2 

3from dataclasses import dataclass 

4from pathlib import Path 

5 

6type TargetId = str 

7type CpuArchitecture = str 

8 

9 

10class TargetError(ValueError): 

11 """A requested operating-system target is not registered.""" 

12 

13 

14@dataclass(frozen=True, slots=True) 

15class LinuxTarget: 

16 """OS integration points kept outside store and library workflows.""" 

17 

18 target_id: TargetId 

19 display_name: str 

20 tested: bool 

21 architecture: CpuArchitecture 

22 elf_class: int 

23 elf_machine: int 

24 rom_roots: tuple[Path, ...] 

25 tools_directory: str 

26 launcher_name: str 

27 application_directory: str 

28 executable_name: str 

29 update_staging_directory: str 

30 refresh_marker_environment: str 

31 platform_profile: str 

32 

33 def release_asset_name(self, version: str) -> str: 

34 """Return the exact self-contained bundle name for this target.""" 

35 

36 return f"pocket-harbor-{version}-{self.target_id}-{self.architecture}.zip" 

37 

38 

39DARKOS = LinuxTarget( 

40 target_id="darkos", 

41 display_name="DarkOS", 

42 tested=True, 

43 architecture="arm64", 

44 elf_class=2, 

45 elf_machine=183, 

46 rom_roots=(Path("/roms2"), Path("/roms")), 

47 tools_directory="tools", 

48 launcher_name="Pocket Harbor.sh", 

49 application_directory="pocket-harbor", 

50 executable_name="pocket-harbor", 

51 update_staging_directory=".pocket-harbor-update", 

52 refresh_marker_environment="PH_ES_REFRESH_FILE", 

53 platform_profile="darkos", 

54) 

55 

56TARGETS: tuple[LinuxTarget, ...] = (DARKOS,) 

57 

58 

59def resolve_target(value: str) -> LinuxTarget: 

60 """Resolve a configured target and fail clearly for unimplemented distributions.""" 

61 

62 normalized = value.strip().casefold() 

63 target = next((item for item in TARGETS if item.target_id == normalized), None) 

64 if target is None: 

65 supported = ", ".join(item.target_id for item in TARGETS) 

66 raise TargetError(f"Unknown Linux target {value!r}; available targets: {supported}.") 

67 return target