Debian Codegraph @

tools/check_sources.py

raw
1 #!/usr/bin/env python
2 """Utility to look for hard tabs and \r characters in all sources.
3
4 Usage:
5
6 ./check_sources.py
7
8 It prints summaries and if chosen, line-by-line info of where \\t or \\r
9 characters can be found in our source tree.
10 """
11
12 # Config
13 # If true, all lines that have tabs are printed, with line number
14 full_report_tabs = True
15 # If true, all lines that have tabs are printed, with line number
16 full_report_rets = False
17
18 # Code begins
19 from IPython.external.path import path
20
21 rets = []
22 tabs = []
23
24 for f in path('..').walkfiles('*.py'):
25 errs = ''
26 cont = f.bytes()
27 if '\t' in cont:
28 errs+='t'
29 tabs.append(f)
30
31 if '\r' in cont:
32 errs+='r'
33 rets.append(f)
34
35 if errs:
36 print("%3s" % errs, f)
37
38 if 't' in errs and full_report_tabs:
39 for ln,line in enumerate(f.lines()):
40 if '\t' in line:
41 print('TAB:',ln,':',line, end=' ')
42
43 if 'r' in errs and full_report_rets:
44 for ln,line in enumerate(open(f.abspath(),'rb')):
45 if '\r' in line:
46 print('RET:',ln,':',line, end=' ')
47
48 # Summary at the end, to call cleanup tools if necessary
49 if tabs:
50 print('Hard tabs found. These can be cleaned with untabify:')
51 for f in tabs: print(f, end=' ')
52 if rets:
53 print('Carriage returns (\\r) found in:')
54 for f in rets: print(f, end=' ')