2010-03-11 18:53:45 -04:00
|
|
|
#!/usr/bin/env python3
|
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')
|
2007-01-10 12:19:56 -04:00
|
|
|
except IOError as msg:
|
2007-08-03 14:06:41 -03:00
|
|
|
print(filename, ': can\'t open :', msg)
|
2001-01-17 04:48:39 -04:00
|
|
|
continue
|
2019-03-30 03:33:02 -03:00
|
|
|
with f:
|
|
|
|
line = f.readline()
|
|
|
|
if not re.match('^#! */usr/local/bin/python', line):
|
|
|
|
print(filename, ': not a /usr/local/bin/python script')
|
|
|
|
continue
|
|
|
|
rest = f.read()
|
2001-01-17 04:48:39 -04:00
|
|
|
line = re.sub('/usr/local/bin/python',
|
|
|
|
'/usr/bin/env python', line)
|
2007-08-03 14:06:41 -03:00
|
|
|
print(filename, ':', repr(line))
|
2019-03-30 03:33:02 -03:00
|
|
|
with open(filename, "w") as f:
|
|
|
|
f.write(line)
|
|
|
|
f.write(rest)
|
1992-12-09 19:14:40 -04:00
|
|
|
|
2004-08-09 14:27:55 -03:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|