Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / chrome / test / chromedriver / embed_mobile_devices_in_cpp.py
blob327012d120b18a9c56ded8e720f766d1772f3407
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
6 """Embeds standalone JavaScript snippets in C++ code.
8 The script requires the devtools/front_end/toolbox/OverridesUI.js file from
9 WebKit that lists the known mobile devices to be passed in as the only argument.
10 The list of known devices will be written to a C-style string to be parsed with
11 JSONReader.
12 """
14 import optparse
15 import os
16 import re
17 import subprocess
18 import sys
20 import cpp_source
23 def quotizeKeys(s, keys):
24 """Returns the string s with each instance of each key wrapped in quotes.
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
35 def main():
36 parser = optparse.OptionParser()
37 parser.add_option(
38 '', '--directory', type='string', default='.',
39 help='Path to directory where the cc/h files should be created')
40 options, args = parser.parse_args()
42 devices = '['
43 file_name = args[0]
44 inside_list = False
45 with open(file_name, 'r') as f:
46 for line in f:
47 if not inside_list:
48 if 'WebInspector.OverridesUI._phones = [' in line:
49 inside_list = True
50 if 'WebInspector.OverridesUI._tablets = [' in line:
51 devices += ','
52 inside_list = True
53 else:
54 if line.strip() == '];':
55 inside_list = False
56 continue
57 devices += line.strip()
59 output_dir = 'chrome/test/chromedriver/chrome'
60 devices += ']'
61 devices = quotizeKeys(devices,
62 ['title', 'width', 'height', 'deviceScaleFactor',
63 'userAgent', 'touch', 'mobile'])
64 cpp_source.WriteSource('mobile_device_list',
65 output_dir,
66 options.directory, {'kMobileDevices': devices})
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])
73 if __name__ == '__main__':
74 sys.exit(main())