Chris Masone | 44e4d6c | 2012-08-15 14:25:53 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS 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. |
| 4 | |
| 5 | |
| 6 | from autotest_lib.client.common_lib import global_config |
| 7 | from autotest_lib.client.common_lib.cros import dev_server |
| 8 | |
| 9 | |
| 10 | _CONFIG = global_config.global_config |
| 11 | |
| 12 | |
| 13 | def image_url_pattern(): |
| 14 | return _CONFIG.get_config_value('CROS', 'image_url_pattern', type=str) |
| 15 | |
| 16 | |
| 17 | def sharding_factor(): |
| 18 | return _CONFIG.get_config_value('CROS', 'sharding_factor', type=int) |
| 19 | |
| 20 | |
Chris Masone | e99bcf2 | 2012-08-17 15:09:49 -0700 | [diff] [blame] | 21 | def infrastructure_user_list(): |
| 22 | return _CONFIG.get_config_value('CROS', 'infrastructure_users', type=list, |
| 23 | default=[]) |
| 24 | |
| 25 | |
Chris Masone | 44e4d6c | 2012-08-15 14:25:53 -0700 | [diff] [blame] | 26 | def package_url_pattern(): |
| 27 | return _CONFIG.get_config_value('CROS', 'package_url_pattern', type=str) |
| 28 | |
| 29 | |
Chris Sosa | accb5ce | 2012-08-30 17:29:15 -0700 | [diff] [blame^] | 30 | def get_package_url(devserver_url, build): |
| 31 | """Returns the package url from the |devserver_url| and |build|. |
| 32 | |
| 33 | @param devserver_url: a string specifying the host to contact e.g. |
| 34 | http://my_host:9090. |
| 35 | @param build: the build/image string to use e.g. mario-release/R19-123.0.1. |
| 36 | @return the url where you can find the packages for the build. |
| 37 | """ |
Chris Masone | 44e4d6c | 2012-08-15 14:25:53 -0700 | [diff] [blame] | 38 | return package_url_pattern() % (devserver_url, build) |
| 39 | |
| 40 | |
| 41 | def inject_vars(vars, control_file_in): |
| 42 | """ |
| 43 | Inject the contents of |vars| into |control_file_in|. |
| 44 | |
| 45 | @param vars: a dict to shoehorn into the provided control file string. |
| 46 | @param control_file_in: the contents of a control file to munge. |
| 47 | @return the modified control file string. |
| 48 | """ |
| 49 | control_file = '' |
| 50 | for key, value in vars.iteritems(): |
| 51 | # None gets injected as 'None' without this check; same for digits. |
| 52 | if isinstance(value, str): |
| 53 | control_file += "%s='%s'\n" % (key, value) |
| 54 | else: |
| 55 | control_file += "%s=%r\n" % (key, value) |
| 56 | return control_file + control_file_in |