made universal_newlines parameter in _run_popen optional

This commit is contained in:
Faraphel 2022-07-10 23:56:10 +02:00
parent 4cb2aa7379
commit d456430714
2 changed files with 7 additions and 6 deletions

View file

@ -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,
)

View file

@ -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<percentage>\d*)%(?:.*?ETA (?P<estimation>\d*:\d*))?\s*', process.stdout.readline())