async def add_map(self, filename, insert=True, save_matchsettings=True): """ Add or insert map to current online playlist. :param filename: Load from filename relative to the 'Maps' directory on the dedicated host server. :param insert: Insert after the current map, this will make it play directly after the current map. True by default. :param save_matchsettings: Save match settings as well. :type filename: str :type insert: bool :type save_matchsettings: bool :raise: pyplanet.contrib.map.exceptions.MapIncompatible :raise: pyplanet.contrib.map.exceptions.MapException """ gbx_method = 'InsertMap' if insert else 'AddMap' try: result = await self._instance.gbx(gbx_method, filename) except Fault as e: if 'unknown' in e.faultString: raise MapNotFound('Map is not found on the server.') elif 'already' in e.faultString: raise MapException('Map already added to server.') raise MapException(e.faultString) # Try to save match settings. try: if save_matchsettings: await self.save_matchsettings() except Exception as e: handle_exception(e, __name__, 'add_map', extra_data={'EXTRAHOOK': 'Map Insert bug, see #306'}) return result
async def get_map_by_index(self, index): """ Get map instance by index id (primary key). :param index: Primary key index. :return: Map instance or raise exception. """ try: return await Map.get(id=index) except DoesNotExist: raise MapNotFound('Map not found.')
async def get_map(self, uid=None): """ Get map instance by uid. :param uid: By uid (pk). :return: Player or exception if not found """ try: return await Map.get_by_uid(uid) except DoesNotExist: raise MapNotFound('Map not found.')
async def remove_map(self, map, delete_file=False): """ Remove and optionally delete file from server and playlist. :param map: Map instance or filename in string. :param delete_file: Boolean to decide if we are going to remove the file from the server too. Defaults to False. :type delete_file: bool :raise: pyplanet.contrib.map.exceptions.MapException :raise: pyplanet.core.storage.exceptions.StorageException """ if isinstance(map, Map): map = map.file if not isinstance(map, str): raise ValueError('Map must be instance or string uid!') try: success = await self._instance.gbx('RemoveMap', map) if success: the_map = None for m in self._maps: if m.file == map: the_map = m break if the_map: self._maps.remove(the_map) except Fault as e: if 'unknown' in e.faultString: raise MapNotFound( 'Dedicated can\'t find map. Already removed?') raise MapException( 'Error when removing map from playlist: {}'.format( e.faultString)) # Try to save match settings. try: await self.save_matchsettings() except: pass # Delete the actual file. if delete_file: try: await self._instance.storage.remove_map(map) except: raise MapException( 'Can\'t delete map file after removing from playlist.')