summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/knotty2.py
diff options
context:
space:
mode:
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)