3 from allmydata.util import fileutil
7 R=re.compile("^#! */usr/bin/python *$")
8 for fname in sys.argv[1:]:
9 inf = open(fname, "rU")
10 rntf = fileutil.ReopenableNamedTemporaryFile()
11 outf = open(rntf.name, "w")
14 if first and R.search(l):
15 outf.write("#!/usr/bin/env python\n")
22 shutil.move(rntf.name, fname)
23 except EnvironmentError:
24 # Couldn't atomically overwrite, so just hope that this process doesn't die
25 # and the target file doesn't get recreated in between the following two
27 shutil.move(fname, fname + ".bak")
28 shutil.move(rntf.name, fname)
30 fileutil.remove_if_possible(fname + ".bak")