• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #! /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 
11 from pathlib import Path
12 
13 __author__ = "Steve Dower <steve.dower@python.org>"
14 __version__ = "1.0.0.0"
15 
16 def 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 
22 ROOT_DIR = Path(__file__).resolve().parent
23 
24 if __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')
37