annotate Tools/scripts/fixps.py @ 58689:514b56efd89a 3.1

Merged revisions 77962 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines Merged revisions 77943,77959-77960 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines Explicitly mention the default value for formatdate's usegmt parameter. ........ r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert ........ r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines Add Chris Rebert to ACKS for issue 6760 Popen doc improvements. ........ ................
author R. David Murray <rdmurray@bitdance.com>
date Thu, 04 Feb 2010 16:44:31 +0000
parents 46625e6122e9
children fcfe324663a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4154e98d1478 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
4154e98d1478 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
4154e98d1478 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 import sys
10558
8d2a8a49d983 Use re instead of regex.
Guido van Rossum <guido@python.org>
parents: 4569
diff changeset
7 import re
1104
4154e98d1478 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
4154e98d1478 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
4154e98d1478 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 def main():
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 15930
diff changeset
11 for filename in sys.argv[1:]:
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 10558
diff changeset
12 try:
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 15930
diff changeset
13 f = open(filename, 'r')
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 33074
diff changeset
14 except IOError as msg:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
15 print(filename, ': can\'t open :', msg)
15930
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):
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
19 print(filename, ': not a /usr/local/bin/python script')
15930
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)
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 40587
diff changeset
26 print(filename, ':', repr(line))
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 15930
diff changeset
27 f = open(filename, "w")
15930
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
4154e98d1478 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
33074
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 31515
diff changeset
32 if __name__ == '__main__':
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 31515
diff changeset
33 main()