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
3 # found in the LICENSE file.
10 hv
= hex(ord(ch
)).replace('0x', '')
14 # URL escapes the delimiter characters from the output. urllib.quote is not
15 # used because it cannot escape '.'.
18 # Must perform replace on '%' first before the others.
20 result
= result
.replace(c
, '%' + _hex(c
))
23 # Generate a list of command-line switches to enable field trials defined in
24 # fieldtrial_testing_config_*.json.
25 def GenerateArgs(base_config_path
, platform_config_path
=None):
27 with
open(base_config_path
, 'r') as base_file
:
28 variations
= json
.load(base_file
)
29 if platform_config_path
:
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):
36 except (IOError, ValueError):
41 for trial
, groups
in variations
.iteritems():
44 # For now, only take the first group.
46 trial_group
= [trial
, group
['group_name']]
47 field_trials
.extend(trial_group
)
50 for key
, value
in group
['params'].iteritems():
51 param_list
.append(key
)
52 param_list
.append(value
)
54 # Escape the variables for the command-line.
55 trial_group
= [_escape(x
) for x
in trial_group
]
56 param_list
= [_escape(x
) for x
in param_list
]
57 param
= '%s:%s' % ('.'.join(trial_group
), '/'.join(param_list
))
59 if not len(field_trials
):
61 args
= ['--force-fieldtrials=%s' % '/'.join(field_trials
)]
63 args
.append('--force-fieldtrial-params=%s' % ','.join(params
))
68 print 'Usage: fieldtrial_util.py [base_config_path] [platform_config_path]'
70 print GenerateArgs(sys
.argv
[1], sys
.argv
[2])
72 if __name__
== '__main__':