mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 18:00:35 +00:00
Merge pull request #98 from JamesBromberger/python
Do a regular expression replace instead of exact string search and replace
This commit is contained in:
commit
4b293db5d6
1 changed files with 2 additions and 1 deletions
|
@ -49,12 +49,13 @@ def sed_i(file_path, pattern, subst):
|
|||
from shutil import move
|
||||
from os import close
|
||||
import os
|
||||
import re
|
||||
temp_fd, temp_path = mkstemp()
|
||||
mode = os.stat(file_path).st_mode
|
||||
with open(temp_path, 'w') as new_file:
|
||||
with open(file_path) as old_file:
|
||||
for line in old_file:
|
||||
new_file.write(line.replace(pattern, subst))
|
||||
new_file.write(re.sub(pattern, subst, line))
|
||||
close(temp_fd)
|
||||
os.chmod(temp_path, mode)
|
||||
move(temp_path, file_path)
|
||||
|
|
Loading…
Add table
Reference in a new issue