File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 2929import stat
3030import errno
3131import getpass
32- from contextlib import contextmanager , closing
32+ from contextlib import contextmanager
3333import subprocess
34+ import fileinput
3435
3536import llnl .util .tty as tty
3637
@@ -85,13 +86,14 @@ def groupid_to_group(x):
8586 if ignore_absent and not os .path .exists (filename ):
8687 continue
8788
88- shutil .copy (filename , backup_filename )
89+ # Create backup file. Don't overwrite an existing backup
90+ # file in case this file is being filtered multiple times.
91+ if not os .path .exists (backup_filename ):
92+ shutil .copy (filename , backup_filename )
93+
8994 try :
90- with closing (open (backup_filename )) as infile :
91- with closing (open (filename , 'w' )) as outfile :
92- for line in infile :
93- foo = re .sub (regex , repl , line )
94- outfile .write (foo )
95+ for line in fileinput .input (filename , inplace = True ):
96+ print (re .sub (regex , repl , line .rstrip ()))
9597 except :
9698 # clean up the original file on failure.
9799 shutil .move (backup_filename , filename )
You can’t perform that action at this time.
0 commit comments