Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/fixps.py @ 17581:c1937faabb23 2.1
Added support for optional explanation parameter to the \versionadded
macro.
Refactored do_cmd_versionadded() and do_cmd_versionchanged() to do most
of the work in a helper function, with the do_cmd_*() wrappers just supplying
a portion of the replacement text.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Wed, 18 Apr 2001 17:29:14 +0000 |
| parents | 14a27acc755a |
| children | 93c92f20b6bf |
| 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(): | |
|
15930
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
11 for file in sys.argv[1:]: |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
12 try: |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
13 f = open(file, 'r') |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
14 except IOError, msg: |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
15 print file, ': can\'t open :', msg |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
16 continue |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
17 line = f.readline() |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
18 if not re.match('^#! */usr/local/bin/python', line): |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
19 print file, ': not a /usr/local/bin/python script' |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
20 f.close() |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
21 continue |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
22 rest = f.read() |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
23 f.close() |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
24 line = re.sub('/usr/local/bin/python', |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
25 '/usr/bin/env python', line) |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
26 print file, ':', `line` |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
27 f = open(file, "w") |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
28 f.write(line) |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
29 f.write(rest) |
|
14a27acc755a
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
10558
diff
changeset
|
30 f.close() |
| 1104 | 31 |
| 32 | |
| 33 main() |
