|
|
|
@ -21,15 +21,19 @@ def apply_(filepath, look_for, replace_with, ignore_if_not_found): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def replace_in_file(filepath, look_for, replace_with, ignore_if_not_found): |
|
|
|
|
try: |
|
|
|
|
with open(filepath) as file_: |
|
|
|
|
content = file_.read() |
|
|
|
|
except FileNotFoundError: |
|
|
|
|
if ignore_if_not_found: |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
content = content.replace(look_for, replace_with) |
|
|
|
|
|
|
|
|
|
with open(filepath, 'w') as f: |
|
|
|
|
for line in content: |
|
|
|
|
f.write(line) |
|
|
|
|
if not isinstance(filepath, list): |
|
|
|
|
filepath = [filepath] |
|
|
|
|
|
|
|
|
|
for single_filepath in filepath: |
|
|
|
|
try: |
|
|
|
|
with open(single_filepath) as file_: |
|
|
|
|
content = file_.read() |
|
|
|
|
except FileNotFoundError: |
|
|
|
|
if ignore_if_not_found: |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
content = content.replace(look_for, replace_with) |
|
|
|
|
|
|
|
|
|
with open(single_filepath, 'w') as f: |
|
|
|
|
for line in content: |
|
|
|
|
f.write(line) |
|
|
|
|