summaryrefslogtreecommitdiffstats
path: root/bitbake-dev/lib/bb/command.py
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2008-09-30 15:08:33 +0000
committerRichard Purdie <richard@openedhand.com>2008-09-30 15:08:33 +0000
commitc30eddb243e7e65f67f656e62848a033cf6f2e5c (patch)
tree110dd95788b76f55d31cb8d30aac2de8400b6f4a /bitbake-dev/lib/bb/command.py
parent5ef0510474004eeb2ae8a99b64e2febb1920e077 (diff)
downloadpoky-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/command.py')
-rw-r--r--bitbake-dev/lib/bb/command.py211
1 files changed, 211 insertions, 0 deletions
diff --git a/bitbake-dev/lib/bb/command.py b/bitbake-dev/lib/bb/command.py
new file mode 100644
index 0000000000..8384e89e55
--- /dev/null
+++ b/bitbake-dev/lib/bb/command.py
@@ -0,0 +1,211 @@
1"""
2BitBake 'Command' module
3
4Provide an interface to interact with the bitbake server through 'commands'
5"""
6
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"""
23The bitbake server takes 'commands' from its UI/commandline.
24Commands are either 'online' of 'offline' in nature.
25Offline commands return data to the client in the form of events.
26Online commands must only return data through the function return value
27and must not trigger events, directly or indirectly.
28Commands are queued in a CommandQueue
29"""
30
31import bb
32
33offline_cmds = {}
34online_cmds = {}
35
36class Command:
37 """
38 A queue of 'offline' commands for bitbake
39 """
40 def __init__(self, cooker):
41
42 self.cooker = cooker
43 self.cmds_online = CommandsOnline()
44 self.cmds_offline = CommandsOffline()
45
46 # FIXME Add lock for this
47 self.currentOfflineCommand = None
48
49 for attr in CommandsOnline.__dict__:
50 command = attr[:].lower()
51 method = getattr(CommandsOnline, attr)
52 online_cmds[command] = (method)
53
54 for attr in CommandsOffline.__dict__:
55 command = attr[:].lower()
56 method = getattr(CommandsOffline, attr)
57 offline_cmds[command] = (method)
58
59 def runCommand(self, commandline):
60 try:
61 command = commandline.pop(0)
62 if command in CommandsOnline.__dict__:
63 # Can run online commands straight away
64 return getattr(CommandsOnline, command)(self.cmds_online, self, commandline)
65 if self.currentOfflineCommand is not None:
66 return "Busy (%s in progress)" % self.currentOfflineCommand[0]
67 if command not in CommandsOffline.__dict__:
68 return "No such command"
69 self.currentOfflineCommand = (command, commandline)
70 return True
71 except:
72 import traceback
73 return traceback.format_exc()
74
75 def runOfflineCommand(self):
76 try:
77 if self.currentOfflineCommand is not None:
78 (command, options) = self.currentOfflineCommand
79 getattr(CommandsOffline, command)(self.cmds_offline, self, options)
80 except:
81 import traceback
82 self.finishOfflineCommand(traceback.format_exc())
83
84 def finishOfflineCommand(self, error = None):
85 if error:
86 bb.event.fire(bb.command.CookerCommandFailed(self.cooker.configuration.event_data, error))
87 else:
88 bb.event.fire(bb.command.CookerCommandCompleted(self.cooker.configuration.event_data))
89 self.currentOfflineCommand = None
90
91
92class CommandsOnline:
93 """
94 A class of online commands
95 These should run quickly so as not to hurt interactive performance.
96 These must not influence any running offline command.
97 """
98
99 def stateShutdown(self, command, params):
100 """
101 Trigger cooker 'shutdown' mode
102 """
103 command.cooker.cookerAction = bb.cooker.cookerShutdown
104
105 def stateStop(self, command, params):
106 """
107 Stop the cooker
108 """
109 command.cooker.cookerAction = bb.cooker.cookerStop
110
111 def getCmdLineAction(self, command, params):
112 """
113 Get any command parsed from the commandline
114 """
115 return command.cooker.commandlineAction
116
117 def readVariable(self, command, params):
118 """
119 Read the value of a variable from configuration.data
120 """
121 varname = params[0]
122 expand = True
123 if len(params) > 1:
124 expand = params[1]
125
126 return bb.data.getVar(varname, command.cooker.configuration.data, expand)
127
128class CommandsOffline:
129 """
130 A class of offline commands
131 These functions communicate via generated events.
132 Any function that requires metadata parsing should be here.
133 """
134
135 def buildFile(self, command, params):
136 """
137 Build a single specified .bb file
138 """
139 bfile = params[0]
140 task = params[1]
141
142 command.cooker.buildFile(bfile, task)
143
144 def buildTargets(self, command, params):
145 """
146 Build a set of targets
147 """
148 pkgs_to_build = params[0]
149
150 command.cooker.buildTargets(pkgs_to_build)
151
152 def generateDepTreeEvent(self, command, params):
153 """
154 Generate an event containing the dependency information
155 """
156 pkgs_to_build = params[0]
157
158 command.cooker.generateDepTreeEvent(pkgs_to_build)
159 command.finishOfflineCommand()
160
161 def generateDotGraph(self, command, params):
162 """
163 Dump dependency information to disk as .dot files
164 """
165 pkgs_to_build = params[0]
166
167 command.cooker.generateDotGraphFiles(pkgs_to_build)
168 command.finishOfflineCommand()
169
170 def showVersions(self, command, params):
171 """
172 Show the currently selected versions
173 """
174 command.cooker.showVersions()
175 command.finishOfflineCommand()
176
177 def showEnvironment(self, command, params):
178 """
179 Print the environment
180 """
181 bfile = params[0]
182 pkg = params[1]
183
184 command.cooker.showEnvironment(bfile, pkg)
185 command.finishOfflineCommand()
186
187 def parseFiles(self, command, params):
188 """
189 Parse the .bb files
190 """
191 command.cooker.updateCache()
192 command.finishOfflineCommand()
193
194#
195# Events
196#
197class CookerCommandCompleted(bb.event.Event):
198 """
199 Cooker command completed
200 """
201 def __init__(self, data):
202 bb.event.Event.__init__(self, data)
203
204
205class CookerCommandFailed(bb.event.Event):
206 """
207 Cooker command completed
208 """
209 def __init__(self, data, error):
210 bb.event.Event.__init__(self, data)
211 self.error = error