From patchwork Fri Jun 8 13:41:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [bitbake-devel, v4, 03/18] knotty: Add the ability to dynamically select loglevel from stdin Date: Fri, 08 Jun 2012 13:41:38 -0000 From: Jason Wessel X-Patchwork-Id: 29487 Message-Id: <1339162913-23759-4-git-send-email-jason.wessel@windriver.com> To: 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 --- lib/bb/ui/knotty.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py index fd86ed5..f72f0ad 100644 --- a/lib/bb/ui/knotty.py +++ b/lib/bb/ui/knotty.py @@ -108,6 +108,32 @@ class TerminalFilter(object): def finish(self): return +class StdinMgr: + def __init__(self): + self.stdinbackup = None + self.fd = None + if sys.stdin.isatty(): + self.fd = sys.stdin.fileno() + self.stdinbackup = termios.tcgetattr(self.fd) + new = termios.tcgetattr(self.fd) + new[3] = new[3] & ~termios.ICANON & ~termios.ECHO + termios.tcsetattr(self.fd, 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: + termios.tcsetattr(self.fd, 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 = termios.tcgetattr(self.fd) + new[3] = new[3] | termios.ECHO + termios.tcsetattr(self.fd, termios.TCSANOW, new) + class RtLogLevel: def __init__(self, mlt): self.displaytail = False @@ -184,11 +210,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: @@ -364,6 +394,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") @@ -375,6 +406,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:",