| 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 devtools/front_end/toolbox/OverridesUI.js file from |
| 9 mobile devices to be passed in as the only argument. The list of known devices | 9 WebKit that lists the known mobile devices to be passed in as the only argument. |
| 10 will be written to a C-style string to be parsed with JSONReader. | 10 The list of known devices will be written to a C-style string to be parsed with |
| 11 JSONReader. |
| 11 """ | 12 """ |
| 12 | 13 |
| 13 import optparse | 14 import optparse |
| 14 import os | 15 import os |
| 16 import re |
| 17 import subprocess |
| 15 import sys | 18 import sys |
| 16 | 19 |
| 17 import cpp_source | 20 import cpp_source |
| 18 | 21 |
| 19 | 22 |
| 23 def quotizeKeys(s, keys): |
| 24 """Returns the string s with each instance of each key wrapped in quotes. |
| 25 |
| 26 Args: |
| 27 s: a string containing keys that need to be wrapped in quotes. |
| 28 keys: an iterable of keys to be wrapped in quotes in the string. |
| 29 """ |
| 30 for key in keys: |
| 31 s = re.sub('%s: ' % key, '"%s": ' % key, s) |
| 32 return s |
| 33 |
| 34 |
| 20 def main(): | 35 def main(): |
| 21 parser = optparse.OptionParser() | 36 parser = optparse.OptionParser() |
| 22 parser.add_option( | 37 parser.add_option( |
| 23 '', '--directory', type='string', default='.', | 38 '', '--directory', type='string', default='.', |
| 24 help='Path to directory where the cc/h files should be created') | 39 help='Path to directory where the cc/h files should be created') |
| 25 options, args = parser.parse_args() | 40 options, args = parser.parse_args() |
| 26 | 41 |
| 27 devices = '[' | 42 devices = '[' |
| 28 file_name = args[0] | 43 file_name = args[0] |
| 29 inside_list = False | 44 inside_list = False |
| 30 with open(file_name, 'r') as f: | 45 with open(file_name, 'r') as f: |
| 31 for line in f: | 46 for line in f: |
| 32 if not inside_list: | 47 if not inside_list: |
| 33 if 'WebInspector.OverridesUI._phones = [' in line or \ | 48 if 'WebInspector.OverridesUI._phones = [' in line: |
| 34 'WebInspector.OverridesUI._tablets = [' in line: | 49 inside_list = True |
| 50 if 'WebInspector.OverridesUI._tablets = [' in line: |
| 51 devices += ',' |
| 35 inside_list = True | 52 inside_list = True |
| 36 else: | 53 else: |
| 37 if line.strip() == '];': | 54 if line.strip() == '];': |
| 38 inside_list = False | 55 inside_list = False |
| 39 continue | 56 continue |
| 40 devices += line.strip() | 57 devices += line.strip() |
| 41 | 58 |
| 59 output_dir = 'chrome/test/chromedriver/chrome' |
| 42 devices += ']' | 60 devices += ']' |
| 61 devices = quotizeKeys(devices, |
| 62 ['title', 'width', 'height', 'deviceScaleFactor', |
| 63 'userAgent', 'touch', 'mobile']) |
| 43 cpp_source.WriteSource('mobile_device_list', | 64 cpp_source.WriteSource('mobile_device_list', |
| 44 'chrome/test/chromedriver/chrome', | 65 output_dir, |
| 45 options.directory, {'kMobileDevices': devices}) | 66 options.directory, {'kMobileDevices': devices}) |
| 46 | 67 |
| 68 clang_format = ['clang-format', '-i'] |
| 69 subprocess.Popen(clang_format + ['%s/mobile_device_list.cc' % output_dir]) |
| 70 subprocess.Popen(clang_format + ['%s/mobile_device_list.h' % output_dir]) |
| 71 |
| 47 | 72 |
| 48 if __name__ == '__main__': | 73 if __name__ == '__main__': |
| 49 sys.exit(main()) | 74 sys.exit(main()) |
| OLD | NEW |