Coverage for src/romfarmer/config/slim_platform.py: 96%

68 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-09-05 02:19 -0700

1"""Slim platform configuration — intrinsic facts only. 

2 

3A SlimPlatformConfig contains ONLY immutable facts about a platform: 

4what it is, where its ROMs come from, how its archives are structured. 

5 

6It explicitly does NOT contain: 

7- Compression settings (build choice) 

8- Target/output paths (target-specific) 

9- Organization style (target-specific) 

10- Selection/filtering (build choice) 

11- enabled flag (build choice) 

12 

13These concerns are handled by Recipes and Targets respectively. 

14""" 

15 

16from pathlib import Path 

17 

18from pydantic import BaseModel, Field 

19 

20from .models import ( 

21 DATSource, 

22 ExtractionType, 

23 SourceConfig, 

24) 

25 

26 

27class ListPatterns(BaseModel): 

28 """List file patterns for a platform. 

29 

30 These describe the naming conventions for keep/delete list files, 

31 which is an intrinsic property of how the platform's curated lists 

32 are organized on disk. 

33 """ 

34 

35 delete: str | None = Field(None, description="Delete list pattern (e.g., 'saturn-delete')") 

36 add_myrient: str | None = Field( 

37 None, description="Myrient additions pattern (e.g., 'saturn+*')" 

38 ) 

39 add_extra: str | None = Field(None, description="Extra additions pattern (e.g., 'saturn.*')") 

40 add: str | None = Field( 

41 None, description="Generic additions pattern (e.g., 'fbneo+*') — arcade style" 

42 ) 

43 

44 

45class DATReference(BaseModel): 

46 """Reference to a DAT file for this platform. 

47 

48 This is intrinsic — it describes which DAT collection this platform 

49 belongs to and how to find its DAT file. 

50 """ 

51 

52 source: DATSource = Field( 

53 description="DAT source type (retool_1g1r_eng, redump_retool_1g1r_eng, fbneo_official, etc.)" 

54 ) 

55 file: Path | None = Field(None, description="Explicit DAT file path (for arcade platforms)") 

56 platform_name: str | None = Field( 

57 None, 

58 description="DAT platform name to search for when it differs from the platform id " 

59 "(e.g. gb2players → 'Nintendo - Game Boy')", 

60 ) 

61 expected_count: int | None = Field(None, description="Expected game count for validation") 

62 match_method: str = Field("hash", description="Match method: 'hash' or 'fuzzy_name'") 

63 version: str | None = Field(None, description="DAT version (for arcade DATs)") 

64 # Arcade-specific DAT filtering 

65 filter_driver: str | None = Field( 

66 None, description="MAME driver name to filter by (e.g., 'naomi')" 

67 ) 

68 filter_romof: str | None = Field(None, description="MAME romof/BIOS to filter by") 

69 exclude_romof: list[str] | None = Field( 

70 None, description="Exclude games with these BIOS dependencies" 

71 ) 

72 name_pattern: str | None = Field(None, description="Glob pattern to filter game names") 

73 exclude_name_pattern: str | None = Field(None, description="Glob pattern to exclude game names") 

74 

75 

76class ArcadeFilter(BaseModel): 

77 """Arcade-specific game filtering configuration. 

78 

79 Intrinsic to the platform — describes which subset of the arcade 

80 ROM set this platform represents. 

81 """ 

82 

83 mode: str = Field(default="relaxed", description="Filter mode: strict, relaxed, permissive") 

84 include_hacks: bool = Field(default=False) 

85 include_bootlegs: bool = Field(default=False) 

86 include_prototypes: bool = Field(default=False) 

87 include_homebrew: bool = Field(default=False) 

88 include_demos: bool = Field(default=False) 

89 include_working_only: bool = Field(default=True) 

90 region_priority: list[str] = Field(default_factory=lambda: ["world", "usa", "europe", "japan"]) 

91 

92 

93class PS3Config(BaseModel): 

94 """PS3-specific intrinsic configuration. 

95 

96 These are facts about how PS3 ROMs need to be processed, 

97 not build choices. 

98 """ 

99 

100 keys_directory: Path | None = Field(None, description="PS3 disc keys directory") 

101 ps3dec_path: Path | None = Field(None, description="Path to PS3Dec tool") 

102 # Updates 

103 nps_database: Path | None = Field(None, description="NoPayStation database path (PS3_DLCS.tsv)") 

104 pkg_archive: Path | None = Field(None, description="PKG archive directory") 

