1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-01 00:59:48 +00:00

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>
This commit is contained in:
Cristiana Voicu
2013-11-12 18:12:17 +02:00
committed by Richard Purdie
parent 8c534107d9
commit ea92671d98
+6 -34
View File
@@ -202,20 +202,11 @@ class BBCooker:
#add append var operation to the end of default_file #add append var operation to the end of default_file
default_file = bb.cookerdata.findConfigFile(default_file, self.data) default_file = bb.cookerdata.findConfigFile(default_file, self.data)
with open(default_file, 'r') as f: total = "#added by hob"
contents = f.readlines()
f.close()
total = ""
for c in contents:
total += c
total += "#added by hob"
total += "\n%s += \"%s\"\n" % (var, val) total += "\n%s += \"%s\"\n" % (var, val)
with open(default_file, 'w') as f: with open(default_file, 'a') as f:
f.write(total) f.write(total)
f.close()
#add to history #add to history
loginfo = {"op":append, "file":default_file, "line":total.count("\n")} loginfo = {"op":append, "file":default_file, "line":total.count("\n")}
@@ -244,7 +235,6 @@ class BBCooker:
if topdir in conf_file: if topdir in conf_file:
with open(conf_file, 'r') as f: with open(conf_file, 'r') as f:
contents = f.readlines() contents = f.readlines()
f.close()
lines = self.data.varhistory.get_variable_lines(var, conf_file) lines = self.data.varhistory.get_variable_lines(var, conf_file)
for line in lines: for line in lines:
@@ -270,12 +260,8 @@ class BBCooker:
for ii in range(begin_line, end_line): for ii in range(begin_line, end_line):
contents[ii] = "#" + contents[ii] contents[ii] = "#" + contents[ii]
total = ""
for c in contents:
total += c
with open(conf_file, 'w') as f: with open(conf_file, 'w') as f:
f.write(total) f.writelines(contents)
f.close()
if replaced == False: if replaced == False:
#remove var from history #remove var from history
@@ -284,21 +270,12 @@ class BBCooker:
#add var to the end of default_file #add var to the end of default_file
default_file = bb.cookerdata.findConfigFile(default_file, self.data) default_file = bb.cookerdata.findConfigFile(default_file, self.data)
with open(default_file, 'r') as f:
contents = f.readlines()
f.close()
total = ""
for c in contents:
total += c
#add the variable on a single line, to be easy to replace the second time #add the variable on a single line, to be easy to replace the second time
total += "\n#added by hob" total = "\n#added by hob"
total += "\n%s %s \"%s\"\n" % (var, op, val) total += "\n%s %s \"%s\"\n" % (var, op, val)
with open(default_file, 'w') as f: with open(default_file, 'a') as f:
f.write(total) f.write(total)
f.close()
#add to history #add to history
loginfo = {"op":set, "file":default_file, "line":total.count("\n")} loginfo = {"op":set, "file":default_file, "line":total.count("\n")}
@@ -312,7 +289,6 @@ class BBCooker:
if topdir in conf_file: if topdir in conf_file:
with open(conf_file, 'r') as f: with open(conf_file, 'r') as f:
contents = f.readlines() contents = f.readlines()
f.close()
lines = self.data.varhistory.get_variable_lines(var, conf_file) lines = self.data.varhistory.get_variable_lines(var, conf_file)
for line in lines: for line in lines:
@@ -335,12 +311,8 @@ class BBCooker:
#remove var from history #remove var from history
self.data.varhistory.del_var_history(var, conf_file, line) self.data.varhistory.del_var_history(var, conf_file, line)
total = ""
for c in contents:
total += c
with open(conf_file, 'w') as f: with open(conf_file, 'w') as f:
f.write(total) f.writelines(contents)
f.close()
def createConfigFile(self, name): def createConfigFile(self, name):
path = os.getcwd() path = os.getcwd()