def inject_silent_crash_report() -> bool: """ Injects code needed for the new login method in MissionEditor.lua :return: success of the operation :rtype: bool """ FS.ensure_path(FS.saved_games_path, 'saved games') autoexec_path = FS.ensure_path(FS.dcs_autoexec_file, 'dcs autoexec file', must_exist=False) utils.create_versioned_backup(autoexec_path, file_must_exist=False) if autoexec_path.exists(): LOGGER.debug('autoexec.cfg already exists, reading') content = autoexec_path.read_text(encoding='utf8') else: LOGGER.debug('autoexec.cfg does not exist, creating') content = '' if _SILENT_CRASH_REPORT in content: LOGGER.debug('silent crash report already enabled') return True content = f'{content}{_SILENT_CRASH_REPORT}' LOGGER.debug('writing new "autoexec.cfg" content: %s', content) autoexec_path.write_text(content) return True
def test_variant_open_beta_missing(): variant = Path('./DCS/dcs_variant.txt') variant.write_text('openbeta') with pytest.raises(FileNotFoundError) as exc: FS.get_saved_games_variant() assert str(exc).endswith('Saved Games\\DCS.openbeta')
def test_ensure_path(): FS.saved_games_path = None with pytest.raises(RuntimeError): # noinspection PyTypeChecker FS.ensure_path(FS.saved_games_path, 'test') with pytest.raises(FileNotFoundError): FS.ensure_path('./test', 'test')
def test_variant_open_beta(): variant = Path('./DCS/dcs_variant.txt') variant.write_text('openbeta') Path('./Saved Games/DCS.openbeta').mkdir() assert isinstance(FS.get_saved_games_variant('./DCS'), Path)
def test_base_variant(): variant = FS.get_saved_games_variant() assert isinstance(variant, Path) expected = Path('Saved Games/DCS').absolute() assert variant.samefile(expected)
def test_no_dcs_dir(): Path('./DCS').rmdir() with pytest.raises(FileNotFoundError) as exc: FS.get_saved_games_variant('./DCS') assert str(exc).endswith('\\DCS')
def test_saved_games_not_found(): Path('./Saved Games/DCS').rmdir() Path('./Saved Games').rmdir() with pytest.raises(FileNotFoundError) as exc: FS.get_saved_games_variant() assert str(exc).endswith('Saved Games')
def main(debug: bool): # pylint: disable=too-many-locals """ Main entry point Args: debug: show more verbose console output """ from esst import __version__, LOGGER, LOGGING_CONSOLE_HANDLER, config config.init() from esst.core import CTX from esst import ESSTConfig, DiscordBotConfig, DCSConfig, ListenerConfig, ServerConfig from esst.sentry.sentry import SENTRY SENTRY.register_context('App context', CTX) CTX.sentry = SENTRY _setup_logging_debug(__version__, LOGGER, LOGGING_CONSOLE_HANDLER, debug, ESSTConfig.DEBUG()) LOGGER.debug('instantiating main event loop') loop = asyncio.get_event_loop() CTX.loop = loop _check_wan_and_start_wan_monitor(loop, LOGGER, CTX) CTX.start_discord_loop = DiscordBotConfig.DISCORD_START_BOT() CTX.start_server_loop = ServerConfig.SERVER_START_LOOP() CTX.start_dcs_loop = DCSConfig.DCS_START_LOOP() CTX.start_listener_loop = ListenerConfig.LISTENER_START_LOOP() if not DCSConfig.DCS_CAN_START(): CTX.dcs_blocker.append('config') CTX.dcs_setup_dedi_config = DCSConfig.DCS_INSTALL_DEDICATED_CONFIG() CTX.dcs_install_hooks = DCSConfig.DCS_INSTALL_HOOKS() CTX.dcs_auto_mission = DCSConfig.DCS_AUTO_MISSION_ENABLE() loop = asyncio.get_event_loop() # loop.set_debug(True) CTX.discord_msg_queue = queue.Queue() _set_console_title(__version__) from esst import FS FS.init() from esst.utils import clean_all_folder, assign_ports clean_all_folder() assign_ports() _init_atis_module() import esst.discord_bot.discord_bot discord_loop = esst.discord_bot.discord_bot.App() from esst.dcs import dcs dcs_loop = dcs.App() from esst.server import server server_loop = server.App() from esst.listener.listener import DCSListener listener_loop = DCSListener() futures = asyncio.gather( loop.create_task(discord_loop.run()), loop.create_task(dcs_loop.run()), loop.create_task(listener_loop.run()), loop.create_task(server_loop.run()), loop.create_task(watch_for_exceptions()), ) import signal signal.signal(signal.SIGINT, sigint_handler) loop.run_until_complete(futures) LOGGER.debug('main loop is done, killing DCS') futures = asyncio.gather( # type: ignore loop.create_task(dcs_loop.kill_running_app()), loop.create_task(listener_loop.run_until_dcs_is_closed()), ) loop.run_until_complete(futures) LOGGER.debug('all done !')