Comments
Patch
@@ -1,22 +1,14 @@
-do_devshell[dirs] = "${S}"
-do_devshell[nostamp] = "1"
+inherit terminal
-XAUTHORITY ?= "${HOME}/.Xauthority"
-devshell_do_devshell() {
- export DISPLAY='${DISPLAY}'
- export DBUS_SESSION_BUS_ADDRESS='${DBUS_SESSION_BUS_ADDRESS}'
- export XAUTHORITY='${XAUTHORITY}'
- export TERMWINDOWTITLE="Bitbake Developer Shell"
- export EXTRA_OEMAKE='${EXTRA_OEMAKE}'
- export SHELLCMDS="bash"
- ${TERMCMDRUN}
- if [ $? -ne 0 ]; then
- echo "Fatal: '${TERMCMD}' not found. Check TERMCMD variable."
- exit 1
- fi
+export XAUTHORITY ?= "${HOME}/.Xauthority"
+export SHELL ?= 'bash'
+
+python do_devshell () {
+ oe_terminal(d.getVar('SHELL', True), 'OpenEmbedded Developer Shell', d)
}
-addtask devshell after do_patch
-EXPORT_FUNCTIONS do_devshell
+addtask devshell after do_patch
+do_devshell[dirs] = "${S}"
+do_devshell[nostamp] = "1"
new file mode 100644
@@ -0,0 +1,100 @@
+import logging
+import os
+import oe.classutils
+from bb.process import Popen, ExecutionError
+
+logger = logging.getLogger('BitBake.OE.Terminal')
+
+
+class UnsupportedTerminal(StandardError):
+ pass
+
+class NoSupportedTerminals(StandardError):
+ pass
+
+
+class Registry(oe.classutils.ClassRegistry):
+ registry = {}
+
+ def __init__(cls, name, bases, attrs):
+ super(Registry, cls).__init__(name.lower(), bases, attrs)
+ if not cls.cmd:
+ cls.unregister()
+
+
+class Terminal(Popen):
+ __metaclass__ = Registry
+ cmd = None
+
+ def __init__(self, cmd, title=None):
+ self.format_cmd(cmd, title)
+
+ try:
+ Popen.__init__(self, self.cmd, shell=True)
+ except OSError as exc:
+ import errno
+ if exc.errno == errno.ENOENT:
+ raise UnsupportedTerminal(self.name)
+ else:
+ raise
+
+ def format_cmd(self, cmd, title):
+ fmt = {'title': title or 'Terminal', 'cmd': cmd}
+ if isinstance(self.cmd, basestring):
+ self.cmd = self.cmd.format(**fmt)
+ else:
+ self.cmd = [element.format(**fmt) for element in self.cmd]
+
+class XTerminal(Terminal):
+ def __init__(self, cmd, title=None):
+ Terminal.__init__(self, cmd, title)
+ if not os.environ.get('DISPLAY'):
+ raise UnsupportedTerminal(self.name)
+
+class Gnome(XTerminal):
+ cmd = 'gnome-terminal --disable-factory -t "{title}" -x {cmd}'
+ priority = 2
+
+class Konsole(XTerminal):
+ cmd = 'konsole -T "{title}" -e {cmd}'
+ priority = 2
+
+class XTerm(XTerminal):
+ cmd = 'xterm -T "{title}" -e {cmd}'
+ priority = 1
+
+class Rxvt(XTerminal):
+ cmd = 'rxvt -T "{title}" -e {cmd}'
+ priority = 1
+
+class Screen(Terminal):
+ cmd = 'screen -D -m -t "{title}" {cmd}'
+
+
+def prioritized():
+ return Registry.prioritized()
+
+def spawn_preferred(cmd, title=None):
+ """Spawn the first supported terminal, by priority"""
+ for terminal in Registry.prioritized():
+ try:
+ spawn(terminal.name, cmd, title)
+ break
+ except UnsupportedTerminal:
+ continue
+ else:
+ raise NoSupportedTerminals()
+
+def spawn(name, cmd, title=None):
+ """Spawn the specified terminal, by name"""
+ logger.debug(1, 'Attempting to spawn terminal "%s"' %
+ name)
+ try:
+ terminal = Registry.registry[name]
+ except KeyError:
+ raise UnsupportedTerminal(name)
+
+ pipe = terminal(cmd, title)
+ output = pipe.communicate()[0]
+ if pipe.returncode != 0:
+ raise ExecutionError(pipe.cmd, pipe.returncode, output)