OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import argparse | 6 import argparse |
7 import ast | |
7 from checker import Checker as Checker | 8 from checker import Checker as Checker |
8 import os | 9 import os |
9 try: | 10 try: |
10 import json | 11 import json |
11 except: | 12 except: |
12 import simplejson as json | 13 import simplejson as json |
13 | 14 |
14 | 15 |
15 | 16 |
16 class Module(object): | 17 class Module(object): |
(...skipping 26 matching lines...) Expand all Loading... | |
43 | 44 |
44 def __init__(self, verbose=False): | 45 def __init__(self, verbose=False): |
45 self._verbose = verbose | 46 self._verbose = verbose |
46 | 47 |
47 def parse(self, file_path): | 48 def parse(self, file_path): |
48 if file_path in self._cache: | 49 if file_path in self._cache: |
49 print "(INFO) Found module file %s in the cache" % file_path | 50 print "(INFO) Found module file %s in the cache" % file_path |
50 return self._cache[file_path] | 51 return self._cache[file_path] |
51 | 52 |
52 file = open(file_path, "r") | 53 file = open(file_path, "r") |
53 data = json.load(file) | 54 data = ast.literal_eval(file.read()) |
54 file.close() | 55 file.close() |
55 | 56 |
56 if self._verbose: | 57 if self._verbose: |
57 pretty_json = json.dumps(data, indent=2, separators=(',', ': ')).strip() | 58 pretty_json = json.dumps(data, indent=2, separators=(',', ': ')).strip() |
Dan Beam
2014/07/24 03:52:25
i think we should just read the file and print it
Vitaly Pavlenko
2014/07/24 18:32:02
Acknowledged.
| |
58 print "(INFO) Layout: " + os.linesep + pretty_json + os.linesep | 59 print "(INFO) Layout: " + os.linesep + pretty_json + os.linesep |
59 | 60 |
60 self._cache[file_path] = [Module.from_dict(m) for m in data] | 61 self._cache[file_path] = [Module.from_dict(m) for m in data] |
61 return self._cache[file_path] | 62 return self._cache[file_path] |
62 | 63 |
63 | 64 |
64 class ModuleCompiler(object): | 65 class ModuleCompiler(object): |
65 _checker = None | 66 _checker = None |
66 _parser = None | 67 _parser = None |
67 | 68 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 | 115 |
115 | 116 |
116 if __name__ == "__main__": | 117 if __name__ == "__main__": |
117 parser = argparse.ArgumentParser( | 118 parser = argparse.ArgumentParser( |
118 description="Typecheck JavaScript using Closure compiler") | 119 description="Typecheck JavaScript using Closure compiler") |
119 parser.add_argument("-v", "--verbose", action="store_true", | 120 parser.add_argument("-v", "--verbose", action="store_true", |
120 help="Show more information as this script runs") | 121 help="Show more information as this script runs") |
121 parser.add_argument("module_file", nargs=argparse.ONE_OR_MORE, | 122 parser.add_argument("module_file", nargs=argparse.ONE_OR_MORE, |
122 help="Path to a modules file to check") | 123 help="Path to a modules file to check") |
123 main(parser.parse_args()) | 124 main(parser.parse_args()) |
OLD | NEW |