Merge pull request #92 from JamesBromberger/python

sed_i preserves permissions now
This commit is contained in:
Anders Ingemann 2013-08-17 04:21:57 -07:00
commit 030cd8c239

View file

@ -50,10 +50,13 @@ def sed_i(file_path, pattern, subst):
from tempfile import mkstemp from tempfile import mkstemp
from shutil import move from shutil import move
from os import close from os import close
import os
temp_fd, temp_path = mkstemp() temp_fd, temp_path = mkstemp()
mode = os.stat(file_path).st_mode
with open(temp_path, 'w') as new_file: with open(temp_path, 'w') as new_file:
with open(file_path) as old_file: with open(file_path) as old_file:
for line in old_file: for line in old_file:
new_file.write(line.replace(pattern, subst)) new_file.write(line.replace(pattern, subst))
close(temp_fd) close(temp_fd)
os.chmod(temp_path, mode)
move(temp_path, file_path) move(temp_path, file_path)