blob: dd6690c097eab4bfd99ca6f90d8584e78ad10f35 [file] [log] [blame]
Chris Masone44e4d6c2012-08-15 14:25:53 -07001# 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
6from autotest_lib.client.common_lib import global_config
7from autotest_lib.client.common_lib.cros import dev_server
8
9
10_CONFIG = global_config.global_config
11
12
13def image_url_pattern():
14 return _CONFIG.get_config_value('CROS', 'image_url_pattern', type=str)
15
16
17def sharding_factor():
18 return _CONFIG.get_config_value('CROS', 'sharding_factor', type=int)
19
20
Chris Masonee99bcf22012-08-17 15:09:49 -070021def infrastructure_user_list():
22 return _CONFIG.get_config_value('CROS', 'infrastructure_users', type=list,
23 default=[])
24
25
Chris Masone44e4d6c2012-08-15 14:25:53 -070026def package_url_pattern():
27 return _CONFIG.get_config_value('CROS', 'package_url_pattern', type=str)
28
29
Chris Sosaaccb5ce2012-08-30 17:29:15 -070030def 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 Masone44e4d6c2012-08-15 14:25:53 -070038 return package_url_pattern() % (devserver_url, build)
39
40
41def 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