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

Side by Side Diff: tools/variations/fieldtrial_util.py

Issue 1209743002: Generate a static struct from fieldtrial_testing_config (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@codegen_nested_structs
Patch Set: add +x file permission Created 5 years, 5 months 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 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import sys 6 import sys
7 7
8 8
9 def _hex(ch): 9 def _hex(ch):
10 hv = hex(ord(ch)).replace('0x', '') 10 hv = hex(ord(ch)).replace('0x', '')
11 hv.zfill(2) 11 hv.zfill(2)
12 return hv.upper() 12 return hv.upper()
13 13
14 # URL escapes the delimiter characters from the output. urllib.quote is not 14 # URL escapes the delimiter characters from the output. urllib.quote is not
15 # used because it cannot escape '.'. 15 # used because it cannot escape '.'.
16 def _escape(str): 16 def _escape(str):
17 result = str 17 result = str
18 # Must perform replace on '%' first before the others. 18 # Must perform replace on '%' first before the others.
19 for c in '%:/.,': 19 for c in '%:/.,':
20 result = result.replace(c, '%' + _hex(c)) 20 result = result.replace(c, '%' + _hex(c))
21 return result 21 return result
22 22
23 # Generate a list of command-line switches to enable field trials defined in 23 # Generate a list of command-line switches to enable field trials defined in
24 # fieldtrial_testing_config_*.json. 24 # fieldtrial_testing_config_*.json.
25 def GenerateArgs(base_config_path, platform_config_path=None): 25 def GenerateArgs(config_path):
26 try: 26 try:
27 with open(base_config_path, 'r') as base_file: 27 with open(config_path, 'r') as base_file:
28 variations = json.load(base_file) 28 variations = json.load(base_file)
29 if platform_config_path:
30 try:
31 with open(platform_config_path, 'r') as platform_file:
32 platform_specifics = json.load(platform_file)
33 variations.update(platform_specifics)
34 except (IOError, ValueError):
35 pass
36 except (IOError, ValueError): 29 except (IOError, ValueError):
37 return [] 30 return []
38 31
39 field_trials = [] 32 field_trials = []
40 params = [] 33 params = []
41 for trial, groups in variations.iteritems(): 34 for trial, groups in variations.iteritems():
42 if not len(groups): 35 if not len(groups):
43 continue 36 continue
44 # For now, only take the first group. 37 # For now, only take the first group.
45 group = groups[0] 38 group = groups[0]
(...skipping 18 matching lines...) Expand all
64 return args 57 return args
65 58
66 def main(): 59 def main():
67 if len(sys.argv) < 3: 60 if len(sys.argv) < 3:
68 print 'Usage: fieldtrial_util.py [base_config_path] [platform_config_path]' 61 print 'Usage: fieldtrial_util.py [base_config_path] [platform_config_path]'
69 exit(-1) 62 exit(-1)
70 print GenerateArgs(sys.argv[1], sys.argv[2]) 63 print GenerateArgs(sys.argv[1], sys.argv[2])
71 64
72 if __name__ == '__main__': 65 if __name__ == '__main__':
73 main() 66 main()
OLDNEW
« no previous file with comments | « tools/variations/fieldtrial_to_struct_unittest.py ('k') | tools/variations/fieldtrial_util_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698