[bitbake-devel] [PATCH 2/7] knotty.py: Add the ability to dynamically select loglevel from stdin
Mark Hatle
mark.hatle at windriver.com
Wed May 29 03:59:10 UTC 2013
From: Jason Wessel <jason.wessel at windriver.com>
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
Signed-off-by: Jason Wessel <jason.wessel at windriver.com>
---
lib/bb/ui/knotty.py | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
index 34ca678..293572f 100644
--- a/lib/bb/ui/knotty.py
+++ b/lib/bb/ui/knotty.py
@@ -218,6 +218,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
@@ -317,11 +346,15 @@ def main(server, eventHandler, params, 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:
@@ -512,6 +545,7 @@ def main(server, eventHandler, params, 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")
@@ -527,6 +561,7 @@ def main(server, eventHandler, params, tf = TerminalFilter):
main.shutdown = main.shutdown + 1
pass
+ stdin_mgr.restore()
summary = ""
if taskfailures:
summary += pluralise("\nSummary: %s task failed:",
--
1.8.1.2.545.g2f19ada
More information about the bitbake-devel
mailing list