summaryrefslogtreecommitdiffstats
path: root/scripts/lib/devtool/__init__.py
diff options
context:
space:
mode:
authorChris Laplante <chris.laplante@agilent.com>2025-09-16 11:51:44 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-09-18 11:16:42 +0100
commit5c4a0dbcac7fbfc2651d2e8eca8e96a88154f11a (patch)
treeaa95081c4aecc659a56ac594002d1054bd36f1ba /scripts/lib/devtool/__init__.py
parentbde1f02b3fd95e4a850b43f5da4057d94a6f5384 (diff)
downloadpoky-5c4a0dbcac7fbfc2651d2e8eca8e96a88154f11a.tar.gz
devtool: __init__: simplify replace_from_file
Mostly just remove some useless helper functions (From OE-Core rev: b27b1083f59cf0a268e9b141568119f257002d13) 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>
Diffstat (limited to 'scripts/lib/devtool/__init__.py')
-rw-r--r--scripts/lib/devtool/__init__.py27
1 files changed, 8 insertions, 19 deletions
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):
295 295
296def replace_from_file(path, old, new): 296def replace_from_file(path, old, new):
297 """Replace strings on a file""" 297 """Replace strings on a file"""
298
299 def read_file(path):
300 data = None
301 with open(path) as f:
302 data = f.read()
303 return data
304
305 def write_file(path, data):
306 if data is None:
307 return
308 wdata = data.rstrip() + "\n"
309 with open(path, "w") as f:
310 f.write(wdata)
311
312 # In case old is None, return immediately
313 if old is None: 298 if old is None:
314 return 299 return
300
315 try: 301 try:
316 rdata = read_file(path) 302 with open(path) as f:
303 rdata = f.read()
317 except IOError as e: 304 except IOError as e:
318 import errno 305 import errno
319 # if file does not exit, just quit, otherwise raise an exception 306 # if file does not exit, just quit, otherwise raise an exception
320 if e.errno == errno.ENOENT: 307 if e.errno == errno.ENOENT:
321 return 308 return
322 else: 309 raise
323 raise
324 310
325 old_contents = rdata.splitlines() 311 old_contents = rdata.splitlines()
326 new_contents = [] 312 new_contents = []
@@ -329,7 +315,10 @@ def replace_from_file(path, old, new):
329 new_contents.append(old_content.replace(old, new)) 315 new_contents.append(old_content.replace(old, new))
330 except ValueError: 316 except ValueError:
331 pass 317 pass
332 write_file(path, "\n".join(new_contents)) 318
319 wdata = ("\n".join(new_contents)).rstrip() + "\n"
320 with open(path, "w") as f:
321 f.write(wdata)
333 322
334 323
335def update_unlockedsigs(basepath, workspace, fixed_setup, extra=None): 324def update_unlockedsigs(basepath, workspace, fixed_setup, extra=None):