forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrakelint.py
51 lines (40 loc) · 1.3 KB
/
drakelint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
def _check_invalid_line_endings(newlines):
"""Return 0 if all of the @p newlines are Unix, and 1 otherwise."""
for newline in newlines:
if newline != '\n':
print("Non-Unix newline characters found.")
return 1
return 0
def main():
"""Run Drake lint checks on each path specified as a command-line argument.
Exit 1 if any of the paths are invalid or any lint checks fail.
Otherwise exit 0.
"""
total_errors = 0
for filename in sys.argv[1:]:
# Open the file.
print("drakelint.py: Linting " + filename)
with open(filename, 'rU') as file:
if not file:
print("Unable to open " + filename)
sys.exit(1)
# Read its data.
file.read()
if file.newlines is None:
newlines = tuple()
else:
newlines = tuple(file.newlines)
# Run tests and count errors.
errors = 0
errors += _check_invalid_line_endings(newlines)
if errors != 0:
print(str(errors) + " errors detected.")
# Wrap up.
total_errors += errors
if total_errors == 0:
sys.exit(0)
else:
sys.exit(1)
if __name__ == "__main__":
main()