Re-arranging for packaging prep
[theonering] / support / test_syntax.py
1 #!/usr/bin/env python
2
3 import commands
4
5
6 verbose = False
7
8
9 def syntax_test(file):
10         commandTemplate = """
11         python -t -t -W all -c "import py_compile; py_compile.compile ('%(filename)s', doraise=False)" """
12         compileCommand = commandTemplate % {"filename": file}
13         (status, text) = commands.getstatusoutput (compileCommand)
14         text = text.rstrip()
15         passed = len(text) == 0
16
17         if passed:
18                 output = ("Syntax is correct for "+file) if verbose else ""
19         else:
20                 output = ("Syntax is invalid for %s\n" % file) if verbose else ""
21                 output += text
22         return (passed, output)
23
24
25 if __name__ == "__main__":
26         import sys
27         import os
28         import optparse
29
30         opar = optparse.OptionParser()
31         opar.add_option("-v", "--verbose", dest="verbose", help="Toggle verbosity", action="store_true", default=False)
32         options, args = opar.parse_args(sys.argv[1:])
33         verbose = options.verbose
34
35         completeOutput = []
36         allPassed = True
37         for filename in args:
38                 passed, output = syntax_test(filename)
39                 if not passed:
40                         allPassed = False
41                 if output.strip():
42                         completeOutput.append(output)
43         print "\n".join(completeOutput)
44
45         sys.exit(0 if allPassed else 1);