diff options
author | Richard Purdie <richard@openedhand.com> | 2008-09-30 15:08:33 +0000 |
---|---|---|
committer | Richard Purdie <richard@openedhand.com> | 2008-09-30 15:08:33 +0000 |
commit | c30eddb243e7e65f67f656e62848a033cf6f2e5c (patch) | |
tree | 110dd95788b76f55d31cb8d30aac2de8400b6f4a /bitbake-dev/lib/bb/ui/ncurses.py | |
parent | 5ef0510474004eeb2ae8a99b64e2febb1920e077 (diff) | |
download | poky-c30eddb243e7e65f67f656e62848a033cf6f2e5c.tar.gz |
Add bitbake-dev to allow ease of testing and development of bitbake trunk
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@5337 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake-dev/lib/bb/ui/ncurses.py')
-rw-r--r-- | bitbake-dev/lib/bb/ui/ncurses.py | 333 |
1 files changed, 333 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/ui/ncurses.py b/bitbake-dev/lib/bb/ui/ncurses.py new file mode 100644 index 0000000000..1476baa61f --- /dev/null +++ b/bitbake-dev/lib/bb/ui/ncurses.py | |||
@@ -0,0 +1,333 @@ | |||
1 | # | ||
2 | # BitBake Curses UI Implementation | ||
3 | # | ||
4 | # Implements an ncurses frontend for the BitBake utility. | ||
5 | # | ||
6 | # Copyright (C) 2006 Michael 'Mickey' Lauer | ||
7 | # Copyright (C) 2006-2007 Richard Purdie | ||
8 | # | ||
9 | # This program is free software; you can redistribute it and/or modify | ||
10 | # it under the terms of the GNU General Public License version 2 as | ||
11 | # published by the Free Software Foundation. | ||
12 | # | ||
13 | # This program is distributed in the hope that it will be useful, | ||
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | # GNU General Public License for more details. | ||
17 | # | ||
18 | # You should have received a copy of the GNU General Public License along | ||
19 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
21 | |||
22 | """ | ||
23 | We have the following windows: | ||
24 | |||
25 | 1.) Main Window: Shows what we are ultimately building and how far we are. Includes status bar | ||
26 | 2.) Thread Activity Window: Shows one status line for every concurrent bitbake thread. | ||
27 | 3.) Command Line Window: Contains an interactive command line where you can interact w/ Bitbake. | ||
28 | |||
29 | Basic window layout is like that: | ||
30 | |||
31 | |---------------------------------------------------------| | ||
32 | | <Main Window> | <Thread Activity Window> | | ||
33 | | | 0: foo do_compile complete| | ||
34 | | Building Gtk+-2.6.10 | 1: bar do_patch complete | | ||
35 | | Status: 60% | ... | | ||
36 | | | ... | | ||
37 | | | ... | | ||
38 | |---------------------------------------------------------| | ||
39 | |<Command Line Window> | | ||
40 | |>>> which virtual/kernel | | ||
41 | |openzaurus-kernel | | ||
42 | |>>> _ | | ||
43 | |---------------------------------------------------------| | ||
44 | |||
45 | """ | ||
46 | |||
47 | import os, sys, curses, time, random, threading, itertools, time | ||
48 | from curses.textpad import Textbox | ||
49 | import bb | ||
50 | from bb import ui | ||
51 | from bb.ui import uihelper | ||
52 | |||
53 | parsespin = itertools.cycle( r'|/-\\' ) | ||
54 | |||
55 | X = 0 | ||
56 | Y = 1 | ||
57 | WIDTH = 2 | ||
58 | HEIGHT = 3 | ||
59 | |||
60 | MAXSTATUSLENGTH = 32 | ||
61 | |||
62 | class NCursesUI: | ||
63 | """ | ||
64 | NCurses UI Class | ||
65 | """ | ||
66 | class Window: | ||
67 | """Base Window Class""" | ||
68 | def __init__( self, x, y, width, height, fg=curses.COLOR_BLACK, bg=curses.COLOR_WHITE ): | ||
69 | self.win = curses.newwin( height, width, y, x ) | ||
70 | self.dimensions = ( x, y, width, height ) | ||
71 | """ | ||
72 | if curses.has_colors(): | ||
73 | color = 1 | ||
74 | curses.init_pair( color, fg, bg ) | ||
75 | self.win.bkgdset( ord(' '), curses.color_pair(color) ) | ||
76 | else: | ||
77 | self.win.bkgdset( ord(' '), curses.A_BOLD ) | ||
78 | """ | ||
79 | self.erase() | ||
80 | self.setScrolling() | ||
81 | self.win.noutrefresh() | ||
82 | |||
83 | def erase( self ): | ||
84 | self.win.erase() | ||
85 | |||
86 | def setScrolling( self, b = True ): | ||
87 | self.win.scrollok( b ) | ||
88 | self.win.idlok( b ) | ||
89 | |||
90 | def setBoxed( self ): | ||
91 | self.boxed = True | ||
92 | self.win.box() | ||
93 | self.win.noutrefresh() | ||
94 | |||
95 | def setText( self, x, y, text, *args ): | ||
96 | self.win.addstr( y, x, text, *args ) | ||
97 | self.win.noutrefresh() | ||
98 | |||
99 | def appendText( self, text, *args ): | ||
100 | self.win.addstr( text, *args ) | ||
101 | self.win.noutrefresh() | ||
102 | |||
103 | def drawHline( self, y ): | ||
104 | self.win.hline( y, 0, curses.ACS_HLINE, self.dimensions[WIDTH] ) | ||
105 | self.win.noutrefresh() | ||
106 | |||
107 | class DecoratedWindow( Window ): | ||
108 | """Base class for windows with a box and a title bar""" | ||
109 | def __init__( self, title, x, y, width, height, fg=curses.COLOR_BLACK, bg=curses.COLOR_WHITE ): | ||
110 | NCursesUI.Window.__init__( self, x+1, y+3, width-2, height-4, fg, bg ) | ||
111 | self.decoration = NCursesUI.Window( x, y, width, height, fg, bg ) | ||
112 | self.decoration.setBoxed() | ||
113 | self.decoration.win.hline( 2, 1, curses.ACS_HLINE, width-2 ) | ||
114 | self.setTitle( title ) | ||
115 | |||
116 | def setTitle( self, title ): | ||
117 | self.decoration.setText( 1, 1, title.center( self.dimensions[WIDTH]-2 ), curses.A_BOLD ) | ||
118 | |||
119 | #-------------------------------------------------------------------------# | ||
120 | # class TitleWindow( Window ): | ||
121 | #-------------------------------------------------------------------------# | ||
122 | # """Title Window""" | ||
123 | # def __init__( self, x, y, width, height ): | ||
124 | # NCursesUI.Window.__init__( self, x, y, width, height ) | ||
125 | # version = bb.__version__ | ||
126 | # title = "BitBake %s" % version | ||
127 | # credit = "(C) 2003-2007 Team BitBake" | ||
128 | # #self.win.hline( 2, 1, curses.ACS_HLINE, width-2 ) | ||
129 | # self.win.border() | ||
130 | # self.setText( 1, 1, title.center( self.dimensions[WIDTH]-2 ), curses.A_BOLD ) | ||
131 | # self.setText( 1, 2, credit.center( self.dimensions[WIDTH]-2 ), curses.A_BOLD ) | ||
132 | |||
133 | #-------------------------------------------------------------------------# | ||
134 | class ThreadActivityWindow( DecoratedWindow ): | ||
135 | #-------------------------------------------------------------------------# | ||
136 | """Thread Activity Window""" | ||
137 | def __init__( self, x, y, width, height ): | ||
138 | NCursesUI.DecoratedWindow.__init__( self, "Thread Activity", x, y, width, height ) | ||
139 | |||
140 | def setStatus( self, thread, text ): | ||
141 | line = "%02d: %s" % ( thread, text ) | ||
142 | width = self.dimensions[WIDTH] | ||
143 | if ( len(line) > width ): | ||
144 | line = line[:width-3] + "..." | ||
145 | else: | ||
146 | line = line.ljust( width ) | ||
147 | self.setText( 0, thread, line ) | ||
148 | |||
149 | #-------------------------------------------------------------------------# | ||
150 | class MainWindow( DecoratedWindow ): | ||
151 | #-------------------------------------------------------------------------# | ||
152 | """Main Window""" | ||
153 | def __init__( self, x, y, width, height ): | ||
154 | self.StatusPosition = width - MAXSTATUSLENGTH | ||
155 | NCursesUI.DecoratedWindow.__init__( self, None, x, y, width, height ) | ||
156 | curses.nl() | ||
157 | |||
158 | def setTitle( self, title ): | ||
159 | title = "BitBake %s" % bb.__version__ | ||
160 | self.decoration.setText( 2, 1, title, curses.A_BOLD ) | ||
161 | self.decoration.setText( self.StatusPosition - 8, 1, "Status:", curses.A_BOLD ) | ||
162 | |||
163 | def setStatus(self, status): | ||
164 | while len(status) < MAXSTATUSLENGTH: | ||
165 | status = status + " " | ||
166 | self.decoration.setText( self.StatusPosition, 1, status, curses.A_BOLD ) | ||
167 | |||
168 | |||
169 | #-------------------------------------------------------------------------# | ||
170 | class ShellOutputWindow( DecoratedWindow ): | ||
171 | #-------------------------------------------------------------------------# | ||
172 | """Interactive Command Line Output""" | ||
173 | def __init__( self, x, y, width, height ): | ||
174 | NCursesUI.DecoratedWindow.__init__( self, "Command Line Window", x, y, width, height ) | ||
175 | |||
176 | #-------------------------------------------------------------------------# | ||
177 | class ShellInputWindow( Window ): | ||
178 | #-------------------------------------------------------------------------# | ||
179 | """Interactive Command Line Input""" | ||
180 | def __init__( self, x, y, width, height ): | ||
181 | NCursesUI.Window.__init__( self, x, y, width, height ) | ||
182 | |||
183 | # self.textbox = Textbox( self.win ) | ||
184 | # t = threading.Thread() | ||
185 | # t.run = self.textbox.edit | ||
186 | # t.start() | ||
187 | |||
188 | #-------------------------------------------------------------------------# | ||
189 | def main(self, stdscr, server, eventHandler): | ||
190 | #-------------------------------------------------------------------------# | ||
191 | height, width = stdscr.getmaxyx() | ||
192 | |||
193 | # for now split it like that: | ||
194 | # MAIN_y + THREAD_y = 2/3 screen at the top | ||
195 | # MAIN_x = 2/3 left, THREAD_y = 1/3 right | ||
196 | # CLI_y = 1/3 of screen at the bottom | ||
197 | # CLI_x = full | ||
198 | |||
199 | main_left = 0 | ||
200 | main_top = 0 | ||
201 | main_height = ( height / 3 * 2 ) | ||
202 | main_width = ( width / 3 ) * 2 | ||
203 | clo_left = main_left | ||
204 | clo_top = main_top + main_height | ||
205 | clo_height = height - main_height - main_top - 1 | ||
206 | clo_width = width | ||
207 | cli_left = main_left | ||
208 | cli_top = clo_top + clo_height | ||
209 | cli_height = 1 | ||
210 | cli_width = width | ||
211 | thread_left = main_left + main_width | ||
212 | thread_top = main_top | ||
213 | thread_height = main_height | ||
214 | thread_width = width - main_width | ||
215 | |||
216 | #tw = self.TitleWindow( 0, 0, width, main_top ) | ||
217 | mw = self.MainWindow( main_left, main_top, main_width, main_height ) | ||
218 | taw = self.ThreadActivityWindow( thread_left, thread_top, thread_width, thread_height ) | ||
219 | clo = self.ShellOutputWindow( clo_left, clo_top, clo_width, clo_height ) | ||
220 | cli = self.ShellInputWindow( cli_left, cli_top, cli_width, cli_height ) | ||
221 | cli.setText( 0, 0, "BB>" ) | ||
222 | |||
223 | mw.setStatus("Idle") | ||
224 | |||
225 | helper = uihelper.BBUIHelper() | ||
226 | shutdown = 0 | ||
227 | |||
228 | try: | ||
229 | cmdline = server.runCommand(["getCmdLineAction"]) | ||
230 | if not cmdline: | ||
231 | return | ||
232 | ret = server.runCommand(cmdline) | ||
233 | if ret != True: | ||
234 | print "Couldn't get default commandlind! %s" % ret | ||
235 | return | ||
236 | except xmlrpclib.Fault, x: | ||
237 | print "XMLRPC Fault getting commandline:\n %s" % x | ||
238 | return | ||
239 | |||
240 | exitflag = False | ||
241 | while not exitflag: | ||
242 | try: | ||
243 | event = eventHandler.waitEvent(0.25) | ||
244 | if not event: | ||
245 | continue | ||
246 | helper.eventHandler(event) | ||
247 | #mw.appendText("%s\n" % event[0]) | ||
248 | if event[0].startswith('bb.event.Pkg'): | ||
249 | mw.appendText("NOTE: %s\n" % event[1]['_message']) | ||
250 | if event[0].startswith('bb.build.Task'): | ||
251 | mw.appendText("NOTE: %s\n" % event[1]['_message']) | ||
252 | if event[0].startswith('bb.msg.MsgDebug'): | ||
253 | mw.appendText('DEBUG: ' + event[1]['_message'] + '\n') | ||
254 | if event[0].startswith('bb.msg.MsgNote'): | ||
255 | mw.appendText('NOTE: ' + event[1]['_message'] + '\n') | ||
256 | if event[0].startswith('bb.msg.MsgWarn'): | ||
257 | mw.appendText('WARNING: ' + event[1]['_message'] + '\n') | ||
258 | if event[0].startswith('bb.msg.MsgError'): | ||
259 | mw.appendText('ERROR: ' + event[1]['_message'] + '\n') | ||
260 | if event[0].startswith('bb.msg.MsgFatal'): | ||
261 | mw.appendText('FATAL: ' + event[1]['_message'] + '\n') | ||
262 | if event[0].startswith('bb.event.ParseProgress'): | ||
263 | x = event[1]['sofar'] | ||
264 | y = event[1]['total'] | ||
265 | if x == y: | ||
266 | mw.setStatus("Idle") | ||
267 | mw.appendText("Parsing finished. %d cached, %d parsed, %d skipped, %d masked." | ||
268 | % ( event[1]['cached'], event[1]['parsed'], event[1]['skipped'], event[1]['masked'] )) | ||
269 | else: | ||
270 | mw.setStatus("Parsing: %s (%04d/%04d) [%2d %%]" % ( parsespin.next(), x, y, x*100/y ) ) | ||
271 | # if event[0].startswith('bb.build.TaskFailed'): | ||
272 | # if event[1]['logfile']: | ||
273 | # if data.getVar("BBINCLUDELOGS", d): | ||
274 | # bb.msg.error(bb.msg.domain.Build, "log data follows (%s)" % logfile) | ||
275 | # number_of_lines = data.getVar("BBINCLUDELOGS_LINES", d) | ||
276 | # if number_of_lines: | ||
277 | # os.system('tail -n%s %s' % (number_of_lines, logfile)) | ||
278 | # else: | ||
279 | # f = open(logfile, "r") | ||
280 | # while True: | ||
281 | # l = f.readline() | ||
282 | # if l == '': | ||
283 | # break | ||
284 | # l = l.rstrip() | ||
285 | # print '| %s' % l | ||
286 | # f.close() | ||
287 | # else: | ||
288 | # bb.msg.error(bb.msg.domain.Build, "see log in %s" % logfile) | ||
289 | |||
290 | if event[0] == 'bb.command.CookerCommandCompleted': | ||
291 | exitflag = True | ||
292 | if event[0] == 'bb.command.CookerCommandFailed': | ||
293 | mw.appendText("Command execution failed: %s" % event[1]['error']) | ||
294 | time.sleep(2) | ||
295 | exitflag = True | ||
296 | if event[0] == 'bb.cooker.CookerExit': | ||
297 | exitflag = True | ||
298 | |||
299 | if helper.needUpdate: | ||
300 | activetasks, failedtasks = helper.getTasks() | ||
301 | taw.erase() | ||
302 | taw.setText(0, 0, "") | ||
303 | if activetasks: | ||
304 | taw.appendText("Active Tasks:\n") | ||
305 | for task in activetasks: | ||
306 | taw.appendText(task) | ||
307 | if failedtasks: | ||
308 | taw.appendText("Failed Tasks:\n") | ||
309 | for task in failedtasks: | ||
310 | taw.appendText(task) | ||
311 | |||
312 | curses.doupdate() | ||
313 | except KeyboardInterrupt: | ||
314 | if shutdown == 2: | ||
315 | mw.appendText("Third Keyboard Interrupt, exit.\n") | ||
316 | exitflag = True | ||
317 | if shutdown == 1: | ||
318 | mw.appendText("Second Keyboard Interrupt, stopping...\n") | ||
319 | server.runCommand(["stateStop"]) | ||
320 | if shutdown == 0: | ||
321 | mw.appendText("Keyboard Interrupt, closing down...\n") | ||
322 | server.runCommand(["stateShutdown"]) | ||
323 | shutdown = shutdown + 1 | ||
324 | pass | ||
325 | |||
326 | def init(server, eventHandler): | ||
327 | ui = NCursesUI() | ||
328 | try: | ||
329 | curses.wrapper(ui.main, server, eventHandler) | ||
330 | except: | ||
331 | import traceback | ||
332 | traceback.print_exc() | ||
333 | |||