Debian Codegraph @

scripts/check_crlf.py

raw
1 #!/usr/bin/env python
2 """
3 Checker for line endings
4 ~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Make sure Python (.py) and Bash completion (.bashcomp) files do not
7 contain CR/LF newlines.
8
9 :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
10 :license: BSD, see LICENSE for details.
11 """
12
13 import sys
14 import os
15
16 if __name__ == '__main__':
17 error = False
18 for directory in sys.argv[1:]:
19 if not os.path.exists(directory):
20 continue
21
22 for root, dirs, files in os.walk(directory):
23 for filename in files:
24 if not filename.endswith('.py') and not filename.endswith('.bashcomp'):
25 continue
26
27 full_path = os.path.join(root, filename)
28 with open(full_path, 'rb') as f:
29 if b'\r\n' in f.read():
30 print('CR/LF found in', full_path)
31 error = True
32
33 if error:
34 sys.exit(1)
35
36 sys.exit(0)