mirror of
https://git.yoctoproject.org/git/poky
synced 2026-01-01 13:58:04 +00:00
ftools functions that expect data may get 'None'; this patch does this check and return immediately if this is the case. (From OE-Core rev: 5eaa4fa30e2362e6dd572b8a6f7a909b608e14bf) Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
import os
|
|
import re
|
|
import errno
|
|
|
|
def write_file(path, data):
|
|
# In case data is None, return immediately
|
|
if data is None:
|
|
return
|
|
wdata = data.rstrip() + "\n"
|
|
with open(path, "w") as f:
|
|
f.write(wdata)
|
|
|
|
def append_file(path, data):
|
|
# In case data is None, return immediately
|
|
if data is None:
|
|
return
|
|
wdata = data.rstrip() + "\n"
|
|
with open(path, "a") as f:
|
|
f.write(wdata)
|
|
|
|
def read_file(path):
|
|
data = None
|
|
with open(path) as f:
|
|
data = f.read()
|
|
return data
|
|
|
|
def remove_from_file(path, data):
|
|
# In case data is None, return immediately
|
|
if data is None:
|
|
return
|
|
try:
|
|
rdata = read_file(path)
|
|
except IOError as e:
|
|
# if file does not exit, just quit, otherwise raise an exception
|
|
if e.errno == errno.ENOENT:
|
|
return
|
|
else:
|
|
raise
|
|
lines = rdata.splitlines()
|
|
rmdata = data.strip().splitlines()
|
|
for l in rmdata:
|
|
for c in range(0, lines.count(l)):
|
|
i = lines.index(l)
|
|
del(lines[i])
|
|
write_file(path, "\n".join(lines))
|