diff options
Diffstat (limited to 'bitbake/lib/bb/data.py')
-rw-r--r-- | bitbake/lib/bb/data.py | 163 |
1 files changed, 13 insertions, 150 deletions
diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py index 5938277273..cc5594e41e 100644 --- a/bitbake/lib/bb/data.py +++ b/bitbake/lib/bb/data.py | |||
@@ -77,90 +77,33 @@ def initVar(var, d): | |||
77 | 77 | ||
78 | 78 | ||
79 | def setVar(var, value, d): | 79 | def setVar(var, value, d): |
80 | """Set a variable to a given value | 80 | """Set a variable to a given value""" |
81 | |||
82 | Example: | ||
83 | >>> d = init() | ||
84 | >>> setVar('TEST', 'testcontents', d) | ||
85 | >>> print getVar('TEST', d) | ||
86 | testcontents | ||
87 | """ | ||
88 | d.setVar(var,value) | 81 | d.setVar(var,value) |
89 | 82 | ||
90 | 83 | ||
91 | def getVar(var, d, exp = 0): | 84 | def getVar(var, d, exp = 0): |
92 | """Gets the value of a variable | 85 | """Gets the value of a variable""" |
93 | |||
94 | Example: | ||
95 | >>> d = init() | ||
96 | >>> setVar('TEST', 'testcontents', d) | ||
97 | >>> print getVar('TEST', d) | ||
98 | testcontents | ||
99 | """ | ||
100 | return d.getVar(var,exp) | 86 | return d.getVar(var,exp) |
101 | 87 | ||
102 | 88 | ||
103 | def renameVar(key, newkey, d): | 89 | def renameVar(key, newkey, d): |
104 | """Renames a variable from key to newkey | 90 | """Renames a variable from key to newkey""" |
105 | |||
106 | Example: | ||
107 | >>> d = init() | ||
108 | >>> setVar('TEST', 'testcontents', d) | ||
109 | >>> renameVar('TEST', 'TEST2', d) | ||
110 | >>> print getVar('TEST2', d) | ||
111 | testcontents | ||
112 | """ | ||
113 | d.renameVar(key, newkey) | 91 | d.renameVar(key, newkey) |
114 | 92 | ||
115 | def delVar(var, d): | 93 | def delVar(var, d): |
116 | """Removes a variable from the data set | 94 | """Removes a variable from the data set""" |
117 | |||
118 | Example: | ||
119 | >>> d = init() | ||
120 | >>> setVar('TEST', 'testcontents', d) | ||
121 | >>> print getVar('TEST', d) | ||
122 | testcontents | ||
123 | >>> delVar('TEST', d) | ||
124 | >>> print getVar('TEST', d) | ||
125 | None | ||
126 | """ | ||
127 | d.delVar(var) | 95 | d.delVar(var) |
128 | 96 | ||
129 | def setVarFlag(var, flag, flagvalue, d): | 97 | def setVarFlag(var, flag, flagvalue, d): |
130 | """Set a flag for a given variable to a given value | 98 | """Set a flag for a given variable to a given value""" |
131 | |||
132 | Example: | ||
133 | >>> d = init() | ||
134 | >>> setVarFlag('TEST', 'python', 1, d) | ||
135 | >>> print getVarFlag('TEST', 'python', d) | ||
136 | 1 | ||
137 | """ | ||
138 | d.setVarFlag(var,flag,flagvalue) | 99 | d.setVarFlag(var,flag,flagvalue) |
139 | 100 | ||
140 | def getVarFlag(var, flag, d): | 101 | def getVarFlag(var, flag, d): |
141 | """Gets given flag from given var | 102 | """Gets given flag from given var""" |
142 | |||
143 | Example: | ||
144 | >>> d = init() | ||
145 | >>> setVarFlag('TEST', 'python', 1, d) | ||
146 | >>> print getVarFlag('TEST', 'python', d) | ||
147 | 1 | ||
148 | """ | ||
149 | return d.getVarFlag(var,flag) | 103 | return d.getVarFlag(var,flag) |
150 | 104 | ||
151 | def delVarFlag(var, flag, d): | 105 | def delVarFlag(var, flag, d): |
152 | """Removes a given flag from the variable's flags | 106 | """Removes a given flag from the variable's flags""" |
153 | |||
154 | Example: | ||
155 | >>> d = init() | ||
156 | >>> setVarFlag('TEST', 'testflag', 1, d) | ||
157 | >>> print getVarFlag('TEST', 'testflag', d) | ||
158 | 1 | ||
159 | >>> delVarFlag('TEST', 'testflag', d) | ||
160 | >>> print getVarFlag('TEST', 'testflag', d) | ||
161 | None | ||
162 | |||
163 | """ | ||
164 | d.delVarFlag(var,flag) | 107 | d.delVarFlag(var,flag) |
165 | 108 | ||
166 | def setVarFlags(var, flags, d): | 109 | def setVarFlags(var, flags, d): |
@@ -170,54 +113,19 @@ def setVarFlags(var, flags, d): | |||
170 | setVarFlags will not clear previous | 113 | setVarFlags will not clear previous |
171 | flags. Think of this method as | 114 | flags. Think of this method as |
172 | addVarFlags | 115 | addVarFlags |
173 | |||
174 | Example: | ||
175 | >>> d = init() | ||
176 | >>> myflags = {} | ||
177 | >>> myflags['test'] = 'blah' | ||
178 | >>> setVarFlags('TEST', myflags, d) | ||
179 | >>> print getVarFlag('TEST', 'test', d) | ||
180 | blah | ||
181 | """ | 116 | """ |
182 | d.setVarFlags(var,flags) | 117 | d.setVarFlags(var,flags) |
183 | 118 | ||
184 | def getVarFlags(var, d): | 119 | def getVarFlags(var, d): |
185 | """Gets a variable's flags | 120 | """Gets a variable's flags""" |
186 | |||
187 | Example: | ||
188 | >>> d = init() | ||
189 | >>> setVarFlag('TEST', 'test', 'blah', d) | ||
190 | >>> print getVarFlags('TEST', d)['test'] | ||
191 | blah | ||
192 | """ | ||
193 | return d.getVarFlags(var) | 121 | return d.getVarFlags(var) |
194 | 122 | ||
195 | def delVarFlags(var, d): | 123 | def delVarFlags(var, d): |
196 | """Removes a variable's flags | 124 | """Removes a variable's flags""" |
197 | |||
198 | Example: | ||
199 | >>> data = init() | ||
200 | >>> setVarFlag('TEST', 'testflag', 1, data) | ||
201 | >>> print getVarFlag('TEST', 'testflag', data) | ||
202 | 1 | ||
203 | >>> delVarFlags('TEST', data) | ||
204 | >>> print getVarFlags('TEST', data) | ||
205 | None | ||
206 | |||
207 | """ | ||
208 | d.delVarFlags(var) | 125 | d.delVarFlags(var) |
209 | 126 | ||
210 | def keys(d): | 127 | def keys(d): |
211 | """Return a list of keys in d | 128 | """Return a list of keys in d""" |
212 | |||
213 | Example: | ||
214 | >>> d = init() | ||
215 | >>> setVar('TEST', 1, d) | ||
216 | >>> setVar('MOO' , 2, d) | ||
217 | >>> setVarFlag('TEST', 'test', 1, d) | ||
218 | >>> keys(d) | ||
219 | ['TEST', 'MOO'] | ||
220 | """ | ||
221 | return d.keys() | 129 | return d.keys() |
222 | 130 | ||
223 | def getData(d): | 131 | def getData(d): |
@@ -253,32 +161,7 @@ __expand_var_regexp__ = re.compile(r"\${[^{}]+}") | |||
253 | __expand_python_regexp__ = re.compile(r"\${@.+?}") | 161 | __expand_python_regexp__ = re.compile(r"\${@.+?}") |
254 | 162 | ||
255 | def expand(s, d, varname = None): | 163 | def expand(s, d, varname = None): |
256 | """Variable expansion using the data store. | 164 | """Variable expansion using the data store""" |
257 | |||
258 | Example: | ||
259 | Standard expansion: | ||
260 | >>> d = init() | ||
261 | >>> setVar('A', 'sshd', d) | ||
262 | >>> print expand('/usr/bin/${A}', d) | ||
263 | /usr/bin/sshd | ||
264 | |||
265 | Python expansion: | ||
266 | >>> d = init() | ||
267 | >>> print expand('result: ${@37 * 72}', d) | ||
268 | result: 2664 | ||
269 | |||
270 | Shell expansion: | ||
271 | >>> d = init() | ||
272 | >>> print expand('${TARGET_MOO}', d) | ||
273 | ${TARGET_MOO} | ||
274 | >>> setVar('TARGET_MOO', 'yupp', d) | ||
275 | >>> print expand('${TARGET_MOO}',d) | ||
276 | yupp | ||
277 | >>> setVar('SRC_URI', 'http://somebug.${TARGET_MOO}', d) | ||
278 | >>> delVar('TARGET_MOO', d) | ||
279 | >>> print expand('${SRC_URI}', d) | ||
280 | http://somebug.${TARGET_MOO} | ||
281 | """ | ||
282 | return d.expand(s, varname) | 165 | return d.expand(s, varname) |
283 | 166 | ||
284 | def expandKeys(alterdata, readdata = None): | 167 | def expandKeys(alterdata, readdata = None): |
@@ -304,17 +187,8 @@ def expandKeys(alterdata, readdata = None): | |||
304 | 187 | ||
305 | def expandData(alterdata, readdata = None): | 188 | def expandData(alterdata, readdata = None): |
306 | """For each variable in alterdata, expand it, and update the var contents. | 189 | """For each variable in alterdata, expand it, and update the var contents. |
307 | Replacements use data from readdata. | 190 | Replacements use data from readdata |
308 | 191 | """ | |
309 | Example: | ||
310 | >>> a=init() | ||
311 | >>> b=init() | ||
312 | >>> setVar("dlmsg", "dl_dir is ${DL_DIR}", a) | ||
313 | >>> setVar("DL_DIR", "/path/to/whatever", b) | ||
314 | >>> expandData(a, b) | ||
315 | >>> print getVar("dlmsg", a) | ||
316 | dl_dir is /path/to/whatever | ||
317 | """ | ||
318 | if readdata == None: | 192 | if readdata == None: |
319 | readdata = alterdata | 193 | readdata = alterdata |
320 | 194 | ||
@@ -418,14 +292,3 @@ def inherits_class(klass, d): | |||
418 | if os.path.join('classes', '%s.bbclass' % klass) in val: | 292 | if os.path.join('classes', '%s.bbclass' % klass) in val: |
419 | return True | 293 | return True |
420 | return False | 294 | return False |
421 | |||
422 | def _test(): | ||
423 | """Start a doctest run on this module""" | ||
424 | import doctest | ||
425 | import bb | ||
426 | from bb import data | ||
427 | bb.msg.set_debug_level(0) | ||
428 | doctest.testmod(data) | ||
429 | |||
430 | if __name__ == "__main__": | ||
431 | _test() | ||