mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-23 23:02:25 +00:00
misc/fixshebangs.py
This commit is contained in:
parent
9c35ca76a4
commit
24650490ed
30
misc/fixshebangs.py
Normal file
30
misc/fixshebangs.py
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from allmydata.util import fileutil
|
||||
|
||||
import re, shutil, sys
|
||||
|
||||
R=re.compile("^#! */usr/bin/python *$")
|
||||
for fname in sys.argv[1:]:
|
||||
inf = open(fname, "rU")
|
||||
rntf = fileutil.ReopenableNamedTemporaryFile()
|
||||
outf = open(rntf.name, "w")
|
||||
first = True
|
||||
for l in inf:
|
||||
if first and R.search(l):
|
||||
outf.write("#!/usr/bin/env python\n")
|
||||
else:
|
||||
outf.write(l)
|
||||
first = False
|
||||
outf.close()
|
||||
|
||||
try:
|
||||
shutil.move(rntf.name, fname)
|
||||
except EnvironmentError:
|
||||
# Couldn't atomically overwrite, so just hope that this process doesn't die
|
||||
# and the target file doesn't get recreated in between the following two
|
||||
# operations:
|
||||
shutil.move(fname, fname + ".bak")
|
||||
shutil.move(rntf.name, fname)
|
||||
|
||||
fileutil.remove_if_possible(fname + ".bak")
|
Loading…
Reference in New Issue
Block a user