Apparently the code to forestall Tk eating events was too aggressive (Tk user input...
[python/dscho.git] / Tools / scripts / fixps.py
blob1e6e114af3826955dd4bfff2a6fd4409878705b6
1 #!/usr/bin/env python
3 # Fix Python script(s) to reference the interpreter via /usr/bin/env python.
4 # Warning: this overwrites the file without making a backup.
6 import sys
7 import re
10 def main():
11 for file in sys.argv[1:]:
12 try:
13 f = open(file, 'r')
14 except IOError, msg:
15 print file, ': can\'t open :', msg
16 continue
17 line = f.readline()
18 if not re.match('^#! */usr/local/bin/python', line):
19 print file, ': not a /usr/local/bin/python script'
20 f.close()
21 continue
22 rest = f.read()
23 f.close()
24 line = re.sub('/usr/local/bin/python',
25 '/usr/bin/env python', line)
26 print file, ':', `line`
27 f = open(file, "w")
28 f.write(line)
29 f.write(rest)
30 f.close()
33 main()