view Tools/scripts/fixps.py @ 48632:5f3ef6400a96

Blocked revisions 65444 via svnmerge ........ r65444 | brett.cannon | 2008-08-03 15:57:23 -0700 (Sun, 03 Aug 2008) | 3 lines Remove a dict.has_key() and callable() usage in SimpleXMLRPCServer as triggered under -3 through test_xmlrpc. ........
author Brett Cannon <bcannon@gmail.com>
date Sun, 03 Aug 2008 22:58:03 +0000
parents 46625e6122e9
children fcfe324663a6
line wrap: on
line source

#!/usr/bin/env python

# Fix Python script(s) to reference the interpreter via /usr/bin/env python.
# Warning: this overwrites the file without making a backup.

import sys
import re


def main():
    for filename in sys.argv[1:]:
        try:
            f = open(filename, 'r')
        except IOError as msg:
            print(filename, ': can\'t open :', msg)
            continue
        line = f.readline()
        if not re.match('^#! */usr/local/bin/python', line):
            print(filename, ': not a /usr/local/bin/python script')
            f.close()
            continue
        rest = f.read()
        f.close()
        line = re.sub('/usr/local/bin/python',
                      '/usr/bin/env python', line)
        print(filename, ':', repr(line))
        f = open(filename, "w")
        f.write(line)
        f.write(rest)
        f.close()

if __name__ == '__main__':
    main()