[PATCH v2 03/30] u_boot_pylib: Make pty optional
Simon Glass
sjg at chromium.org
Sun Apr 30 03:29:36 CEST 2023
This library is not available on Windows. Detect this and work around it
by using a normal pipe.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v2:
- move u_boot_pylib changes to a separate patch
tools/u_boot_pylib/cros_subprocess.py | 28 ++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/tools/u_boot_pylib/cros_subprocess.py b/tools/u_boot_pylib/cros_subprocess.py
index cd614f38a648..35cef7333f3a 100644
--- a/tools/u_boot_pylib/cros_subprocess.py
+++ b/tools/u_boot_pylib/cros_subprocess.py
@@ -16,12 +16,18 @@ progress information and filter output in real time.
import errno
import os
-import pty
import select
import subprocess
import sys
import unittest
+try:
+ import pty
+ HAVE_PTY = True
+except:
+ # For Windows
+ HAVE_PTY = False
+
# Import these here so the caller does not need to import subprocess also.
PIPE = subprocess.PIPE
@@ -74,11 +80,17 @@ class Popen(subprocess.Popen):
stderr_pty = None
if stdout == PIPE_PTY:
- stdout_pty = pty.openpty()
- stdout = os.fdopen(stdout_pty[1])
+ if HAVE_PTY:
+ stdout_pty = pty.openpty()
+ stdout = os.fdopen(stdout_pty[1])
+ else:
+ stdout = PIPE
if stderr == PIPE_PTY:
- stderr_pty = pty.openpty()
- stderr = os.fdopen(stderr_pty[1])
+ if HAVE_PTY:
+ stderr_pty = pty.openpty()
+ stderr = os.fdopen(stderr_pty[1])
+ else:
+ stderr = PIPE
super(Popen, self).__init__(args, stdin=stdin,
stdout=stdout, stderr=stderr, shell=shell, cwd=cwd, env=env,
@@ -156,6 +168,12 @@ class Popen(subprocess.Popen):
Note also that if you set stderr to STDOUT, then stderr will be empty
and the combined output will just be the same as stdout.
"""
+ if not HAVE_PTY:
+ stdout, stderr = self.communicate(input_buf)
+ stdout = self.convert_data(stdout)
+ stderr = self.convert_data(stderr)
+ combined = self.convert_data(stdout + stderr)
+ return (stdout, stderr, combined)
read_set = []
write_set = []
--
2.40.1.495.gc816e09b53d-goog
More information about the U-Boot
mailing list