Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/test/chromedriver/embed_mobile_devices_in_cpp.py

Issue 749353003: [chromedriver] Fix mobile device embedding script (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Responding to comments; using clang-format Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
57 output_dir = 'chrome/test/chromedriver/chrome'
42 devices += ']' 58 devices += ']'
59 devices = quotizeKeys(devices,
60 ['title', 'width', 'height', 'deviceScaleFactor',
61 'userAgent', 'touch', 'mobile'])
43 cpp_source.WriteSource('mobile_device_list', 62 cpp_source.WriteSource('mobile_device_list',
44 'chrome/test/chromedriver/chrome', 63 output_dir,
45 options.directory, {'kMobileDevices': devices}) 64 options.directory, {'kMobileDevices': devices})
46 65
66 print('\n'.join([
67 'Be sure to format output files:',
68 ' clang-format -i %s/mobile_device_list.cc' % output_dir,
69 ' clang-format -i %s/mobile_device_list.h' % output_dir]))
samuong 2015/01/20 22:02:33 It'd be nice if we could automate this. Can you us
srawlins 2015/01/22 20:15:58 Done.
70
47 71
48 if __name__ == '__main__': 72 if __name__ == '__main__':
49 sys.exit(main()) 73 sys.exit(main())
OLDNEW
« chrome/test/chromedriver/cpp_source.py ('K') | « chrome/test/chromedriver/cpp_source.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698