projects
/
litex.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
ffe83ef
)
build/tools: add replace_in_file function.
author
Florent Kermarrec
<florent@enjoy-digital.fr>
Wed, 25 Mar 2020 15:36:53 +0000
(16:36 +0100)
committer
Florent Kermarrec
<florent@enjoy-digital.fr>
Wed, 25 Mar 2020 15:36:53 +0000
(16:36 +0100)
litex/build/tools.py
patch
|
blob
|
history
diff --git
a/litex/build/tools.py
b/litex/build/tools.py
index 030d32f53819fb120a6cda6e6172a4254c35996e..16dd8af9a06c037cf16fdef3bd445c033e4e66b3 100644
(file)
--- a/
litex/build/tools.py
+++ b/
litex/build/tools.py
@@
-37,6
+37,17
@@
def write_to_file(filename, contents, force_unix=False):
with open(filename, "w", newline=newline) as f:
f.write(contents)
+def replace_in_file(filename, _from, _to):
+ # Read in the file
+ with open(filename, "r") as file :
+ filedata = file.read()
+
+ # Replace the target string
+ filedata = filedata.replace(_from, _to)
+
+ # Write the file out again
+ with open(filename, "w") as file:
+ file.write(filedata)
def sub_rules(line, rules, max_matches=1):
for pattern, color in rules: