diff options
author | Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> | 2017-08-07 12:21:51 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-08-09 09:24:15 +0100 |
commit | 6cbe18ff832fa588e4dd1375f8a6f69ec44a06af (patch) | |
tree | 8dbff2ec14e52f5d68b420886b0b272ce470beb3 /meta | |
parent | c4b9c258d573a795a263a43dc9359f8fef0b594b (diff) | |
download | poky-6cbe18ff832fa588e4dd1375f8a6f69ec44a06af.tar.gz |
terminal: wait for terminal task to finish before procedding
This commit generalizes the work done in [1] and [2], both fixing
issues on several areas (the former with -c patch and gnome-terminal and
the latter with -c menuconfig and several terminals, including
gnome-terminal and tmux). The main idea is to get the PID
from the new spawned terminal and loop there until finished.
[1] 76e8ab47c9: terminal: Fix gnome-terminal to work with recent versions
[2] 7d02ea283b: cml1.bbclass: wait until menuconfig terminal finishes
(From OE-Core rev: 55707401d5bfb1f7686c273fc2d0db89df206395)
Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oe/terminal.py | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py index 0426e15834..3c6220dfce 100644 --- a/meta/lib/oe/terminal.py +++ b/meta/lib/oe/terminal.py | |||
@@ -62,28 +62,7 @@ class Gnome(XTerminal): | |||
62 | # Once fixed on the gnome-terminal project, this should be removed. | 62 | # Once fixed on the gnome-terminal project, this should be removed. |
63 | if os.getenv('LC_ALL'): os.putenv('LC_ALL','') | 63 | if os.getenv('LC_ALL'): os.putenv('LC_ALL','') |
64 | 64 | ||
65 | # We need to know when the command completes but gnome-terminal gives us no way | 65 | XTerminal.__init__(self, sh_cmd, title, env, d) |
66 | # to do this. We therefore write the pid to a file using a "phonehome" wrapper | ||
67 | # script, then monitor the pid until it exits. Thanks gnome! | ||
68 | import tempfile | ||
69 | pidfile = tempfile.NamedTemporaryFile(delete = False).name | ||
70 | try: | ||
71 | sh_cmd = "oe-gnome-terminal-phonehome " + pidfile + " " + sh_cmd | ||
72 | XTerminal.__init__(self, sh_cmd, title, env, d) | ||
73 | while os.stat(pidfile).st_size <= 0: | ||
74 | continue | ||
75 | with open(pidfile, "r") as f: | ||
76 | pid = int(f.readline()) | ||
77 | finally: | ||
78 | os.unlink(pidfile) | ||
79 | |||
80 | import time | ||
81 | while True: | ||
82 | try: | ||
83 | os.kill(pid, 0) | ||
84 | time.sleep(0.1) | ||
85 | except OSError: | ||
86 | return | ||
87 | 66 | ||
88 | class Mate(XTerminal): | 67 | class Mate(XTerminal): |
89 | command = 'mate-terminal -t "{title}" -x {command}' | 68 | command = 'mate-terminal -t "{title}" -x {command}' |
@@ -237,12 +216,35 @@ def spawn(name, sh_cmd, title=None, env=None, d=None): | |||
237 | except KeyError: | 216 | except KeyError: |
238 | raise UnsupportedTerminal(name) | 217 | raise UnsupportedTerminal(name) |
239 | 218 | ||
240 | pipe = terminal(sh_cmd, title, env, d) | 219 | # We need to know when the command completes but some terminals (at least |
241 | output = pipe.communicate()[0] | 220 | # gnome and tmux) gives us no way to do this. We therefore write the pid |
242 | if output: | 221 | # to a file using a "phonehome" wrapper script, then monitor the pid |
243 | output = output.decode("utf-8") | 222 | # until it exits. |
244 | if pipe.returncode != 0: | 223 | import tempfile |
245 | raise ExecutionError(sh_cmd, pipe.returncode, output) | 224 | pidfile = tempfile.NamedTemporaryFile(delete = False).name |
225 | try: | ||
226 | sh_cmd = "oe-gnome-terminal-phonehome " + pidfile + " " + sh_cmd | ||
227 | pipe = terminal(sh_cmd, title, env, d) | ||
228 | output = pipe.communicate()[0] | ||
229 | if output: | ||
230 | output = output.decode("utf-8") | ||
231 | if pipe.returncode != 0: | ||
232 | raise ExecutionError(sh_cmd, pipe.returncode, output) | ||
233 | |||
234 | while os.stat(pidfile).st_size <= 0: | ||
235 | continue | ||
236 | with open(pidfile, "r") as f: | ||
237 | pid = int(f.readline()) | ||
238 | finally: | ||
239 | os.unlink(pidfile) | ||
240 | |||
241 | import time | ||
242 | while True: | ||
243 | try: | ||
244 | os.kill(pid, 0) | ||
245 | time.sleep(0.1) | ||
246 | except OSError: | ||
247 | return | ||
246 | 248 | ||
247 | def check_tmux_pane_size(tmux): | 249 | def check_tmux_pane_size(tmux): |
248 | import subprocess as sub | 250 | import subprocess as sub |