diff options
author | Cristiana Voicu <cristiana.voicu@intel.com> | 2013-11-12 18:12:17 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-11-12 17:01:37 +0000 |
commit | ea92671d9823e3667d6ced7ac2af20f991da404d (patch) | |
tree | e330ea690c7388d3cebaa2c7e112caaf2852a69f /bitbake/lib/bb | |
parent | 8c534107d9129489f96c3c6af56d45d806cc60ad (diff) | |
download | poky-ea92671d9823e3667d6ced7ac2af20f991da404d.tar.gz |
bitbake: cooker: replace "w" file opening mode with "a" mode
Also removed some redundant file manipulation code
Based on patch sent by Stefan Stanacar <stefanx.stanacar@intel.com>
(Bitbake rev: e054c1e7c8581f66082fcdfb89769401ca6e78a3)
Signed-off-by: Cristiana Voicu <cristiana.voicu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb')
-rw-r--r-- | bitbake/lib/bb/cooker.py | 40 |
1 files changed, 6 insertions, 34 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py index 0af4558fde..0580cd5508 100644 --- a/bitbake/lib/bb/cooker.py +++ b/bitbake/lib/bb/cooker.py | |||
@@ -202,20 +202,11 @@ class BBCooker: | |||
202 | #add append var operation to the end of default_file | 202 | #add append var operation to the end of default_file |
203 | default_file = bb.cookerdata.findConfigFile(default_file, self.data) | 203 | default_file = bb.cookerdata.findConfigFile(default_file, self.data) |
204 | 204 | ||
205 | with open(default_file, 'r') as f: | 205 | total = "#added by hob" |
206 | contents = f.readlines() | ||
207 | f.close() | ||
208 | |||
209 | total = "" | ||
210 | for c in contents: | ||
211 | total += c | ||
212 | |||
213 | total += "#added by hob" | ||
214 | total += "\n%s += \"%s\"\n" % (var, val) | 206 | total += "\n%s += \"%s\"\n" % (var, val) |
215 | 207 | ||
216 | with open(default_file, 'w') as f: | 208 | with open(default_file, 'a') as f: |
217 | f.write(total) | 209 | f.write(total) |
218 | f.close() | ||
219 | 210 | ||
220 | #add to history | 211 | #add to history |
221 | loginfo = {"op":append, "file":default_file, "line":total.count("\n")} | 212 | loginfo = {"op":append, "file":default_file, "line":total.count("\n")} |
@@ -244,7 +235,6 @@ class BBCooker: | |||
244 | if topdir in conf_file: | 235 | if topdir in conf_file: |
245 | with open(conf_file, 'r') as f: | 236 | with open(conf_file, 'r') as f: |
246 | contents = f.readlines() | 237 | contents = f.readlines() |
247 | f.close() | ||
248 | 238 | ||
249 | lines = self.data.varhistory.get_variable_lines(var, conf_file) | 239 | lines = self.data.varhistory.get_variable_lines(var, conf_file) |
250 | for line in lines: | 240 | for line in lines: |
@@ -270,12 +260,8 @@ class BBCooker: | |||
270 | for ii in range(begin_line, end_line): | 260 | for ii in range(begin_line, end_line): |
271 | contents[ii] = "#" + contents[ii] | 261 | contents[ii] = "#" + contents[ii] |
272 | 262 | ||
273 | total = "" | ||
274 | for c in contents: | ||
275 | total += c | ||
276 | with open(conf_file, 'w') as f: | 263 | with open(conf_file, 'w') as f: |
277 | f.write(total) | 264 | f.writelines(contents) |
278 | f.close() | ||
279 | 265 | ||
280 | if replaced == False: | 266 | if replaced == False: |
281 | #remove var from history | 267 | #remove var from history |
@@ -284,21 +270,12 @@ class BBCooker: | |||
284 | #add var to the end of default_file | 270 | #add var to the end of default_file |
285 | default_file = bb.cookerdata.findConfigFile(default_file, self.data) | 271 | default_file = bb.cookerdata.findConfigFile(default_file, self.data) |
286 | 272 | ||
287 | with open(default_file, 'r') as f: | ||
288 | contents = f.readlines() | ||
289 | f.close() | ||
290 | |||
291 | total = "" | ||
292 | for c in contents: | ||
293 | total += c | ||
294 | |||
295 | #add the variable on a single line, to be easy to replace the second time | 273 | #add the variable on a single line, to be easy to replace the second time |
296 | total += "\n#added by hob" | 274 | total = "\n#added by hob" |
297 | total += "\n%s %s \"%s\"\n" % (var, op, val) | 275 | total += "\n%s %s \"%s\"\n" % (var, op, val) |
298 | 276 | ||
299 | with open(default_file, 'w') as f: | 277 | with open(default_file, 'a') as f: |
300 | f.write(total) | 278 | f.write(total) |
301 | f.close() | ||
302 | 279 | ||
303 | #add to history | 280 | #add to history |
304 | loginfo = {"op":set, "file":default_file, "line":total.count("\n")} | 281 | loginfo = {"op":set, "file":default_file, "line":total.count("\n")} |
@@ -312,7 +289,6 @@ class BBCooker: | |||
312 | if topdir in conf_file: | 289 | if topdir in conf_file: |
313 | with open(conf_file, 'r') as f: | 290 | with open(conf_file, 'r') as f: |
314 | contents = f.readlines() | 291 | contents = f.readlines() |
315 | f.close() | ||
316 | 292 | ||
317 | lines = self.data.varhistory.get_variable_lines(var, conf_file) | 293 | lines = self.data.varhistory.get_variable_lines(var, conf_file) |
318 | for line in lines: | 294 | for line in lines: |
@@ -335,12 +311,8 @@ class BBCooker: | |||
335 | #remove var from history | 311 | #remove var from history |
336 | self.data.varhistory.del_var_history(var, conf_file, line) | 312 | self.data.varhistory.del_var_history(var, conf_file, line) |
337 | 313 | ||
338 | total = "" | ||
339 | for c in contents: | ||
340 | total += c | ||
341 | with open(conf_file, 'w') as f: | 314 | with open(conf_file, 'w') as f: |
342 | f.write(total) | 315 | f.writelines(contents) |
343 | f.close() | ||
344 | 316 | ||
345 | def createConfigFile(self, name): | 317 | def createConfigFile(self, name): |
346 | path = os.getcwd() | 318 | path = os.getcwd() |