* [PATCH 2/4] event.py, knotty.py, ncurses.py, runningbuild.py: Add support for LogExecTTY event
2012-09-17 22:43 [PATCH 0/4] Add ability to auto spawn screen on a controlling terminal Jason Wessel
2012-09-17 22:43 ` [PATCH 1/4] progress.py: Fix traceback when running goggle ui Jason Wessel
@ 2012-09-17 22:43 ` Jason Wessel
2012-09-17 22:43 ` [PATCH 3/4] terminal: pass data store all the way through to terminal class Jason Wessel
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Jason Wessel @ 2012-09-17 22:43 UTC (permalink / raw)
To: bitbake-devel
The LogExecTTY even is intended to provide the ability to spawn a task
on a the controlling tty, if a tty is availble. When a controlling
tty is not availble the previous behavior is preserved where a warning
is issued about the action an end user must execute.
All the available UI's were tested against the new event type.
This feature is primarily intended for hooking up a screen client
session automatically on the controlling tty to allow for a more
streamlined end user experience when using a pure command line driven
environment. The changes that send the LogExecTTY event are in the
oe-core side.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
---
lib/bb/event.py | 9 +++++++++
lib/bb/ui/crumbs/runningbuild.py | 15 +++++++++++++++
lib/bb/ui/knotty.py | 19 +++++++++++++++++++
lib/bb/ui/ncurses.py | 2 ++
4 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/lib/bb/event.py b/lib/bb/event.py
index ab62d4d..e62f2f8 100644
--- a/lib/bb/event.py
+++ b/lib/bb/event.py
@@ -509,6 +509,15 @@ class MsgFatal(MsgBase):
class MsgPlain(MsgBase):
"""General output"""
+class LogExecTTY(Event):
+ """Send event containing program to spawn on tty of the logger"""
+ def __init__(self, msg, prog, sleep_delay, retries):
+ Event.__init__(self)
+ self.msg = msg
+ self.prog = prog
+ self.sleep_delay = sleep_delay
+ self.retries = retries
+
class LogHandler(logging.Handler):
"""Dispatch logging messages as bitbake events"""
diff --git a/lib/bb/ui/crumbs/runningbuild.py b/lib/bb/ui/crumbs/runningbuild.py
index a57d6db..700fd65 100644
--- a/lib/bb/ui/crumbs/runningbuild.py
+++ b/lib/bb/ui/crumbs/runningbuild.py
@@ -375,6 +375,21 @@ class RunningBuild (gobject.GObject):
msg += ("%s\n" % reason)
self.emit("no-provider", msg)
self.emit("log", msg)
+ elif isinstance(event, bb.event.LogExecTTY):
+ icon = "dialog-warning"
+ color = HobColors.WARNING
+ if self.sequential or not parent:
+ tree_add = self.model.append
+ else:
+ tree_add = self.model.prepend
+ tree_add(parent,
+ (None,
+ package,
+ task,
+ event.msg,
+ icon,
+ color,
+ 0))
else:
if not isinstance(event, (bb.event.BuildBase,
bb.event.StampUpdate,
diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
index 858cacf..d81ad5d 100644
--- a/lib/bb/ui/knotty.py
+++ b/lib/bb/ui/knotty.py
@@ -27,6 +27,7 @@ import logging
import progressbar
import signal
import bb.msg
+import time
import fcntl
import struct
import copy
@@ -216,6 +217,10 @@ def main(server, eventHandler, tf = TerminalFilter):
includelogs = server.runCommand(["getVariable", "BBINCLUDELOGS"])
loglines = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"])
consolelogfile = server.runCommand(["getVariable", "BB_CONSOLELOG"])
+ if sys.stdin.isatty() and sys.stdout.isatty():
+ log_exec_tty = True
+ else:
+ log_exec_tty = False
helper = uihelper.BBUIHelper()
@@ -271,6 +276,20 @@ def main(server, eventHandler, tf = TerminalFilter):
if not main.shutdown:
main.shutdown = 1
+ if isinstance(event, bb.event.LogExecTTY):
+ if log_exec_tty:
+ tries = event.retries
+ while tries:
+ print "Trying to run: %s" % event.prog
+ if os.system(event.prog) == 0:
+ break
+ time.sleep(event.sleep_delay)
+ tries -= 1
+ if tries:
+ continue
+ logger.warn(event.msg)
+ continue
+
if isinstance(event, logging.LogRecord):
if event.levelno >= format.ERROR:
errors = errors + 1
diff --git a/lib/bb/ui/ncurses.py b/lib/bb/ui/ncurses.py
index f573b95..f6ea7f9 100644
--- a/lib/bb/ui/ncurses.py
+++ b/lib/bb/ui/ncurses.py
@@ -318,6 +318,8 @@ class NCursesUI:
if isinstance(event, bb.cooker.CookerExit):
exitflag = True
+ if isinstance(event, bb.event.LogExecTTY):
+ mw.appendText('WARN: ' + event.msg + '\n')
if helper.needUpdate:
activetasks, failedtasks = helper.getTasks()
taw.erase()
--
1.7.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/4] terminal: pass data store all the way through to terminal class
2012-09-17 22:43 [PATCH 0/4] Add ability to auto spawn screen on a controlling terminal Jason Wessel
2012-09-17 22:43 ` [PATCH 1/4] progress.py: Fix traceback when running goggle ui Jason Wessel
2012-09-17 22:43 ` [PATCH 2/4] event.py, knotty.py, ncurses.py, runningbuild.py: Add support for LogExecTTY event Jason Wessel
@ 2012-09-17 22:43 ` Jason Wessel
2012-09-17 22:43 ` [PATCH 4/4] terminal: Send LogExecTTY event to spawn screen Jason Wessel
2012-09-24 14:32 ` [PATCH 0/4] Add ability to auto spawn screen on a controlling terminal Richard Purdie
4 siblings, 0 replies; 6+ messages in thread
From: Jason Wessel @ 2012-09-17 22:43 UTC (permalink / raw)
To: bitbake-devel
Passing the data store will be needed for firing a custom event
for the screen class.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
---
meta/classes/terminal.bbclass | 4 ++--
meta/lib/oe/terminal.py | 22 +++++++++++-----------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/meta/classes/terminal.bbclass b/meta/classes/terminal.bbclass
index 3cfc84b..2cd6f4c 100644
--- a/meta/classes/terminal.bbclass
+++ b/meta/classes/terminal.bbclass
@@ -25,7 +25,7 @@ def oe_terminal(command, title, d):
bb.fatal('Devshell usage disabled with OE_TERMINAL')
elif terminal != 'auto':
try:
- oe.terminal.spawn(terminal, command, title)
+ oe.terminal.spawn(terminal, command, title, None, d)
return
except oe.terminal.UnsupportedTerminal:
bb.warn('Unsupported terminal "%s", defaulting to "auto"' %
@@ -34,7 +34,7 @@ def oe_terminal(command, title, d):
bb.fatal('Unable to spawn terminal %s: %s' % (terminal, exc))
try:
- oe.terminal.spawn_preferred(command, title)
+ oe.terminal.spawn_preferred(command, title, None, d)
except oe.terminal.NoSupportedTerminals:
bb.fatal('No valid terminal found, unable to open devshell')
except oe.terminal.ExecutionError as exc:
diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py
index d66309f..c71d6ad 100644
--- a/meta/lib/oe/terminal.py
+++ b/meta/lib/oe/terminal.py
@@ -28,7 +28,7 @@ class Registry(oe.classutils.ClassRegistry):
class Terminal(Popen):
__metaclass__ = Registry
- def __init__(self, sh_cmd, title=None, env=None):
+ def __init__(self, sh_cmd, title=None, env=None, d=None):
fmt_sh_cmd = self.format_command(sh_cmd, title)
try:
Popen.__init__(self, fmt_sh_cmd, env=env)
@@ -47,7 +47,7 @@ class Terminal(Popen):
return [element.format(**fmt) for element in self.command]
class XTerminal(Terminal):
- def __init__(self, sh_cmd, title=None, env=None):
+ def __init__(self, sh_cmd, title=None, env=None, d=None):
Terminal.__init__(self, sh_cmd, title, env)
if not os.environ.get('DISPLAY'):
raise UnsupportedTerminal(self.name)
@@ -60,7 +60,7 @@ class Xfce(XTerminal):
command = 'Terminal -T "{title}" -e "{command}"'
priority = 2
- def __init__(self, command, title=None, env=None):
+ def __init__(self, command, title=None, env=None, d=None):
# Upstream binary name is Terminal but Debian/Ubuntu use
# xfce4-terminal to avoid possible(?) conflicts
distro = distro_name()
@@ -68,20 +68,20 @@ class Xfce(XTerminal):
cmd = 'xfce4-terminal -T "{title}" -e "{command}"'
else:
cmd = command
- XTerminal.__init__(self, cmd, title, env)
+ XTerminal.__init__(self, cmd, title, env, d)
class Konsole(XTerminal):
command = 'konsole -T "{title}" -e {command}'
priority = 2
- def __init__(self, sh_cmd, title=None, env=None):
+ def __init__(self, sh_cmd, title=None, env=None, d=None):
# Check version
vernum = check_konsole_version("konsole")
if vernum:
if vernum.split('.')[0] == "2":
logger.debug(1, 'Konsole from KDE 4.x will not work as devshell, skipping')
raise UnsupportedTerminal(self.name)
- XTerminal.__init__(self, sh_cmd, title, env)
+ XTerminal.__init__(self, sh_cmd, title, env, d)
class XTerm(XTerminal):
command = 'xterm -T "{title}" -e {command}'
@@ -94,7 +94,7 @@ class Rxvt(XTerminal):
class Screen(Terminal):
command = 'screen -D -m -t "{title}" -S devshell {command}'
- def __init__(self, sh_cmd, title=None, env=None):
+ def __init__(self, sh_cmd, title=None, env=None, d=None):
s_id = "devshell_%i" % os.getpid()
self.command = "screen -D -m -t \"{title}\" -S %s {command}" % s_id
Terminal.__init__(self, sh_cmd, title, env)
@@ -105,18 +105,18 @@ class Screen(Terminal):
def prioritized():
return Registry.prioritized()
-def spawn_preferred(sh_cmd, title=None, env=None):
+def spawn_preferred(sh_cmd, title=None, env=None, d=None):
"""Spawn the first supported terminal, by priority"""
for terminal in prioritized():
try:
- spawn(terminal.name, sh_cmd, title, env)
+ spawn(terminal.name, sh_cmd, title, env, d)
break
except UnsupportedTerminal:
continue
else:
raise NoSupportedTerminals()
-def spawn(name, sh_cmd, title=None, env=None):
+def spawn(name, sh_cmd, title=None, env=None, d=None):
"""Spawn the specified terminal, by name"""
logger.debug(1, 'Attempting to spawn terminal "%s"', name)
try:
@@ -124,7 +124,7 @@ def spawn(name, sh_cmd, title=None, env=None):
except KeyError:
raise UnsupportedTerminal(name)
- pipe = terminal(sh_cmd, title, env)
+ pipe = terminal(sh_cmd, title, env, d)
output = pipe.communicate()[0]
if pipe.returncode != 0:
raise ExecutionError(sh_cmd, pipe.returncode, output)
--
1.7.1
^ permalink raw reply related [flat|nested] 6+ messages in thread