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