示例#1
0
    def start(self):
        """Run the thread."""
        for key, value in self.env.items():
            logger.debug("%s=\"%s\"", key, value)
        logger.debug(" ".join(self.wrapper_command))

        if self.terminal:
            terminal = system.find_executable(self.terminal)
            if not terminal:
                logger.error("Couldn't find terminal %s", self.terminal)
                return
            script_path = get_terminal_script(self.wrapper_command, self.cwd,
                                              self.env)
            self.game_process = self.execute_process(
                [terminal, "-e", script_path])
        else:
            env = self.get_child_environment()
            self.game_process = self.execute_process(self.wrapper_command, env)

        if not self.game_process:
            logger.error("No game process available")
            return

        GLib.child_watch_add(self.game_process.pid, self.on_stop)

        # make stdout nonblocking.
        fileno = self.game_process.stdout.fileno()
        fcntl.fcntl(fileno, fcntl.F_SETFL,
                    fcntl.fcntl(fileno, fcntl.F_GETFL) | os.O_NONBLOCK)

        self.stdout_monitor = GLib.io_add_watch(
            self.game_process.stdout,
            GLib.IO_IN | GLib.IO_HUP,
            self.on_stdout_output,
        )
示例#2
0
    def get_wrapper_command(self):
        """Return launch arguments for the wrapper script"""
        wrapper_command = [
            WRAPPER_SCRIPT,
            self._title,
            str(len(self.include_processes)),
            str(len(self.exclude_processes)),
        ] + self.include_processes + self.exclude_processes
        if not self.terminal:
            return wrapper_command + self.command

        terminal_path = system.find_executable(self.terminal)
        if not terminal_path:
            raise RuntimeError("Couldn't find terminal %s" % self.terminal)
        script_path = get_terminal_script(self.command, self.cwd, self.env)
        return wrapper_command + [terminal_path, "-e", script_path]