def parse(cls, gm_id, config: ConfigFile): steam_id = config.get_val(gm_id, 'SteamID', '<none>') if not steam_id.isdigit(): raise ValueError('Game {} has invalid Steam ID: {}'.format( gm_id, steam_id)) folder = config.get_val(gm_id, 'Dir', '') if not folder: raise ValueError('Game {} has no folder!'.format(gm_id)) mod_times = {} for name, value in config.items(gm_id): if name.startswith('pack_mod_'): mod_times[name[9:].casefold()] = srctools.conv_int(value) return cls(gm_id, steam_id, folder, mod_times)
def parse(cls, gm_id: str, config: ConfigFile) -> 'Game': """Parse out the given game ID from the config file.""" steam_id = config.get_val(gm_id, 'SteamID', '<none>') if not steam_id.isdigit(): raise ValueError(f'Game {gm_id} has invalid Steam ID: {steam_id}') folder = config.get_val(gm_id, 'Dir', '') if not folder: raise ValueError(f'Game {gm_id} has no folder!') if not os.path.exists(folder): raise ValueError( f'Folder {folder} does not exist for game {gm_id}!') mod_times = {} for name, value in config.items(gm_id): if name.startswith('pack_mod_'): mod_times[name[9:].casefold()] = srctools.conv_int(value) return cls(gm_id, steam_id, folder, mod_times)