Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/fixps.py @ 15164:8930ec3bc00a legacy-trunk
Added additional test cases for pulldom modifications.
| author | Lars Gustäbel <lars@gustaebel.de> |
|---|---|
| date | Wed, 11 Oct 2000 22:36:00 +0000 |
| parents | 8d2a8a49d983 |
| children | 14a27acc755a |
| rev | line source |
|---|---|
|
10558
8d2a8a49d983
Use re instead of regex.
Guido van Rossum <guido@python.org>
parents:
4569
diff
changeset
|
1 #!/usr/bin/env python |
| 1104 | 2 |
|
4569
e708f568b8b7
Changed so that it replaces /usr/local/bin/python with /usr/bin/env python.
Guido van Rossum <guido@python.org>
parents:
1106
diff
changeset
|
3 # Fix Python script(s) to reference the interpreter via /usr/bin/env python. |
|
10558
8d2a8a49d983
Use re instead of regex.
Guido van Rossum <guido@python.org>
parents:
4569
diff
changeset
|
4 # Warning: this overwrites the file without making a backup. |
| 1104 | 5 |
| 6 import sys | |
|
10558
8d2a8a49d983
Use re instead of regex.
Guido van Rossum <guido@python.org>
parents:
4569
diff
changeset
|
7 import re |
| 1104 | 8 |
| 9 | |
| 10 def main(): | |
| 11 for file in sys.argv[1:]: | |
| 12 try: | |
|
10558
8d2a8a49d983
Use re instead of regex.
Guido van Rossum <guido@python.org>
parents:
4569
diff
changeset
|
13 f = open(file, 'r') |
|
8d2a8a49d983
Use re instead of regex.
Guido van Rossum <guido@python.org>
parents:
4569
diff
changeset
|
14 except IOError, msg: |
|
8d2a8a49d983
Use re instead of regex.
Guido van Rossum <guido@python.org>
parents:
4569
diff
changeset
|
15 print file, ': can\'t open :', msg |
| 1104 | 16 continue |
| 17 line = f.readline() | |
|
10558
8d2a8a49d983
Use re instead of regex.
Guido van Rossum <guido@python.org>
parents:
4569
diff
changeset
|
18 if not re.match('^#! */usr/local/bin/python', line): |
|
4569
e708f568b8b7
Changed so that it replaces /usr/local/bin/python with /usr/bin/env python.
Guido van Rossum <guido@python.org>
parents:
1106
diff
changeset
|
19 print file, ': not a /usr/local/bin/python script' |
| 1104 | 20 f.close() |
| 21 continue | |
| 22 rest = f.read() | |
|
10558
8d2a8a49d983
Use re instead of regex.
Guido van Rossum <guido@python.org>
parents:
4569
diff
changeset
|
23 f.close() |
|
8d2a8a49d983
Use re instead of regex.
Guido van Rossum <guido@python.org>
parents:
4569
diff
changeset
|
24 line = re.sub('/usr/local/bin/python', |
|
8d2a8a49d983
Use re instead of regex.
Guido van Rossum <guido@python.org>
parents:
4569
diff
changeset
|
25 '/usr/bin/env python', line) |
| 1104 | 26 print file, ':', `line` |
|
10558
8d2a8a49d983
Use re instead of regex.
Guido van Rossum <guido@python.org>
parents:
4569
diff
changeset
|
27 f = open(file, "w") |
| 1104 | 28 f.write(line) |
| 29 f.write(rest) | |
| 30 f.close() | |
| 31 | |
| 32 | |
| 33 main() |
