| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import collections | 7 import collections |
| 8 from datetime import date | 8 from datetime import date |
| 9 import re | 9 import re |
| 10 import optparse | 10 import optparse |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 def _StripPrefix(self): | 84 def _StripPrefix(self): |
| 85 prefix_to_strip = self.prefix_to_strip | 85 prefix_to_strip = self.prefix_to_strip |
| 86 if not prefix_to_strip: | 86 if not prefix_to_strip: |
| 87 prefix_to_strip = self.original_enum_name | 87 prefix_to_strip = self.original_enum_name |
| 88 prefix_to_strip = re.sub('(?!^)([A-Z]+)', r'_\1', prefix_to_strip).upper() | 88 prefix_to_strip = re.sub('(?!^)([A-Z]+)', r'_\1', prefix_to_strip).upper() |
| 89 prefix_to_strip += '_' | 89 prefix_to_strip += '_' |
| 90 if not all([w.startswith(prefix_to_strip) for w in self.entries.keys()]): | 90 if not all([w.startswith(prefix_to_strip) for w in self.entries.keys()]): |
| 91 prefix_to_strip = '' | 91 prefix_to_strip = '' |
| 92 | 92 |
| 93 entries = collections.OrderedDict() | 93 def StripEntries(entries): |
| 94 for (k, v) in self.entries.iteritems(): | 94 ret = collections.OrderedDict() |
| 95 stripped_key = k.replace(prefix_to_strip, '', 1) | 95 for (k, v) in entries.iteritems(): |
| 96 if isinstance(v, basestring): | 96 stripped_key = k.replace(prefix_to_strip, '', 1) |
| 97 stripped_value = v.replace(prefix_to_strip, '', 1) | 97 if isinstance(v, basestring): |
| 98 else: | 98 stripped_value = v.replace(prefix_to_strip, '', 1) |
| 99 stripped_value = v | 99 else: |
| 100 entries[stripped_key] = stripped_value | 100 stripped_value = v |
| 101 ret[stripped_key] = stripped_value |
| 101 | 102 |
| 102 self.entries = entries | 103 return ret |
| 104 |
| 105 self.entries = StripEntries(self.entries) |
| 106 self.comments = StripEntries(self.comments) |
| 103 | 107 |
| 104 class DirectiveSet(object): | 108 class DirectiveSet(object): |
| 105 class_name_override_key = 'CLASS_NAME_OVERRIDE' | 109 class_name_override_key = 'CLASS_NAME_OVERRIDE' |
| 106 enum_package_key = 'ENUM_PACKAGE' | 110 enum_package_key = 'ENUM_PACKAGE' |
| 107 prefix_to_strip_key = 'PREFIX_TO_STRIP' | 111 prefix_to_strip_key = 'PREFIX_TO_STRIP' |
| 108 | 112 |
| 109 known_keys = [class_name_override_key, enum_package_key, prefix_to_strip_key] | 113 known_keys = [class_name_override_key, enum_package_key, prefix_to_strip_key] |
| 110 | 114 |
| 111 def __init__(self): | 115 def __init__(self): |
| 112 self._directives = {} | 116 self._directives = {} |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 205 |
| 202 enum_entry = HeaderParser.enum_line_re.match(self._current_enum_entry) | 206 enum_entry = HeaderParser.enum_line_re.match(self._current_enum_entry) |
| 203 if not enum_entry: | 207 if not enum_entry: |
| 204 raise Exception('Unexpected error while attempting to parse %s as enum ' | 208 raise Exception('Unexpected error while attempting to parse %s as enum ' |
| 205 'entry.' % self._current_enum_entry) | 209 'entry.' % self._current_enum_entry) |
| 206 | 210 |
| 207 enum_key = enum_entry.groups()[0] | 211 enum_key = enum_entry.groups()[0] |
| 208 enum_value = enum_entry.groups()[2] | 212 enum_value = enum_entry.groups()[2] |
| 209 self._current_definition.AppendEntry(enum_key, enum_value) | 213 self._current_definition.AppendEntry(enum_key, enum_value) |
| 210 if self._current_comments: | 214 if self._current_comments: |
| 211 self._current_definition.AppendEntryComment( | 215 self._current_definition.AppendEntryComment( |
| 212 enum_key, ' '.join(self._current_comments)) | 216 enum_key, ' '.join(self._current_comments)) |
| 213 self._current_comments = [] | 217 self._current_comments = [] |
| 214 self._current_enum_entry = '' | 218 self._current_enum_entry = '' |
| 215 | 219 |
| 216 def _AddToCurrentEnumEntry(self, line): | 220 def _AddToCurrentEnumEntry(self, line): |
| 217 self._current_enum_entry += ' ' + line.strip() | 221 self._current_enum_entry += ' ' + line.strip() |
| 218 | 222 |
| 219 def _FinalizeCurrentEnumEntry(self): | 223 def _FinalizeCurrentEnumEntry(self): |
| 220 if self._current_enum_entry: | 224 if self._current_enum_entry: |
| 221 self._ParseCurrentEnumEntry() | 225 self._ParseCurrentEnumEntry() |
| 222 self._ApplyGeneratorDirectives() | 226 self._ApplyGeneratorDirectives() |
| 223 self._current_definition.Finalize() | 227 self._current_definition.Finalize() |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar: | 385 with zipfile.ZipFile(options.srcjar, 'w', zipfile.ZIP_STORED) as srcjar: |
| 382 for output_path, data in DoGenerate(input_paths): | 386 for output_path, data in DoGenerate(input_paths): |
| 383 build_utils.AddToZipHermetic(srcjar, output_path, data=data) | 387 build_utils.AddToZipHermetic(srcjar, output_path, data=data) |
| 384 | 388 |
| 385 if options.depfile: | 389 if options.depfile: |
| 386 build_utils.WriteDepfile(options.depfile, options.srcjar) | 390 build_utils.WriteDepfile(options.depfile, options.srcjar) |
| 387 | 391 |
| 388 | 392 |
| 389 if __name__ == '__main__': | 393 if __name__ == '__main__': |
| 390 DoMain(sys.argv[1:]) | 394 DoMain(sys.argv[1:]) |
| OLD | NEW |