def log_files(self) -> List[str]: if self._log_files is None: self._log_files = find_logs(self.log_dir, self.game_name) return self._log_files
def test_logs(self): test_files_dir = os.path.normpath(self.root_dir + "/data/logs_similar_names") logs = find_logs(test_files_dir, "GAME_test") self.assertEqual(4, len(logs), "Only 4 log files should be found")
def launch_game(players: List[Player], launch_params: Dict[str, Any], show_all: bool, read_overwrite: bool, wait_callback: Callable) -> None: """ :raises DockerException, ContainerException, RealtimeOutedException """ if not players: raise GameException("at least one player must be specified") # todo: this is a quick fix, do it properly later existing_files = itertools.chain( find_logs(launch_params["log_dir"], launch_params["game_name"]), find_replays(launch_params["map_dir"], launch_params["game_name"]), find_results(launch_params["log_dir"], launch_params["game_name"]), find_frames(launch_params["log_dir"], launch_params["game_name"])) for file_ in existing_files: logger.debug(f"removing existing file {file_}") os.remove(file_) for nth_player, player in enumerate(players): launch_image(player, nth_player=nth_player, num_players=len(players), **launch_params) logger.debug("checking if game has launched properly...") time.sleep(1) start_containers = running_containers(launch_params["game_name"]) if len(start_containers) != len(players): raise DockerException( "some containers exited prematurely, please check logs") if not launch_params["headless"]: for index, player in enumerate(players if show_all else players[:1]): port = launch_params["vnc_base_port"] + index host = launch_params["vnc_host"] logger.info( f"launching vnc viewer for {player} on address {host}:{port}") launch_vnc_viewer(host, port) logger.info( "\n" "In headful mode, you must specify and start the game manually.\n" "Select the map, wait for bots to join the game " "and then start the game.") logger.info( f"waiting until game {launch_params['game_name']} is finished...") running_time = time.time() while True: containers = running_containers(launch_params["game_name"]) if len(containers) == 0: # game finished break if len( containers ) >= 2: # update the last time when there were multiple containers running_time = time.time() if len(containers) == 1 and time.time( ) - running_time > MAX_TIME_RUNNING_SINGLE_CONTAINER: raise ContainerException( f"One lingering container has been found after single container " f"timeout ({MAX_TIME_RUNNING_SINGLE_CONTAINER} sec), the game probably crashed." ) logger.debug(f"waiting. {containers}") wait_callback() exit_codes = [container_exit_code(container) for container in containers] # remove containers before throwing exception logger.debug("removing game containers") remove_game_containers(launch_params["game_name"]) if any(exit_code == EXIT_CODE_REALTIME_OUTED for exit_code in exit_codes): raise RealtimeOutedException( f"some of the game containers has realtime outed.") if any(exit_code == 1 for exit_code in exit_codes): raise ContainerException( f"some of the game containers has finished with error exit code.") if read_overwrite: logger.info("overwriting bot files") for nth_player, player in enumerate(players): if isinstance(player, BotPlayer): logger.debug(f"overwriting files for {player}") distutils.dir_util.copy_tree( f"{player.write_dir}/{launch_params['game_name']}_{nth_player}", player.read_dir)