| OLD | NEW |
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import os.path | 29 import os.path |
| 30 import shutil | 30 import shutil |
| 31 | 31 |
| 32 from in_file import InFile | 32 from in_file import InFile |
| 33 import template_expander |
| 33 | 34 |
| 34 | 35 |
| 35 class Writer(object): | 36 class Writer(object): |
| 36 # Subclasses should override. | 37 # Subclasses should override. |
| 37 class_name = None | 38 class_name = None |
| 38 defaults = None | 39 defaults = None |
| 39 valid_values = None | 40 valid_values = None |
| 40 default_parameters = None | 41 default_parameters = None |
| 41 | 42 |
| 42 def __init__(self, in_file_path): | 43 def __init__(self, in_file_path): |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 # The build system should ensure our output directory exists, but just i
n case. | 78 # The build system should ensure our output directory exists, but just i
n case. |
| 78 directory = os.path.dirname(file_path) | 79 directory = os.path.dirname(file_path) |
| 79 if not os.path.exists(directory): | 80 if not os.path.exists(directory): |
| 80 os.makedirs(directory) | 81 os.makedirs(directory) |
| 81 | 82 |
| 82 with open(file_path, "w") as file_to_write: | 83 with open(file_path, "w") as file_to_write: |
| 83 file_to_write.write(contents) | 84 file_to_write.write(contents) |
| 84 | 85 |
| 85 def _write_file(self, output_dir, generator, file_name): | 86 def _write_file(self, output_dir, generator, file_name): |
| 86 contents = generator() | 87 contents = generator() |
| 88 if type(contents) is dict: |
| 89 contents = template_expander.apply_template(file_name + ".tmpl", con
tents) |
| 87 if not contents: | 90 if not contents: |
| 88 return | 91 return |
| 89 path = os.path.join(output_dir, file_name) | 92 path = os.path.join(output_dir, file_name) |
| 90 self._forcibly_create_text_file_at_path_with_contents(path, contents) | 93 self._forcibly_create_text_file_at_path_with_contents(path, contents) |
| 91 | 94 |
| 92 def write_header(self, output_dir): | 95 def write_header(self, output_dir): |
| 93 self._write_file(output_dir, self.generate_header, self.class_name + '.h
') | 96 self._write_file(output_dir, self.generate_header, self.class_name + '.h
') |
| 94 | 97 |
| 95 def write_headers_header(self, output_dir): | 98 def write_headers_header(self, output_dir): |
| 96 self._write_file(output_dir, self.generate_headers_header, self.class_na
me + 'Headers.h') | 99 self._write_file(output_dir, self.generate_headers_header, self.class_na
me + 'Headers.h') |
| (...skipping 19 matching lines...) Expand all Loading... |
| 116 print "USAGE: %i INPUT_FILE [OUTPUT_DIRECTORY]" % script_name | 119 print "USAGE: %i INPUT_FILE [OUTPUT_DIRECTORY]" % script_name |
| 117 exit(1) | 120 exit(1) |
| 118 output_dir = args[1] if len(args) > 1 else os.getcwd() | 121 output_dir = args[1] if len(args) > 1 else os.getcwd() |
| 119 | 122 |
| 120 writer = self._writer_class(args[0]) | 123 writer = self._writer_class(args[0]) |
| 121 writer.write_header(output_dir) | 124 writer.write_header(output_dir) |
| 122 writer.write_headers_header(output_dir) | 125 writer.write_headers_header(output_dir) |
| 123 writer.write_interfaces_header(output_dir) | 126 writer.write_interfaces_header(output_dir) |
| 124 writer.write_implmentation(output_dir) | 127 writer.write_implmentation(output_dir) |
| 125 writer.write_idl(output_dir) | 128 writer.write_idl(output_dir) |
| OLD | NEW |