2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
5 # Copyright (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>, Vanille Media
7 # This program is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free Software
9 # Foundation; version 2 of the License.
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along with
16 # this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 # Place, Suite 330, Boston, MA 02111-1307 USA.
23 General Question to be decided: Make it a full-fledged Python Shell or
24 retain the simple command line interface like it is at the moment?
27 * readline completion (file and provider?)
30 * command to clean stamps
31 * command to reparse one bbfile
32 * automatic check if reparsing is necessary (inotify?)
34 * call editor on bb file
35 * clean-and-rebuild bbfile
41 from sets import Set as set
42 import sys, os, imp, readline
43 imp.load_source( "bitbake", os.path.dirname( sys.argv[0] )+"/bitbake" )
44 from bb import make, data
47 __credits__ = """BitBake Shell Version %2.1f (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
48 Type 'help' for more information, press CTRL-D to exit.""" % __version__
51 leave_mainloop = False
56 history_file = "%s/.bbsh_history" % os.environ.get( "HOME" )
58 #============================ start of commands ==================
60 def buildCommand( params, cmd = "build" ):
61 """Build a .bb file or a provider"""
65 print "Usage: build <bbfile|provider>"
67 make.options.cmd = cmd
68 cooker.build_cache = []
69 cooker.build_cache_fail = []
71 if name.endswith( ".bb" ):
72 cooker.executeOneBB( os.path.abspath( name ) )
75 print "BBSHELL: D'oh! The .bb files haven't been parsed yet. Next time call 'parse' before building stuff. This time I'll do it for 'ya."
77 cooker.buildPackage( name )
79 def cleanCommand( params ):
80 """Clean a .bb file or a provider"""
81 buildCommand( params, "clean" )
83 def editCommand( params ):
84 """Call $EDITOR on a .bb file"""
88 print "Usage: edit <bbfile>"
90 os.system( "%s %s" % ( os.environ.get( "EDITOR" ), name ) )
92 def exitShell( params ):
93 """Leave the BitBake Shell"""
94 if debug: print "(setting leave_mainloop to true)"
98 def parseCommand( params ):
99 """(Re-)parse .bb files and calculate the dependency graph"""
100 cooker.status = cooker.ParsingStatus()
101 ignore = data.getVar("ASSUME_PROVIDED", make.cfg, 1) or ""
102 cooker.status.ignored_dependencies = set( ignore.split() )
103 cooker.handleCollections( data.getVar("BBFILE_COLLECTIONS", make.cfg, 1) )
105 make.collect_bbfiles( cooker.myProgressCallback )
106 cooker.buildDepgraph()
111 def environmentCommand( params ):
112 """Dump out the outer BitBake environment (see bbread)"""
113 data.emit_env(sys.__stdout__, make.cfg, True)
115 def printCommand( params ):
116 """Print the contents of an outer BitBake environment variable"""
120 print "Usage: print <variable>"
122 value = data.getVar( var, make.cfg, 1 )
125 def rebuildCommand( params ):
126 """Clean and rebuild a .bb file or a provider"""
127 buildCommand( params, "clean" )
128 buildCommand( params, "build" )
130 def setVarCommand( params ):
131 """Set an outer BitBake environment variable"""
134 except ValueError, IndexError:
135 print "Usage: set <variable> <value>"
137 data.setVar( var, value, make.cfg )
140 #============================ end of commands ==================
143 """Register commands and set up readline"""
144 registerCommand( "help", showHelp )
145 registerCommand( "exit", exitShell )
147 registerCommand( "build", buildCommand )
148 registerCommand( "clean", cleanCommand )
149 registerCommand( "edit", editCommand )
150 registerCommand( "environment", environmentCommand )
151 registerCommand( "parse", parseCommand )
152 registerCommand( "print", printCommand )
153 registerCommand( "rebuild", rebuildCommand )
154 registerCommand( "set", setVarCommand )
156 readline.set_completer( completer )
157 readline.parse_and_bind("tab: complete")
161 readline.read_history_file( history_file )
163 pass # It doesn't exist yet.
166 if debug: print "(writing command history)"
169 readline.write_history_file( history_file )
171 print "BBSHELL: Unable to save command history"
173 def completer( *args, **kwargs ):
174 print "completer called", args, kwargs
180 def showHelp( *args ):
181 """Show a comprehensive list of commands and their purpose"""
182 print "="*35, "Available Commands", "="*35
183 for cmd, func in cmds.items():
184 print "| %s | %s" % (cmd.ljust(max([len(x) for x in cmds.keys()])), func.__doc__)
187 def registerCommand( command, function ):
188 cmds[command] = function
190 def processCommand( command, params ):
191 if debug: print "(processing command '%s'...)" % command
193 result = cmds[command]( params )
195 print "Error: '%s' command is not a valid command." % command
197 if debug: print "(result was '%s')" % result
200 while not leave_mainloop:
202 cmdline = raw_input( "BB>> " )
205 processCommand( cmdline.split()[0], cmdline.split()[1:] )
207 processCommand( cmdline, "" )
211 except KeyboardInterrupt:
214 def start( aCooker ):
222 if __name__ == "__main__":
223 print "BBSHELL: Sorry, this program should only be called by BitBake."