Chromium Code Reviews| Index: tools/json_to_struct/json_to_struct.py |
| diff --git a/tools/json_to_struct/json_to_struct.py b/tools/json_to_struct/json_to_struct.py |
| index 831c739498d0f62f85467b02a272cb00f64aa905..447c0b34ff5fb414697cf37a3003326249bd5f15 100755 |
| --- a/tools/json_to_struct/json_to_struct.py |
| +++ b/tools/json_to_struct/json_to_struct.py |
| @@ -173,6 +173,12 @@ def _Load(filename): |
| result = json.loads(json_comment_eater.Nom(handle.read())) |
| return result |
| +def GenerateStruct(basepath, output_root, namespace, schema, description, |
| + description_filename, schema_filename): |
|
Alexei Svitkine (slow)
2015/07/08 16:54:54
Nit: Align
danduong
2015/07/09 00:12:54
Done.
|
| + head = HEAD % (datetime.now().year, schema_filename, description_filename) |
|
Alexei Svitkine (slow)
2015/07/08 16:54:53
Add a comment about what this function does and do
danduong
2015/07/09 00:12:54
Done.
|
| + _GenerateH(basepath, output_root, head, namespace, schema, description) |
| + _GenerateCC(basepath, output_root, head, namespace, schema, description) |
| + |
| if __name__ == '__main__': |
| parser = optparse.OptionParser( |
| description='Generates an C++ array of struct from a JSON description.', |
| @@ -185,6 +191,7 @@ if __name__ == '__main__': |
| help='C++ namespace for generated files. e.g search_providers.') |
| parser.add_option('-s', '--schema', help='path to the schema file, ' |
| 'mandatory.') |
| + parser.add_option('-o', '--output', help='output filename, ') |
| (opts, args) = parser.parse_args() |
| if not opts.schema: |
| @@ -192,7 +199,7 @@ if __name__ == '__main__': |
| description_filename = os.path.normpath(args[0]) |
| root, ext = os.path.splitext(description_filename) |
| - shortroot = os.path.split(root)[1] |
| + shortroot = opts.output if opts.output else os.path.split(root)[1] |
| if opts.destdir: |
| output_root = os.path.join(os.path.normpath(opts.destdir), shortroot) |
| else: |
| @@ -205,7 +212,5 @@ if __name__ == '__main__': |
| schema = _Load(opts.schema) |
| description = _Load(description_filename) |
| - |
| - head = HEAD % (datetime.now().year, opts.schema, description_filename) |
| - _GenerateH(basepath, output_root, head, opts.namespace, schema, description) |
| - _GenerateCC(basepath, output_root, head, opts.namespace, schema, description) |
| + GenerateStruct(basepath, output_root, opts.namespace, schema, description, |
| + description_filename, opts.schema) |