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