From d45643071470d01bfad6372e5e33c41a0731c915 Mon Sep 17 00:00:00 2001 From: Faraphel Date: Sun, 10 Jul 2022 23:56:10 +0200 Subject: [PATCH] made universal_newlines parameter in _run_popen optional --- source/wt/__init__.py | 6 +++--- source/wt/wit.py | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/source/wt/__init__.py b/source/wt/__init__.py index 9919144..10b6995 100644 --- a/source/wt/__init__.py +++ b/source/wt/__init__.py @@ -92,7 +92,7 @@ def _run_dict(tools_path: Path | str, *args) -> dict: return d -def _run_popen(tools_path: Path | str, *args) -> subprocess.Popen: +def _run_popen(tools_path: Path | str, *args, universal_newlines=False) -> subprocess.Popen: """ Run a command and return the process :param args: command arguments @@ -103,6 +103,6 @@ def _run_popen(tools_path: Path | str, *args) -> subprocess.Popen: stdin=subprocess.PIPE, stdout=subprocess.PIPE, creationflags=subprocess.CREATE_NO_WINDOW, - bufsize=1, - universal_newlines=True, + bufsize=1 if universal_newlines else None, + universal_newlines=universal_newlines, ) diff --git a/source/wt/wit.py b/source/wt/wit.py index 584b3d7..0301d2f 100644 --- a/source/wt/wit.py +++ b/source/wt/wit.py @@ -19,13 +19,13 @@ def _tools_run(*args) -> bytes: return _run(tools_path, *args) -def _tools_run_popen(*args) -> subprocess.Popen: +def _tools_run_popen(*args, **kwargs) -> subprocess.Popen: """ Return a command with wit and return the output :param args: command arguments :return: the output of the command """ - return _run_popen(tools_path, *args) + return _run_popen(tools_path, *args, **kwargs) @better_wt_error(tools_path) @@ -155,7 +155,8 @@ class WITPath: shutil.copytree(self._get_fst_root(), dest) else: - process = _tools_run_popen("EXTRACT", self.path, "-d", dest, "--progress") + process = _tools_run_popen("EXTRACT", self.path, "-d", dest, "--progress", universal_newlines=True) + # universal_newlines is required to correctly read text line by line while process.poll() is None: m = re.match(r'\s*(?P\d*)%(?:.*?ETA (?P\d*:\d*))?\s*', process.stdout.readline())