(self)
| 228 | set_env("UMU_CONTAINER_NSENTER", "1") |
| 229 | |
| 230 | def execute_final_command(self): |
| 231 | |
| 232 | def start_and_watch(cmd, is_game=False): |
| 233 | log_file = None |
| 234 | if self.enable_logging: |
| 235 | log_path = Path(logs_dir) / self.log_dir |
| 236 | log_path.mkdir(parents=True, exist_ok=True) |
| 237 | log_file = open(log_path / "umu.log", "a", encoding="utf-8") |
| 238 | |
| 239 | process = subprocess.Popen( |
| 240 | cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 241 | bufsize=8192, text=True |
| 242 | ) |
| 243 | |
| 244 | def watch_stream(stream, lf=None): |
| 245 | for line in iter(stream.readline, ""): |
| 246 | clean_line = re.sub(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])', '', line).strip() |
| 247 | |
| 248 | if lf: |
| 249 | lf.write(f"{clean_line}\n") |
| 250 | lf.flush() |
| 251 | |
| 252 | self.check_game_output(clean_line) |
| 253 | |
| 254 | if os.environ.get("GAMEID") == "winetricks-gui": |
| 255 | GLib.idle_add(self.append_to_text_view, clean_line) |
| 256 | else: |
| 257 | print(line, end="") |
| 258 | stream.close() |
| 259 | |
| 260 | threads = [ |
| 261 | Thread(target=watch_stream, args=(process.stdout, log_file), daemon=True), |
| 262 | Thread(target=watch_stream, args=(process.stderr, log_file), daemon=True) |
| 263 | ] |
| 264 | for t in threads: t.start() |
| 265 | |
| 266 | if is_game: |
| 267 | self.process = process |
| 268 | GLib.child_watch_add(GLib.PRIORITY_DEFAULT, process.pid, self.on_process_exit) |
| 269 | Thread(target=self._watch_game_process, daemon=True).start() |
| 270 | if log_file: |
| 271 | def close_log_later(): |
| 272 | for t in threads: |
| 273 | t.join(timeout=5) |
| 274 | log_file.flush() |
| 275 | log_file.close() |
| 276 | Thread(target=close_log_later, daemon=True).start() |
| 277 | else: |
| 278 | process.wait() |
| 279 | for t in threads: t.join(timeout=1) |
| 280 | if log_file: |
| 281 | log_file.close() |
| 282 | |
| 283 | popen_prefix = [] |
| 284 | if os.environ.get("PREVENT_SLEEP"): |
| 285 | try: |
| 286 | import dbus |
| 287 | iface = dbus.Interface(dbus.SessionBus().get_object("org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop"), "org.freedesktop.portal.Inhibit") |
no test coverage detected