mirror of
git://git.yoctoproject.org/poky.git
synced 2025-07-19 21:09:03 +02:00

Where there isn't a copyright statement, add one to make it explicit. Also add license identifiers as MIT if there isn't one. (From OE-Core rev: bb731d1f3d2a1d50ec0aed864dbca54cf795b040) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
#
|
|
# Copyright OpenEmbedded Contributors
|
|
#
|
|
# SPDX-License-Identifier: MIT
|
|
#
|
|
|
|
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
|
|
|
|
contents = rdata.strip().splitlines()
|
|
for r in data.strip().splitlines():
|
|
try:
|
|
contents.remove(r)
|
|
except ValueError:
|
|
pass
|
|
write_file(path, "\n".join(contents))
|