mirror of
https://git.yoctoproject.org/poky
synced 2026-09-19 09:49:33 +02:00
terminal.py: Fix Xfce on ubuntu/debian; some cleanup
* Xfce class was setting and passing wrong variable for ubuntu/debian.
* Xfce class was using -e instead of -x for passing command. The former creates
a shell escape nightmare
* Clean up local and instance/class variables with same name but different usage.
* Remove side-effect and directly return formatted command for clarity.
(From OE-Core rev: b2ee5c5e34cdc3d65ca7b5da3486360a74d6c500)
Signed-off-by: Jeffrey C Honig <jeffrey.honig@windriver.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
04c2ee40f6
commit
76a16c0c11
@@ -28,11 +28,10 @@ class Registry(oe.classutils.ClassRegistry):
|
|||||||
class Terminal(Popen):
|
class Terminal(Popen):
|
||||||
__metaclass__ = Registry
|
__metaclass__ = Registry
|
||||||
|
|
||||||
def __init__(self, command, title=None, env=None):
|
def __init__(self, sh_cmd, title=None, env=None):
|
||||||
self.format_command(command, title)
|
fmt_sh_cmd = self.format_command(sh_cmd, title)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Popen.__init__(self, self.command, env=env)
|
Popen.__init__(self, fmt_sh_cmd, env=env)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
import errno
|
import errno
|
||||||
if exc.errno == errno.ENOENT:
|
if exc.errno == errno.ENOENT:
|
||||||
@@ -40,16 +39,16 @@ class Terminal(Popen):
|
|||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def format_command(self, command, title):
|
def format_command(self, sh_cmd, title):
|
||||||
fmt = {'title': title or 'Terminal', 'command': command}
|
fmt = {'title': title or 'Terminal', 'command': sh_cmd}
|
||||||
if isinstance(self.command, basestring):
|
if isinstance(self.command, basestring):
|
||||||
self.command = shlex.split(self.command.format(**fmt))
|
return shlex.split(self.command.format(**fmt))
|
||||||
else:
|
else:
|
||||||
self.command = [element.format(**fmt) for element in self.command]
|
return [element.format(**fmt) for element in self.command]
|
||||||
|
|
||||||
class XTerminal(Terminal):
|
class XTerminal(Terminal):
|
||||||
def __init__(self, command, title=None, env=None):
|
def __init__(self, sh_cmd, title=None, env=None):
|
||||||
Terminal.__init__(self, command, title, env)
|
Terminal.__init__(self, sh_cmd, title, env)
|
||||||
if not os.environ.get('DISPLAY'):
|
if not os.environ.get('DISPLAY'):
|
||||||
raise UnsupportedTerminal(self.name)
|
raise UnsupportedTerminal(self.name)
|
||||||
|
|
||||||
@@ -75,14 +74,14 @@ class Konsole(XTerminal):
|
|||||||
command = 'konsole -T "{title}" -e {command}'
|
command = 'konsole -T "{title}" -e {command}'
|
||||||
priority = 2
|
priority = 2
|
||||||
|
|
||||||
def __init__(self, command, title=None, env=None):
|
def __init__(self, sh_cmd, title=None, env=None):
|
||||||
# Check version
|
# Check version
|
||||||
vernum = check_konsole_version("konsole")
|
vernum = check_konsole_version("konsole")
|
||||||
if vernum:
|
if vernum:
|
||||||
if vernum.split('.')[0] == "2":
|
if vernum.split('.')[0] == "2":
|
||||||
logger.debug(1, 'Konsole from KDE 4.x will not work as devshell, skipping')
|
logger.debug(1, 'Konsole from KDE 4.x will not work as devshell, skipping')
|
||||||
raise UnsupportedTerminal(self.name)
|
raise UnsupportedTerminal(self.name)
|
||||||
XTerminal.__init__(self, command, title, env)
|
XTerminal.__init__(self, sh_cmd, title, env)
|
||||||
|
|
||||||
class XTerm(XTerminal):
|
class XTerm(XTerminal):
|
||||||
command = 'xterm -T "{title}" -e {command}'
|
command = 'xterm -T "{title}" -e {command}'
|
||||||
@@ -95,8 +94,8 @@ class Rxvt(XTerminal):
|
|||||||
class Screen(Terminal):
|
class Screen(Terminal):
|
||||||
command = 'screen -D -m -t "{title}" -S devshell {command}'
|
command = 'screen -D -m -t "{title}" -S devshell {command}'
|
||||||
|
|
||||||
def __init__(self, command, title=None, env=None):
|
def __init__(self, sh_cmd, title=None, env=None):
|
||||||
Terminal.__init__(self, command, title, env)
|
Terminal.__init__(self, sh_cmd, title, env)
|
||||||
logger.warn('Screen started. Please connect in another terminal with '
|
logger.warn('Screen started. Please connect in another terminal with '
|
||||||
'"screen -r devshell"')
|
'"screen -r devshell"')
|
||||||
|
|
||||||
@@ -104,18 +103,18 @@ class Screen(Terminal):
|
|||||||
def prioritized():
|
def prioritized():
|
||||||
return Registry.prioritized()
|
return Registry.prioritized()
|
||||||
|
|
||||||
def spawn_preferred(command, title=None, env=None):
|
def spawn_preferred(sh_cmd, title=None, env=None):
|
||||||
"""Spawn the first supported terminal, by priority"""
|
"""Spawn the first supported terminal, by priority"""
|
||||||
for terminal in prioritized():
|
for terminal in prioritized():
|
||||||
try:
|
try:
|
||||||
spawn(terminal.name, command, title, env)
|
spawn(terminal.name, sh_cmd, title, env)
|
||||||
break
|
break
|
||||||
except UnsupportedTerminal:
|
except UnsupportedTerminal:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
raise NoSupportedTerminals()
|
raise NoSupportedTerminals()
|
||||||
|
|
||||||
def spawn(name, command, title=None, env=None):
|
def spawn(name, sh_cmd, title=None, env=None):
|
||||||
"""Spawn the specified terminal, by name"""
|
"""Spawn the specified terminal, by name"""
|
||||||
logger.debug(1, 'Attempting to spawn terminal "%s"', name)
|
logger.debug(1, 'Attempting to spawn terminal "%s"', name)
|
||||||
try:
|
try:
|
||||||
@@ -123,10 +122,10 @@ def spawn(name, command, title=None, env=None):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise UnsupportedTerminal(name)
|
raise UnsupportedTerminal(name)
|
||||||
|
|
||||||
pipe = terminal(command, title, env)
|
pipe = terminal(sh_cmd, title, env)
|
||||||
output = pipe.communicate()[0]
|
output = pipe.communicate()[0]
|
||||||
if pipe.returncode != 0:
|
if pipe.returncode != 0:
|
||||||
raise ExecutionError(pipe.command, pipe.returncode, output)
|
raise ExecutionError(sh_cmd, pipe.returncode, output)
|
||||||
|
|
||||||
def check_konsole_version(konsole):
|
def check_konsole_version(konsole):
|
||||||
import subprocess as sub
|
import subprocess as sub
|
||||||
|
|||||||
Reference in New Issue
Block a user