- Notifications
You must be signed in to change notification settings - Fork 31.7k
/
Copy pathfixps.py
executable file
·33 lines (28 loc) · 893 Bytes
/
fixps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
# Fix Python script(s) to reference the interpreter via /usr/bin/env python.
# Warning: this overwrites the file without making a backup.
importsys
importre
defmain():
forfilenameinsys.argv[1:]:
try:
f=open(filename, 'r')
exceptIOError, msg:
printfilename, ': can\'t open :', msg
continue
line=f.readline()
ifnotre.match('^#! */usr/local/bin/python', line):
printfilename, ': not a /usr/local/bin/python script'
f.close()
continue
rest=f.read()
f.close()
line=re.sub('/usr/local/bin/python',
'/usr/bin/env python', line)
printfilename, ':', repr(line)
f=open(filename, "w")
f.write(line)
f.write(rest)
f.close()
if__name__=='__main__':
main()