summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/knotty2.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2011-11-26 13:37:52 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-03-29 19:44:01 +0100
commiteeb0529e138fa95db8fc6ed74bcaee87804fcb6c (patch)
tree45353a0b77672a788682066b6300b5ee5c457595 /bitbake/lib/bb/ui/knotty2.py
parent5b84c902ebbd0b034c6f328eb44054e2f92556d3 (diff)
downloadpoky-eeb0529e138fa95db8fc6ed74bcaee87804fcb6c.tar.gz
ui/knotty: Add a footer to the build output for interactive terminals as knotty2 UI
On terminals which support it, add summary information to the end of the build output about the number of tasks currently running and how many tasks we've run so far. This provides a summary at a glace of what the current state of the build is and what the build is currently doing which is lacking in the current UI. Also disable echo of characters on stdin since this corrupts the disable, particularly Crtl+C. The "waiting for X tasks" code can be merged into this code too since that is only useful on interactive terminals and this improves the readability of that output too. Improvements since v0: * The tasks are ordered in execution order. * The display is only updated when the list of tasks changes or there is output above the footer. * Running task x oy y and package messages are supressed from the console This UI can be accessed with "bitbake -u knotty2". (From Poky rev: e38b4569648f2916c4370871c79e6a6090eb8bc1) (Bitbake rev: 156189c799d2bb1f69bdaa04b5cd718fe7881425) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/ui/knotty2.py')
-rw-r--r--bitbake/lib/bb/ui/knotty2.py109
1 files changed, 109 insertions, 0 deletions
diff --git a/bitbake/lib/bb/ui/knotty2.py b/bitbake/lib/bb/ui/knotty2.py
new file mode 100644
index 0000000000..aa6a4080e2
--- /dev/null
+++ b/bitbake/lib/bb/ui/knotty2.py
@@ -0,0 +1,109 @@
1#
2# BitBake (No)TTY UI Implementation (v2)
3#
4# Handling output to TTYs or files (no TTY)
5#
6# Copyright (C) 2012 Richard Purdie
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 2 as
10# published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21from bb.ui import knotty
22import logging
23import sys
24logger = logging.getLogger("BitBake")
25
26class InteractConsoleLogFilter(logging.Filter):
27 def __init__(self, tf, format):
28 self.tf = tf
29 self.format = format
30
31 def filter(self, record):
32 if record.levelno == self.format.NOTE and (record.msg.startswith("Running") or record.msg.startswith("package ")):
33 return False
34 self.tf.clearFooter()
35 return True
36
37class TerminalFilter2(object):
38 def __init__(self, main, helper, console, format):
39 self.main = main
40 self.helper = helper
41 self.cuu = None
42 self.stdinbackup = None
43 self.interactive = sys.stdout.isatty()
44 self.footer_present = False
45 self.lastpids = []
46
47 if not self.interactive:
48 return
49
50 import curses
51 import termios
52 import copy
53 self.curses = curses
54 self.termios = termios
55 try:
56 fd = sys.stdin.fileno()
57 self.stdinbackup = termios.tcgetattr(fd)
58 new = copy.deepcopy(self.stdinbackup)
59 new[3] = new[3] & ~termios.ECHO
60 termios.tcsetattr(fd, termios.TCSADRAIN, new)
61 curses.setupterm()
62 self.ed = curses.tigetstr("ed")
63 if self.ed:
64 self.cuu = curses.tigetstr("cuu")
65 except:
66 self.cuu = None
67 console.addFilter(InteractConsoleLogFilter(self, format))
68
69 def clearFooter(self):
70 if self.footer_present:
71 lines = self.footer_present
72 sys.stdout.write(self.curses.tparm(self.cuu, lines))
73 sys.stdout.write(self.curses.tparm(self.ed))
74 self.footer_present = False
75
76 def updateFooter(self):
77 if not self.cuu:
78 return
79 activetasks = self.helper.running_tasks
80 failedtasks = self.helper.failed_tasks
81 runningpids = self.helper.running_pids
82 if self.footer_present and (self.lastpids == runningpids):
83 return
84 if self.footer_present:
85 self.clearFooter()
86 if not activetasks:
87 return
88 lines = 1
89 tasks = []
90 for t in runningpids:
91 tasks.append("%s (pid %s)" % (activetasks[t]["title"], t))
92
93 if self.main.shutdown:
94 print("Waiting for %s running tasks to finish:" % len(activetasks))
95 else:
96 print("Currently %s running tasks (%s of %s):" % (len(activetasks), self.helper.tasknumber_current, self.helper.tasknumber_total))
97 for tasknum, task in enumerate(tasks):
98 print("%s: %s" % (tasknum, task))
99 lines = lines + 1
100 self.footer_present = lines
101 self.lastpids = runningpids[:]
102
103 def finish(self):
104 if self.stdinbackup:
105 fd = sys.stdin.fileno()
106 self.termios.tcsetattr(fd, self.termios.TCSADRAIN, self.stdinbackup)
107
108def main(server, eventHandler):
109 bb.ui.knotty.main(server, eventHandler, TerminalFilter2)