105 use_sony_psn: bool = Field(default=True, description="Check Sony PSN cache for updates") 

106 # DLC 

107 dlc_enabled: bool = Field(default=False) 

108 dlc_mode: str = Field(default="copy", description="DLC mode: copy or extract") 

109 

110 

111class ExtrasConfig(BaseModel): 

112 """Configuration for extras platforms (DLC, updates, NAND content). 

113 

114 Extras platforms produce files organized by install destination, 

115 plus per-frontend install scripts. 

116 """ 

117 

118 destinations: dict[str, str] = Field( 

119 default_factory=dict, 

120 description="Map of subfolder name → filename pattern. " 

121 "Files matching the pattern are sorted into that subfolder.", 

122 ) 

123 install_scripts: dict[str, dict[str, str]] = Field( 

124 default_factory=dict, 

125 description="Per-frontend install script config. " 

126 "Keys are frontend names, values have 'template' and 'description'.", 

127 ) 

128 

129 

130class XboxConfig(BaseModel): 

131 """Xbox/Xbox 360-specific intrinsic configuration.""" 

132 

133 extract_xiso_path: Path | None = Field(None, description="Path to extract-xiso tool") 

134 

135 

136class SlimPlatformConfig(BaseModel): 

137 """Intrinsic facts about a platform. 

138 

139 This model contains ONLY things that are true about the platform itself, 

140 regardless of which build or target is using it. 

141 

142 Naming convention: "slim" because it's the platform config stripped of 

143 all build and target concerns. 

144 """ 

145 

146 # Identity 

147 name: str = Field(description="Platform identifier (e.g., 'saturn', 'nes', 'fbneo')") 

148 display_name: str | None = Field( 

149 None, description="Human-readable name (e.g., 'Nintendo - Game Boy Advance')" 

150 ) 

151 type: str | None = Field( 

152 None, description="Platform type: 'arcade' for arcade systems, None for consoles" 

153 ) 

154 emulator: str | None = Field( 

155 None, description="Emulator name (e.g., 'fbneo', 'mame', 'flycast')" 

156 ) 

157 metadata_system: str | None = Field( 

158 None, 

159 description="System name for metadata lookups (defaults to platform name). " 

160 "Useful for arcade platforms that share MAME metadata.", 

161 ) 

162 

163 # DAT reference 

164 dat: DATReference = Field(description="DAT file reference") 

165 

166 # Sources 

167 sources: list[SourceConfig] = Field(description="Source ROM locations") 

168 chd_sources: list[SourceConfig] | None = Field( 

169 None, description="CHD source locations (arcade platforms with CHD games)" 

170 ) 

171 

172 # Extraction type — intrinsic to the platform's ROM format 

173 extraction: ExtractionType = Field( 

174 default=ExtractionType.NONE, 

175 description="How to extract games from archives: none, cartridge, disc, rvz, ps3, xiso", 

176 ) 

177 

178 # Multi-disc 

179 multi_disc: bool = Field(default=False, description="Platform has multi-disc games") 

180 

181 # List file patterns 

182 list_patterns: ListPatterns | None = Field( 

183 None, description="List file naming patterns for this platform" 

184 ) 

185 

186 # Arcade-specific 

187 arcade_filter: ArcadeFilter | None = Field( 

188 None, description="Arcade game filtering configuration" 

189 ) 

190 bios: list[str] | None = Field(None, description="Required BIOS files (arcade)") 

191 samples_sources: list[SourceConfig] | None = Field( 

192 None, description="Sample audio file sources (FBNeo)" 

193 ) 

194 

195 # PS3-specific 

196 ps3: PS3Config | None = Field(None, description="PS3-specific configuration") 

197 

198 # Xbox-specific 

199 xbox: XboxConfig | None = Field(None, description="Xbox/Xbox 360-specific configuration") 

200 

201 # Extras (DLC/updates) — platforms that produce install-script bundles 

202 extras: ExtrasConfig | None = Field( 

203 None, description="Extras configuration for DLC/updates platforms" 

204 ) 

205 

206 @property 

207 def is_arcade(self) -> bool: 

208 """Check if this is an arcade platform.""" 

209 return self.type == "arcade" 

210 

211 @property 

212 def dat_source(self) -> DATSource: 

213 """Convenience accessor for the DAT source.""" 

214 return self.dat.source 

215 

216 def get_metadata_system(self) -> str: 

217 """Get the system name for metadata lookups.""" 

218 return self.metadata_system or self.name