|
Last change
on this file since 1538 was 2, checked in by Yuri Dario, 15 years ago |
|
Initial import for vendor code.
|
-
Property svn:eol-style
set to
native
|
|
File size:
893 bytes
|
| Line | |
|---|
| 1 | #!/usr/bin/env python
|
|---|
| 2 |
|
|---|
| 3 | # Fix Python script(s) to reference the interpreter via /usr/bin/env python.
|
|---|
| 4 | # Warning: this overwrites the file without making a backup.
|
|---|
| 5 |
|
|---|
| 6 | import sys
|
|---|
| 7 | import re
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | def main():
|
|---|
| 11 | for filename in sys.argv[1:]:
|
|---|
| 12 | try:
|
|---|
| 13 | f = open(filename, 'r')
|
|---|
| 14 | except IOError, msg:
|
|---|
| 15 | print filename, ': can\'t open :', msg
|
|---|
| 16 | continue
|
|---|
| 17 | line = f.readline()
|
|---|
| 18 | if not re.match('^#! */usr/local/bin/python', line):
|
|---|
| 19 | print filename, ': not a /usr/local/bin/python script'
|
|---|
| 20 | f.close()
|
|---|
| 21 | continue
|
|---|
| 22 | rest = f.read()
|
|---|
| 23 | f.close()
|
|---|
| 24 | line = re.sub('/usr/local/bin/python',
|
|---|
| 25 | '/usr/bin/env python', line)
|
|---|
| 26 | print filename, ':', repr(line)
|
|---|
| 27 | f = open(filename, "w")
|
|---|
| 28 | f.write(line)
|
|---|
| 29 | f.write(rest)
|
|---|
| 30 | f.close()
|
|---|
| 31 |
|
|---|
| 32 | if __name__ == '__main__':
|
|---|
| 33 | main()
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.