예제 #1
0
    def __init__(self) -> None:
        self._config_path = 'config.yaml'
        self._user_provided_config_path = False
        self._config = ServerConfig()
        self._ba_root_path = os.path.abspath('dist/ba_root')
        self._interactive = sys.stdin.isatty()
        self._wrapper_shutdown_desired = False
        self._done = False
        self._subprocess_commands: List[Union[str, ServerCommand]] = []
        self._subprocess_commands_lock = Lock()
        self._subprocess_force_kill_time: Optional[float] = None
        self._auto_restart = True
        self._config_auto_restart = True
        self._config_mtime: Optional[float] = None
        self._last_config_mtime_check_time: Optional[float] = None
        self._should_report_subprocess_error = False
        self._running = False
        self._interpreter_start_time: Optional[float] = None
        self._subprocess: Optional[subprocess.Popen[bytes]] = None
        self._subprocess_launch_time: Optional[float] = None
        self._subprocess_sent_config_auto_restart = False
        self._subprocess_sent_clean_exit = False
        self._subprocess_sent_unclean_exit = False
        self._subprocess_thread: Optional[Thread] = None
        self._subprocess_exited_cleanly: Optional[bool] = None

        # This may override the above defaults.
        self._parse_command_line_args()

        # Do an initial config-load. If the config is invalid at this point
        # we can cleanly die (we're more lenient later on reloads).
        self.load_config(strict=True, print_confirmation=False)
예제 #2
0
    def _load_config_from_file(self, print_confirmation: bool) -> ServerConfig:

        out: Optional[ServerConfig] = None

        if not os.path.exists(self._config_path):

            # Special case:
            # If the user didn't specify a particular config file, allow
            # gracefully falling back to defaults if the default one is
            # missing.
            if not self._user_provided_config_path:
                if print_confirmation:
                    print(
                        f'{Clr.YLW}Default config file not found'
                        f' (\'{self._config_path}\'); using default'
                        f' settings.{Clr.RST}',
                        flush=True)
                self._config_mtime = None
                self._last_config_mtime_check_time = time.time()
                return ServerConfig()

            # Don't be so lenient if the user pointed us at one though.
            raise RuntimeError(
                f"Config file not found: '{self._config_path}'.")

        import yaml
        with open(self._config_path) as infile:
            user_config_raw = yaml.safe_load(infile.read())

        # An empty config file will yield None, and that's ok.
        if user_config_raw is not None:
            out = dataclass_from_dict(ServerConfig, user_config_raw)

        # Update our known mod-time since we know it exists.
        self._config_mtime = Path(self._config_path).stat().st_mtime
        self._last_config_mtime_check_time = time.time()

        # Go with defaults if we weren't able to load anything.
        if out is None:
            out = ServerConfig()

        if print_confirmation:
            print(f'{Clr.CYN}Valid server config file loaded.{Clr.RST}',
                  flush=True)
        return out
예제 #3
0
    def _load_config(self) -> ServerConfig:
        user_config_path = 'config.yaml'

        if os.path.exists(user_config_path):
            import yaml
            with open(user_config_path) as infile:
                user_config_raw = yaml.safe_load(infile.read())

            # An empty config file will yield None, and that's ok.
            if user_config_raw is not None:
                return dataclass_from_dict(ServerConfig, user_config_raw)

        # Go with defaults if we weren't able to load anything.
        return ServerConfig()
예제 #4
0
    def _load_config(self) -> ServerConfig:
        user_config_path = 'config.yaml'

        # Start with a default config, and if there is a config.yaml,
        # assign whatever is contained within.
        config = ServerConfig()
        if os.path.exists(user_config_path):
            import yaml
            with open(user_config_path) as infile:
                user_config = yaml.safe_load(infile.read())

            # An empty config file will yield None, and that's ok.
            if user_config is not None:
                dataclass_assign(config, user_config)

        return config