From 5c4a0dbcac7fbfc2651d2e8eca8e96a88154f11a Mon Sep 17 00:00:00 2001 From: Chris Laplante Date: Tue, 16 Sep 2025 11:51:44 -0400 Subject: devtool: __init__: simplify replace_from_file Mostly just remove some useless helper functions (From OE-Core rev: b27b1083f59cf0a268e9b141568119f257002d13) Signed-off-by: Chris Laplante Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Richard Purdie --- scripts/lib/devtool/__init__.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'scripts/lib/devtool/__init__.py') diff --git a/scripts/lib/devtool/__init__.py b/scripts/lib/devtool/__init__.py index 717a60c039..969d6dc13a 100644 --- a/scripts/lib/devtool/__init__.py +++ b/scripts/lib/devtool/__init__.py @@ -295,32 +295,18 @@ def get_bbclassextend_targets(recipefile, pn): def replace_from_file(path, old, new): """Replace strings on a file""" - - def read_file(path): - data = None - with open(path) as f: - data = f.read() - return data - - def write_file(path, data): - if data is None: - return - wdata = data.rstrip() + "\n" - with open(path, "w") as f: - f.write(wdata) - - # In case old is None, return immediately if old is None: return + try: - rdata = read_file(path) + with open(path) as f: + rdata = f.read() except IOError as e: import errno # if file does not exit, just quit, otherwise raise an exception if e.errno == errno.ENOENT: return - else: - raise + raise old_contents = rdata.splitlines() new_contents = [] @@ -329,7 +315,10 @@ def replace_from_file(path, old, new): new_contents.append(old_content.replace(old, new)) except ValueError: pass - write_file(path, "\n".join(new_contents)) + + wdata = ("\n".join(new_contents)).rstrip() + "\n" + with open(path, "w") as f: + f.write(wdata) def update_unlockedsigs(basepath, workspace, fixed_setup, extra=None): -- cgit v1.2.3-54-g00ecf