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 import json | |
11 except: | |
12 import simplejson as json | |
13 | |
14 | 10 |
15 | 11 |
16 class Module(object): | 12 class Module(object): |
17 def __init__(self, name, sources, depends=[], externs=[]): | 13 def __init__(self, name, sources, depends=[], externs=[]): |
18 self.name = name | 14 self.name = name |
19 self.sources = sources | 15 self.sources = sources |
20 # TODO(dbeam): support depending on other modules/dependency flattening. | 16 # TODO(dbeam): support depending on other modules/dependency flattening. |
21 self.depends = depends | 17 self.depends = depends |
22 self.externs = externs | 18 self.externs = externs |
23 | 19 |
(...skipping 19 matching lines...) Expand all Loading... | |
43 | 39 |
44 def __init__(self, verbose=False): | 40 def __init__(self, verbose=False): |
45 self._verbose = verbose | 41 self._verbose = verbose |
46 | 42 |
47 def parse(self, file_path): | 43 def parse(self, file_path): |
48 if file_path in self._cache: | 44 if file_path in self._cache: |
49 print "(INFO) Found module file %s in the cache" % file_path | 45 print "(INFO) Found module file %s in the cache" % file_path |
50 return self._cache[file_path] | 46 return self._cache[file_path] |
51 | 47 |
52 file = open(file_path, "r") | 48 file = open(file_path, "r") |
53 data = json.load(file) | 49 file_content = file.read() |
Dan Beam
2014/07/24 18:34:42
nit: file_contents = open(file_path, "r").read()
Vitaly Pavlenko
2014/07/25 22:09:22
I think that's better:
with open(file_path) as fil
| |
50 data = ast.literal_eval(file_content) | |
54 file.close() | 51 file.close() |
55 | 52 |
56 if self._verbose: | 53 if self._verbose: |
57 pretty_json = json.dumps(data, indent=2, separators=(',', ': ')).strip() | 54 print "(INFO) Layout: " + os.linesep + file_content + os.linesep |
58 print "(INFO) Layout: " + os.linesep + pretty_json + os.linesep | |
59 | 55 |
60 self._cache[file_path] = [Module.from_dict(m) for m in data] | 56 self._cache[file_path] = [Module.from_dict(m) for m in data] |
61 return self._cache[file_path] | 57 return self._cache[file_path] |
62 | 58 |
63 | 59 |
64 class ModuleCompiler(object): | 60 class ModuleCompiler(object): |
65 _checker = None | 61 _checker = None |
66 _parser = None | 62 _parser = None |
67 | 63 |
68 def __init__(self, verbose=False): | 64 def __init__(self, verbose=False): |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 | 110 |
115 | 111 |
116 if __name__ == "__main__": | 112 if __name__ == "__main__": |
117 parser = argparse.ArgumentParser( | 113 parser = argparse.ArgumentParser( |
118 description="Typecheck JavaScript using Closure compiler") | 114 description="Typecheck JavaScript using Closure compiler") |
119 parser.add_argument("-v", "--verbose", action="store_true", | 115 parser.add_argument("-v", "--verbose", action="store_true", |
120 help="Show more information as this script runs") | 116 help="Show more information as this script runs") |
121 parser.add_argument("module_file", nargs=argparse.ONE_OR_MORE, | 117 parser.add_argument("module_file", nargs=argparse.ONE_OR_MORE, |
122 help="Path to a modules file to check") | 118 help="Path to a modules file to check") |
123 main(parser.parse_args()) | 119 main(parser.parse_args()) |
OLD | NEW |