summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/terminal.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oe/terminal.py')
-rw-r--r--meta/lib/oe/terminal.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py
index 61c2687ef4..4412bc14c1 100644
--- a/meta/lib/oe/terminal.py
+++ b/meta/lib/oe/terminal.py
@@ -1,11 +1,12 @@
1# 1#
2# Copyright OpenEmbedded Contributors
3#
2# SPDX-License-Identifier: GPL-2.0-only 4# SPDX-License-Identifier: GPL-2.0-only
3# 5#
4import logging 6import logging
5import oe.classutils 7import oe.classutils
6import shlex 8import shlex
7from bb.process import Popen, ExecutionError 9from bb.process import Popen, ExecutionError
8from distutils.version import LooseVersion
9 10
10logger = logging.getLogger('BitBake.OE.Terminal') 11logger = logging.getLogger('BitBake.OE.Terminal')
11 12
@@ -31,9 +32,10 @@ class Registry(oe.classutils.ClassRegistry):
31 32
32class Terminal(Popen, metaclass=Registry): 33class Terminal(Popen, metaclass=Registry):
33 def __init__(self, sh_cmd, title=None, env=None, d=None): 34 def __init__(self, sh_cmd, title=None, env=None, d=None):
35 from subprocess import STDOUT
34 fmt_sh_cmd = self.format_command(sh_cmd, title) 36 fmt_sh_cmd = self.format_command(sh_cmd, title)
35 try: 37 try:
36 Popen.__init__(self, fmt_sh_cmd, env=env) 38 Popen.__init__(self, fmt_sh_cmd, env=env, stderr=STDOUT)
37 except OSError as exc: 39 except OSError as exc:
38 import errno 40 import errno
39 if exc.errno == errno.ENOENT: 41 if exc.errno == errno.ENOENT:
@@ -86,10 +88,10 @@ class Konsole(XTerminal):
86 def __init__(self, sh_cmd, title=None, env=None, d=None): 88 def __init__(self, sh_cmd, title=None, env=None, d=None):
87 # Check version 89 # Check version
88 vernum = check_terminal_version("konsole") 90 vernum = check_terminal_version("konsole")
89 if vernum and LooseVersion(vernum) < '2.0.0': 91 if vernum and bb.utils.vercmp_string_op(vernum, "2.0.0", "<"):
90 # Konsole from KDE 3.x 92 # Konsole from KDE 3.x
91 self.command = 'konsole -T "{title}" -e {command}' 93 self.command = 'konsole -T "{title}" -e {command}'
92 elif vernum and LooseVersion(vernum) < '16.08.1': 94 elif vernum and bb.utils.vercmp_string_op(vernum, "16.08.1", "<"):
93 # Konsole pre 16.08.01 Has nofork 95 # Konsole pre 16.08.01 Has nofork
94 self.command = 'konsole --nofork --workdir . -p tabtitle="{title}" -e {command}' 96 self.command = 'konsole --nofork --workdir . -p tabtitle="{title}" -e {command}'
95 XTerminal.__init__(self, sh_cmd, title, env, d) 97 XTerminal.__init__(self, sh_cmd, title, env, d)
@@ -102,6 +104,10 @@ class Rxvt(XTerminal):
102 command = 'rxvt -T "{title}" -e {command}' 104 command = 'rxvt -T "{title}" -e {command}'
103 priority = 1 105 priority = 1
104 106
107class URxvt(XTerminal):
108 command = 'urxvt -T "{title}" -e {command}'
109 priority = 1
110
105class Screen(Terminal): 111class Screen(Terminal):
106 command = 'screen -D -m -t "{title}" -S devshell {command}' 112 command = 'screen -D -m -t "{title}" -S devshell {command}'
107 113
@@ -163,7 +169,12 @@ class Tmux(Terminal):
163 # devshells, if it's already there, add a new window to it. 169 # devshells, if it's already there, add a new window to it.
164 window_name = 'devshell-%i' % os.getpid() 170 window_name = 'devshell-%i' % os.getpid()
165 171
166 self.command = 'tmux new -c "{{cwd}}" -d -s {0} -n {0} "{{command}}"'.format(window_name) 172 self.command = 'tmux new -c "{{cwd}}" -d -s {0} -n {0} "{{command}}"'
173 if not check_tmux_version('1.9'):
174 # `tmux new-session -c` was added in 1.9;
175 # older versions fail with that flag
176 self.command = 'tmux new -d -s {0} -n {0} "{{command}}"'
177 self.command = self.command.format(window_name)
167 Terminal.__init__(self, sh_cmd, title, env, d) 178 Terminal.__init__(self, sh_cmd, title, env, d)
168 179
169 attach_cmd = 'tmux att -t {0}'.format(window_name) 180 attach_cmd = 'tmux att -t {0}'.format(window_name)
@@ -253,13 +264,18 @@ def spawn(name, sh_cmd, title=None, env=None, d=None):
253 except OSError: 264 except OSError:
254 return 265 return
255 266
267def check_tmux_version(desired):
268 vernum = check_terminal_version("tmux")
269 if vernum and bb.utils.vercmp_string_op(vernum, desired, "<"):
270 return False
271 return vernum
272
256def check_tmux_pane_size(tmux): 273def check_tmux_pane_size(tmux):
257 import subprocess as sub 274 import subprocess as sub
258 # On older tmux versions (<1.9), return false. The reason 275 # On older tmux versions (<1.9), return false. The reason
259 # is that there is no easy way to get the height of the active panel 276 # is that there is no easy way to get the height of the active panel
260 # on current window without nested formats (available from version 1.9) 277 # on current window without nested formats (available from version 1.9)
261 vernum = check_terminal_version("tmux") 278 if not check_tmux_version('1.9'):
262 if vernum and LooseVersion(vernum) < '1.9':
263 return False 279 return False
264 try: 280 try:
265 p = sub.Popen('%s list-panes -F "#{?pane_active,#{pane_height},}"' % tmux, 281 p = sub.Popen('%s list-panes -F "#{?pane_active,#{pane_height},}"' % tmux,