| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 import subprocess | 3 import subprocess |
| 4 import sys | 4 import sys |
| 5 | 5 |
| 6 import css_properties | 6 import css_properties |
| 7 import in_generator | 7 import in_generator |
| 8 import license | 8 import license |
| 9 | 9 |
| 10 | 10 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 219 |
| 220 css_name_and_enum_pairs = [(property['name'], property['property_id']) f
or property in self._properties_including_aliases] | 220 css_name_and_enum_pairs = [(property['name'], property['property_id']) f
or property in self._properties_including_aliases] |
| 221 | 221 |
| 222 gperf_input = GPERF_TEMPLATE % { | 222 gperf_input = GPERF_TEMPLATE % { |
| 223 'license': license.license_for_generated_cpp(), | 223 'license': license.license_for_generated_cpp(), |
| 224 'class_name': self.class_name, | 224 'class_name': self.class_name, |
| 225 'property_name_strings': '\n'.join(' "%s\\0"' % name for name in
property_names), | 225 'property_name_strings': '\n'.join(' "%s\\0"' % name for name in
property_names), |
| 226 'property_name_offsets': '\n'.join(' %d,' % offset for offset in
property_offsets), | 226 'property_name_offsets': '\n'.join(' %d,' % offset for offset in
property_offsets), |
| 227 'property_to_enum_map': '\n'.join('%s, %s' % property for property i
n css_name_and_enum_pairs), | 227 'property_to_enum_map': '\n'.join('%s, %s' % property for property i
n css_name_and_enum_pairs), |
| 228 } | 228 } |
| 229 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output | |
| 230 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] | 229 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] |
| 231 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. | 230 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. |
| 232 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. | 231 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. |
| 233 | 232 |
| 234 # If gperf isn't in the path we get an OSError. We don't want to use | 233 # If gperf isn't in the path we get an OSError. We don't want to use |
| 235 # the normal solution of shell=True (as this has to run on many | 234 # the normal solution of shell=True (as this has to run on many |
| 236 # platforms), so instead we catch the error and raise a | 235 # platforms), so instead we catch the error and raise a |
| 237 # CalledProcessError like subprocess would do when shell=True is set. | 236 # CalledProcessError like subprocess would do when shell=True is set. |
| 238 try: | 237 try: |
| 239 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=s
ubprocess.PIPE, universal_newlines=True) | 238 return subprocess.check_output(gperf_args, universal_newlines=True) |
| 240 return gperf.communicate(gperf_input)[0] | |
| 241 except OSError: | 239 except OSError: |
| 242 raise subprocess.CalledProcessError(127, gperf_args, output='Command
not found.') | 240 raise subprocess.CalledProcessError(127, gperf_args, output='Command
not found.') |
| 243 | 241 |
| 244 | 242 |
| 245 if __name__ == "__main__": | 243 if __name__ == "__main__": |
| 246 in_generator.Maker(CSSPropertyNamesWriter).main(sys.argv) | 244 in_generator.Maker(CSSPropertyNamesWriter).main(sys.argv) |
| OLD | NEW |