OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 import itertools | 6 import itertools |
7 import json | 7 import json |
8 import os.path | 8 import os.path |
9 import sys | 9 import sys |
10 import optparse | 10 import optparse |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 def _GenerateTrials(config, platform): | 68 def _GenerateTrials(config, platform): |
69 for study_name in sorted(config.keys()): | 69 for study_name in sorted(config.keys()): |
70 study = _CreateTrial(study_name, config[study_name], platform) | 70 study = _CreateTrial(study_name, config[study_name], platform) |
71 # To avoid converting studies with empty experiments (e.g. the study doesn't | 71 # To avoid converting studies with empty experiments (e.g. the study doesn't |
72 # apply to the target platform), this generator only yields studies that | 72 # apply to the target platform), this generator only yields studies that |
73 # have non-empty experiments. | 73 # have non-empty experiments. |
74 if study['experiments']: | 74 if study['experiments']: |
75 yield study | 75 yield study |
76 | 76 |
77 def ConfigToStudies(config, platform): | |
78 """Returns the applicable studies from config for the platform.""" | |
79 return [study for study in _GenerateTrials(config, platform)] | |
80 | |
81 def _FieldTrialConfigToDescription(config, platform): | 77 def _FieldTrialConfigToDescription(config, platform): |
82 return { | 78 return { |
83 'elements': { | 79 'elements': { |
84 'kFieldTrialConfig': { | 80 'kFieldTrialConfig': { |
85 'studies': ConfigToStudies(config, platform) | 81 'studies': [study for study in _GenerateTrials(config, platform)] |
86 } | 82 } |
87 } | 83 } |
88 } | 84 } |
89 | 85 |
90 def main(arguments): | 86 def main(arguments): |
91 parser = optparse.OptionParser( | 87 parser = optparse.OptionParser( |
92 description='Generates a struct from a JSON description.', | 88 description='Generates a struct from a JSON description.', |
93 usage='usage: %prog [option] -s schema -p platform description') | 89 usage='usage: %prog [option] -s schema -p platform description') |
94 parser.add_option('-b', '--destbase', | 90 parser.add_option('-b', '--destbase', |
95 help='base directory of generated files.') | 91 help='base directory of generated files.') |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 128 |
133 schema = _Load(opts.schema) | 129 schema = _Load(opts.schema) |
134 description = _LoadFieldTrialConfig(description_filename, opts.platform) | 130 description = _LoadFieldTrialConfig(description_filename, opts.platform) |
135 json_to_struct.GenerateStruct( | 131 json_to_struct.GenerateStruct( |
136 basepath, output_root, opts.namespace, schema, description, | 132 basepath, output_root, opts.namespace, schema, description, |
137 os.path.split(description_filename)[1], os.path.split(opts.schema)[1], | 133 os.path.split(description_filename)[1], os.path.split(opts.schema)[1], |
138 opts.year) | 134 opts.year) |
139 | 135 |
140 if __name__ == '__main__': | 136 if __name__ == '__main__': |
141 main(sys.argv[1:]) | 137 main(sys.argv[1:]) |
OLD | NEW |