| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 import os.path | 3 import os.path |
| 4 import re | 4 import re |
| 5 import subprocess | 5 import subprocess |
| 6 import sys | 6 import sys |
| 7 | 7 |
| 8 from name_utilities import enum_for_css_keyword | 8 from name_utilities import enum_for_css_keyword |
| 9 from name_utilities import upper_first_letter | 9 from name_utilities import upper_first_letter |
| 10 import json5_generator | 10 import json5_generator |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 'value_keyword_strings': '\n'.join(' "%(name)s\\0"' % keyword for
keyword in self._value_keywords), | 158 'value_keyword_strings': '\n'.join(' "%(name)s\\0"' % keyword for
keyword in self._value_keywords), |
| 159 'value_keyword_offsets': '\n'.join(' %d,' % offset for offset in ke
yword_offsets), | 159 'value_keyword_offsets': '\n'.join(' %d,' % offset for offset in ke
yword_offsets), |
| 160 'value_keyword_to_enum_map': '\n'.join('%(lower_name)s, %(enum_name)
s' % keyword for keyword in self._value_keywords), | 160 'value_keyword_to_enum_map': '\n'.join('%(lower_name)s, %(enum_name)
s' % keyword for keyword in self._value_keywords), |
| 161 'ua_sheet_mode_values_keywords': '\n '.join(map(self._case_va
lue_keyword, self._value_keywords_with_mode('UASheet'))), | 161 'ua_sheet_mode_values_keywords': '\n '.join(map(self._case_va
lue_keyword, self._value_keywords_with_mode('UASheet'))), |
| 162 'quirks_mode_or_ua_sheet_mode_values_keywords': '\n '.join(map(se
lf._case_value_keyword, self._value_keywords_with_mode('QuirksOrUASheet'))), | 162 'quirks_mode_or_ua_sheet_mode_values_keywords': '\n '.join(map(se
lf._case_value_keyword, self._value_keywords_with_mode('QuirksOrUASheet'))), |
| 163 } | 163 } |
| 164 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output | 164 # FIXME: If we could depend on Python 2.7, we would use subprocess.check
_output |
| 165 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] | 165 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] |
| 166 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. | 166 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. |
| 167 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. | 167 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. |
| 168 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr
ocess.PIPE, universal_newlines=True) | 168 |
| 169 return gperf.communicate(gperf_input)[0] | 169 # If gperf isn't in the path we get an OSError. We don't want to use |
| 170 # the normal solution of shell=True (as this has to run on many |
| 171 # platforms), so instead we catch the error and raise a |
| 172 # CalledProcessError like subprocess would do when shell=True is set. |
| 173 try: |
| 174 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=s
ubprocess.PIPE, universal_newlines=True) |
| 175 return gperf.communicate(gperf_input)[0] |
| 176 except OSError: |
| 177 raise subprocess.CalledProcessError(127, gperf_args, output='Command
not found.') |
| 170 | 178 |
| 171 | 179 |
| 172 if __name__ == "__main__": | 180 if __name__ == "__main__": |
| 173 json5_generator.Maker(CSSValueKeywordsWriter).main() | 181 json5_generator.Maker(CSSValueKeywordsWriter).main() |
| OLD | NEW |