ยปCore Development>Code coverage>Tools/scripts/fixps.py

Python code coverage for Tools/scripts/fixps.py

#countcontent
1n/a#!/usr/bin/env python3
2n/a
3n/a# Fix Python script(s) to reference the interpreter via /usr/bin/env python.
4n/a# Warning: this overwrites the file without making a backup.
5n/a
6n/aimport sys
7n/aimport re
8n/a
9n/a
10n/adef main():
11n/a for filename in sys.argv[1:]:
12n/a try:
13n/a f = open(filename, 'r')
14n/a except IOError as msg:
15n/a print(filename, ': can\'t open :', msg)
16n/a continue
17n/a line = f.readline()
18n/a if not re.match('^#! */usr/local/bin/python', line):
19n/a print(filename, ': not a /usr/local/bin/python script')
20n/a f.close()
21n/a continue
22n/a rest = f.read()
23n/a f.close()
24n/a line = re.sub('/usr/local/bin/python',
25n/a '/usr/bin/env python', line)
26n/a print(filename, ':', repr(line))
27n/a f = open(filename, "w")
28n/a f.write(line)
29n/a f.write(rest)
30n/a f.close()
31n/a
32n/aif __name__ == '__main__':
33n/a main()