| 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 |
| 77 def _FieldTrialConfigToDescription(config, platform): | 81 def _FieldTrialConfigToDescription(config, platform): |
| 78 return { | 82 return { |
| 79 'elements': { | 83 'elements': { |
| 80 'kFieldTrialConfig': { | 84 'kFieldTrialConfig': { |
| 81 'studies': [study for study in _GenerateTrials(config, platform)] | 85 'studies': ConfigToStudies(config, platform) |
| 82 } | 86 } |
| 83 } | 87 } |
| 84 } | 88 } |
| 85 | 89 |
| 86 def main(arguments): | 90 def main(arguments): |
| 87 parser = optparse.OptionParser( | 91 parser = optparse.OptionParser( |
| 88 description='Generates a struct from a JSON description.', | 92 description='Generates a struct from a JSON description.', |
| 89 usage='usage: %prog [option] -s schema -p platform description') | 93 usage='usage: %prog [option] -s schema -p platform description') |
| 90 parser.add_option('-b', '--destbase', | 94 parser.add_option('-b', '--destbase', |
| 91 help='base directory of generated files.') | 95 help='base directory of generated files.') |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 132 |
| 129 schema = _Load(opts.schema) | 133 schema = _Load(opts.schema) |
| 130 description = _LoadFieldTrialConfig(description_filename, opts.platform) | 134 description = _LoadFieldTrialConfig(description_filename, opts.platform) |
| 131 json_to_struct.GenerateStruct( | 135 json_to_struct.GenerateStruct( |
| 132 basepath, output_root, opts.namespace, schema, description, | 136 basepath, output_root, opts.namespace, schema, description, |
| 133 os.path.split(description_filename)[1], os.path.split(opts.schema)[1], | 137 os.path.split(description_filename)[1], os.path.split(opts.schema)[1], |
| 134 opts.year) | 138 opts.year) |
| 135 | 139 |
| 136 if __name__ == '__main__': | 140 if __name__ == '__main__': |
| 137 main(sys.argv[1:]) | 141 main(sys.argv[1:]) |
| OLD | NEW |