diff options
Diffstat (limited to 'scripts/lib/devtool')
-rw-r--r-- | scripts/lib/devtool/__init__.py | 27 |
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 | ||
296 | def replace_from_file(path, old, new): | 296 | def 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 | ||
335 | def update_unlockedsigs(basepath, workspace, fixed_setup, extra=None): | 324 | def update_unlockedsigs(basepath, workspace, fixed_setup, extra=None): |