1
1
Fork 0

replace_in_file task now optionally takes multiple filepath inputs

develop
corentin 4 months ago
parent b5451300a4
commit 18c5d5dac8
  1. 28
      vendor/jps_tasks/replace_in_file.py

@ -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)

Loading…
Cancel
Save