Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Embeds standalone JavaScript snippets in C++ code. | 6 """Embeds standalone JavaScript snippets in C++ code. |
| 7 | 7 |
| 8 The script requires the OverridesView file from WebKit that lists the known | 8 The script requires the OverridesUI file from WebKit that lists the known |
|
samuong
2015/01/22 20:21:48
nit: rather than say "the OverridesUI file from We
| |
| 9 mobile devices to be passed in as the only argument. The list of known devices | 9 mobile devices to be passed in as the only argument. The list of known devices |
| 10 will be written to a C-style string to be parsed with JSONReader. | 10 will be written to a C-style string to be parsed with JSONReader. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import optparse | 13 import optparse |
| 14 import os | 14 import os |
| 15 import re | |
| 16 import subprocess | |
| 15 import sys | 17 import sys |
| 16 | 18 |
| 17 import cpp_source | 19 import cpp_source |
| 18 | 20 |
| 19 | 21 |
| 22 def quotizeKeys(s, keys): | |
| 23 """Returns the string s with each instance of each key wrapped in quotes. | |
| 24 | |
| 25 Args: | |
| 26 s: a string containing keys that need to be wrapped in quotes. | |
| 27 keys: an iterable of keys to be wrapped in quotes in the string. | |
| 28 """ | |
| 29 for key in keys: | |
| 30 s = re.sub('%s: ' % key, '"%s": ' % key, s) | |
| 31 return s | |
| 32 | |
| 33 | |
| 20 def main(): | 34 def main(): |
| 21 parser = optparse.OptionParser() | 35 parser = optparse.OptionParser() |
| 22 parser.add_option( | 36 parser.add_option( |
| 23 '', '--directory', type='string', default='.', | 37 '', '--directory', type='string', default='.', |
| 24 help='Path to directory where the cc/h files should be created') | 38 help='Path to directory where the cc/h files should be created') |
| 25 options, args = parser.parse_args() | 39 options, args = parser.parse_args() |
| 26 | 40 |
| 27 devices = '[' | 41 devices = '[' |
| 28 file_name = args[0] | 42 file_name = args[0] |
| 29 inside_list = False | 43 inside_list = False |
| 30 with open(file_name, 'r') as f: | 44 with open(file_name, 'r') as f: |
| 31 for line in f: | 45 for line in f: |
| 32 if not inside_list: | 46 if not inside_list: |
| 33 if 'WebInspector.OverridesUI._phones = [' in line or \ | 47 if 'WebInspector.OverridesUI._phones = [' in line: |
| 34 'WebInspector.OverridesUI._tablets = [' in line: | 48 inside_list = True |
| 49 if 'WebInspector.OverridesUI._tablets = [' in line: | |
| 50 devices += ',' | |
| 35 inside_list = True | 51 inside_list = True |
| 36 else: | 52 else: |
| 37 if line.strip() == '];': | 53 if line.strip() == '];': |
| 38 inside_list = False | 54 inside_list = False |
| 39 continue | 55 continue |
| 40 devices += line.strip() | 56 devices += line.strip() |
| 41 | 57 |
| 58 output_dir = 'chrome/test/chromedriver/chrome' | |
| 42 devices += ']' | 59 devices += ']' |
| 60 devices = quotizeKeys(devices, | |
| 61 ['title', 'width', 'height', 'deviceScaleFactor', | |
| 62 'userAgent', 'touch', 'mobile']) | |
| 43 cpp_source.WriteSource('mobile_device_list', | 63 cpp_source.WriteSource('mobile_device_list', |
| 44 'chrome/test/chromedriver/chrome', | 64 output_dir, |
| 45 options.directory, {'kMobileDevices': devices}) | 65 options.directory, {'kMobileDevices': devices}) |
| 46 | 66 |
| 67 clang_format = ['clang-format', '-i'] | |
| 68 subprocess.Popen(clang_format + ['%s/mobile_device_list.cc' % output_dir]) | |
| 69 subprocess.Popen(clang_format + ['%s/mobile_device_list.h' % output_dir]) | |
| 70 | |
| 47 | 71 |
| 48 if __name__ == '__main__': | 72 if __name__ == '__main__': |
| 49 sys.exit(main()) | 73 sys.exit(main()) |
| OLD | NEW |