]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
devtool: __init__: simplify replace_from_file
authorChris Laplante <chris.laplante@agilent.com>
Tue, 16 Sep 2025 15:51:44 +0000 (11:51 -0400)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 18 Sep 2025 10:08:20 +0000 (11:08 +0100)
Mostly just remove some useless helper functions

Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/lib/devtool/__init__.py

index 717a60c039ff8e09fab90b9112e526956456bb83..969d6dc13ab13d172bf2827200b1cb44d88ebd26 100644 (file)
@@ -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):