File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- #! /usr/bin/env python
1+ #!/usr/bin/env python
22
33# Fix Python script(s) to reference the interpreter via /usr/bin/env python.
4+ # Warning: this overwrites the file without making a backup.
45
56import sys
6- import regex
7- import regsub
7+ import re
88
99
1010def main ():
1111 for file in sys .argv [1 :]:
1212 try :
13- f = open (file , 'r+ ' )
14- except IOError :
15- print file , ': can\' t open for update'
13+ f = open (file , 'r' )
14+ except IOError , msg :
15+ print file , ': can\' t open :' , msg
1616 continue
1717 line = f .readline ()
18- if regex .match ('^#! */usr/local/bin/python' , line ) < 0 :
18+ if not re .match ('^#! */usr/local/bin/python' , line ):
1919 print file , ': not a /usr/local/bin/python script'
2020 f .close ()
2121 continue
2222 rest = f .read ()
23- line = regsub .sub ('/usr/local/bin/python' ,
24- '/usr/bin/env python' , line )
23+ f .close ()
24+ line = re .sub ('/usr/local/bin/python' ,
25+ '/usr/bin/env python' , line )
2526 print file , ':' , `line`
26- f . seek ( 0 )
27+ f = open ( file , "w" )
2728 f .write (line )
2829 f .write (rest )
2930 f .close ()
You can’t perform that action at this time.
0 commit comments