[bitbake-devel] [PATCH 3/8] knotty.py: Add the ability to dynamically select loglevel from stdin
Jason Wessel
jason.wessel at windriver.com
Mon Sep 17 22:43:33 UTC 2012
If stdin is a controlling terminal, make it possible to dynamically
select a log level with the keys 1 and 2.
1 = normal bitbake knotty logs
2 = realtime multiple tail of task logs
(LOCAL REV: NOT UPSTREAM)
Signed-off-by: Jason Wessel <jason.wessel at windriver.com>
---
lib/bb/ui/knotty.py | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
index d412192..0ec1b30 100644
--- a/lib/bb/ui/knotty.py
+++ b/lib/bb/ui/knotty.py
@@ -213,6 +213,35 @@ class TerminalFilter(object):
fd = sys.stdin.fileno()
self.termios.tcsetattr(fd, self.termios.TCSADRAIN, self.stdinbackup)
+class StdinMgr:
+ def __init__(self):
+ import termios
+ self.termios = termios
+ self.stdinbackup = None
+ self.fd = None
+ if sys.stdin.isatty():
+ self.fd = sys.stdin.fileno()
+ self.stdinbackup = self.termios.tcgetattr(self.fd)
+ new = self.termios.tcgetattr(self.fd)
+ new[3] = new[3] & ~self.termios.ICANON & ~self.termios.ECHO
+ self.termios.tcsetattr(self.fd, self.termios.TCSANOW, new)
+
+ def poll(self):
+ if not self.stdinbackup:
+ return False
+ return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])
+
+ def restore(self):
+ if self.stdinbackup:
+ self.termios.tcsetattr(self.fd, self.termios.TCSADRAIN,
+ self.stdinbackup)
+ self.stdinbackup = None
+ # Force echo back on "just in case" something went haywire with an exception
+ if sys.stdin.isatty():
+ new = self.termios.tcgetattr(self.fd)
+ new[3] = new[3] | self.termios.ECHO
+ self.termios.tcsetattr(self.fd, self.termios.TCSANOW, new)
+
class RtLogLevel:
def __init__(self, mlt):
self.displaytail = False
@@ -294,11 +323,15 @@ def main(server, eventHandler, tf = TerminalFilter):
taskfailures = []
termfilter = tf(main, helper, console, format)
+ stdin_mgr = StdinMgr()
while True:
try:
termfilter.updateFooter()
event = eventHandler.waitEvent(0.25)
+ if stdin_mgr.poll():
+ keyinput = sys.stdin.read(1)
+ rtloglevel.setLevel(keyinput, True)
# Always try printing any accumulated log files first
rtloglevel.displayLogs()
if event is None:
@@ -488,6 +521,7 @@ def main(server, eventHandler, tf = TerminalFilter):
if ioerror.args[0] == 4:
pass
except KeyboardInterrupt:
+ stdin_mgr.restore()
termfilter.clearFooter()
if main.shutdown == 1:
print("\nSecond Keyboard Interrupt, stopping...\n")
@@ -499,6 +533,7 @@ def main(server, eventHandler, tf = TerminalFilter):
main.shutdown = main.shutdown + 1
pass
+ stdin_mgr.restore()
summary = ""
if taskfailures:
summary += pluralise("\nSummary: %s task failed:",
--
1.7.1
More information about the bitbake-devel
mailing list