cpython/Tools/scripts/fixps.py

34 lines
863 B
Python
Raw Normal View History

#!/usr/bin/env python
1992-12-09 19:14:40 -04:00
# Fix Python script(s) to reference the interpreter via /usr/bin/env python.
# Warning: this overwrites the file without making a backup.
1992-12-09 19:14:40 -04:00
import sys
import re
1992-12-09 19:14:40 -04:00
def main():
for filename in sys.argv[1:]:
2001-01-17 04:48:39 -04:00
try:
f = open(filename, 'r')
2001-01-17 04:48:39 -04:00
except IOError, msg:
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):
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)
print filename, ':', repr(line)
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
main()