]>
git.saurik.com Git - apple/xnu.git/blob - tools/lldbmacros/core/syntax_checker.py
4 A simple utility that verifies the syntax for python scripts.
5 The checks it does are :
6 * Check for 'tab' characters in .py files
7 * Compile errors in py sources
9 python syntax_checker.py <python_source_file> [<python_source_file> ..]
16 tabs_search_rex
= re
.compile("^\s*\t+",re
.MULTILINE|re
.DOTALL
)
18 if __name__
== "__main__":
20 print >>sys
.stderr
, "Error: Unknown arguments"
23 for fname
in sys
.argv
[1:]:
24 if not os
.path
.exists(fname
):
25 print >>sys
.stderr
, "Error: Cannot recognize %s as a file" % fname
27 if fname
.split('.')[-1] != 'py':
28 print "Note: %s is not a valid python file. Skipping." % fname
31 strdata
= fh
.readlines()
33 tab_check_status
= True
34 for linedata
in strdata
:
36 if len(tabs_search_rex
.findall(linedata
)) > 0 :
37 print >>sys
.stderr
, "Error: Found a TAB character at %s:%d" % (fname
, lineno
)
38 tab_check_status
= False
39 if tab_check_status
== False:
40 print >>sys
.stderr
, "Error: Syntax check failed. Please fix the errors and try again."
42 #now check for error in compilation
44 compile_result
= py_compile
.compile(fname
, cfile
="/dev/null", doraise
=True)
45 except py_compile
.PyCompileError
as exc
:
46 print >>sys
.stderr
, str(exc
)
47 print >>sys
.stderr
, "Error: Compilation failed. Please fix the errors and try again."
49 print "Success: Checked %s. No syntax errors found." % fname