1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import dependency_manager
class BinaryManager(object):
""" This class is effectively a subclass of dependency_manager, but uses a
different number of arguments for FetchPath and LocalPath.
"""
def __init__(self, config_files):
if not config_files or not isinstance(config_files, list):
raise ValueError(
'Must supply a list of config files to the BinaryManager')
configs = [dependency_manager.BaseConfig(config) for config in config_files]
self._dependency_manager = dependency_manager.DependencyManager(configs)
def FetchPathWithVersion(self, binary_name, os_name, arch, os_version=None):
""" Return a path to the executable for <binary_name>, or None if not found.
Will attempt to download from cloud storage if needed.
"""
return self._WrapDependencyManagerFunction(
self._dependency_manager.FetchPathWithVersion, binary_name, os_name,
arch, os_version)
def FetchPath(self, binary_name, os_name, arch, os_version=None):
""" Return a path to the executable for <binary_name>, or None if not found.
Will attempt to download from cloud storage if needed.
"""
return self._WrapDependencyManagerFunction(
self._dependency_manager.FetchPath, binary_name, os_name, arch,
os_version)
def LocalPath(self, binary_name, os_name, arch, os_version=None):
""" Return a local path to the given binary name, or None if not found.
Will not download from cloud_storage.
"""
return self._WrapDependencyManagerFunction(
self._dependency_manager.LocalPath, binary_name, os_name, arch,
os_version)
def _WrapDependencyManagerFunction(
self, function, binary_name, os_name, arch, os_version):
platform = '%s_%s' % (os_name, arch)
if os_version:
try:
versioned_platform = '%s_%s_%s' % (os_name, os_version, arch)
return function(binary_name, versioned_platform)
except dependency_manager.NoPathFoundError:
logging.warning(
'Cannot find path for %s on platform %s. Falling back to %s.',
binary_name, versioned_platform, platform)
return function(binary_name, platform)
|