blob: 60a892a4f7ad59c8e22b15c8f5aa25f51c10db72 [file] [log] [blame]
Steve Dower4486a092017-05-17 13:06:39 -07001#! /usr/bin/env python3
2#
3# Fixes encoding of the project files to add UTF-8 BOM.
4#
5# Visual Studio insists on having the BOM in project files, and will
6# restore it on first edit. This script will go through the relevant
7# files and ensure the BOM is included, which should prevent too many
8# irrelevant changesets.
9#
10
11from pathlib import Path
12
13__author__ = "Steve Dower <steve.dower@python.org>"
14__version__ = "1.0.0.0"
15
16def fix(p):
17 with open(p, 'r', encoding='utf-8-sig') as f:
18 data = f.read()
19 with open(p, 'w', encoding='utf-8-sig') as f:
20 f.write(data)
21
22ROOT_DIR = Path(__file__).resolve().parent
23
24if __name__ == '__main__':
25 count = 0
26 print('Fixing:')
27 for f in ROOT_DIR.glob('*.vcxproj'):
28 print(f' - {f.name}')
29 fix(f)
30 count += 1
31 for f in ROOT_DIR.glob('*.vcxproj.filters'):
32 print(f' - {f.name}')
33 fix(f)
34 count += 1
35 print()
36 print(f'Fixed {count} files')