1999-04-09 11:56:35 -03:00
|
|
|
#!/usr/bin/env python
|
1992-12-09 19:14:40 -04:00
|
|
|
|
1996-11-27 15:43:49 -04:00
|
|
|
# Fix Python script(s) to reference the interpreter via /usr/bin/env python.
|
1999-04-09 11:56:35 -03:00
|
|
|
# Warning: this overwrites the file without making a backup.
|
1992-12-09 19:14:40 -04:00
|
|
|
|
|
|
|
import sys
|
1999-04-09 11:56:35 -03:00
|
|
|
import re
|
1992-12-09 19:14:40 -04:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2003-05-13 15:14:25 -03:00
|
|
|
for filename in sys.argv[1:]:
|
2001-01-17 04:48:39 -04:00
|
|
|
try:
|
2003-05-13 15:14:25 -03:00
|
|
|
f = open(filename, 'r')
|
2001-01-17 04:48:39 -04:00
|
|
|
except IOError, msg:
|
2003-05-13 15:14:25 -03:00
|
|
|
print filename, ': can\'t open :', msg
|
2001-01-17 04:48:39 -04:00
|
|
|
continue
|
|
|
|
line = f.readline()
|
|
|
|
if not re.match('^#! */usr/local/bin/python', line):
|
2003-05-13 15:14:25 -03:00
|
|
|
print filename, ': not a /usr/local/bin/python script'
|
2001-01-17 04:48:39 -04:00
|
|
|
f.close()
|
|
|
|
continue
|
|
|
|
rest = f.read()
|
|
|
|
f.close()
|
|
|
|
line = re.sub('/usr/local/bin/python',
|
|
|
|
'/usr/bin/env python', line)
|
2004-02-12 13:35:32 -04:00
|
|
|
print filename, ':', repr(line)
|
2003-05-13 15:14:25 -03:00
|
|
|
f = open(filename, "w")
|
2001-01-17 04:48:39 -04:00
|
|
|
f.write(line)
|
|
|
|
f.write(rest)
|
|
|
|
f.close()
|
1992-12-09 19:14:40 -04:00
|
|
|
|
2004-08-09 14:27:55 -03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|