cpython/PCbuild/fix_encoding.py
Greg Price fa3a38d81f Mark files as executable that are meant as scripts. (GH-15354)
This is the converse of GH-15353 -- in addition to plenty of
scripts in the tree that are marked with the executable bit
(and so can be directly executed), there are a few that have
a leading `#!` which could let them be executed, but it doesn't
do anything because they don't have the executable bit set.

Here's a command which finds such files and marks them.  The
first line finds files in the tree with a `#!` line *anywhere*;
the next-to-last step checks that the *first* line is actually of
that form.  In between we filter out files that already have the
bit set, and some files that are meant as fragments to be
consumed by one or another kind of preprocessor.

    $ git grep -l '^#!' \
      | grep -vxFf <( \
          git ls-files --stage \
          | perl -lane 'print $F[3] if (!/^100644/)' \
        ) \
      | grep -ve '\.in$' -e '^Doc/includes/' \
      | while read f; do
          head -c2 "$f" | grep -qxF '#!' \
          && chmod a+x "$f"; \
        done
2019-09-09 07:16:33 -07:00

36 lines
952 B
Python
Executable file

#! /usr/bin/env python3
#
# Fixes encoding of the project files to add UTF-8 BOM.
#
# Visual Studio insists on having the BOM in project files, and will
# restore it on first edit. This script will go through the relevant
# files and ensure the BOM is included, which should prevent too many
# irrelevant changesets.
#
from pathlib import Path
__author__ = "Steve Dower <steve.dower@python.org>"
__version__ = "1.0.0.0"
def fix(p):
with open(p, 'r', encoding='utf-8-sig') as f:
data = f.read()
with open(p, 'w', encoding='utf-8-sig') as f:
f.write(data)
ROOT_DIR = Path(__file__).resolve().parent
if __name__ == '__main__':
count = 0
print('Fixing:')
for f in ROOT_DIR.glob('*.vcxproj'):
print(f' - {f.name}')
fix(f)
count += 1
for f in ROOT_DIR.glob('*.vcxproj.filters'):
print(f' - {f.name}')
fix(f)
count += 1
print()
print(f'Fixed {count} files')