• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 The Chromium 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
5import os
6
7from catapult_base import binary_manager
8from dependency_manager import base_config
9from dependency_manager import exceptions as dependency_manager_exceptions
10from devil import devil_env
11
12from telemetry.core import exceptions
13from telemetry.core import util
14
15
16TELEMETRY_PROJECT_CONFIG = os.path.join(
17    util.GetTelemetryDir(), 'telemetry', 'internal', 'binary_dependencies.json')
18
19
20CHROME_BINARY_CONFIG = os.path.join(util.GetCatapultDir(), 'catapult_base',
21                                    'catapult_base', 'chrome_binaries.json')
22
23
24NoPathFoundError = dependency_manager_exceptions.NoPathFoundError
25CloudStorageError = dependency_manager_exceptions.CloudStorageError
26
27
28_binary_manager = None
29
30
31def NeedsInit():
32  return not _binary_manager
33
34
35def InitDependencyManager(environment_config):
36  global _binary_manager
37  if _binary_manager:
38    raise exceptions.InitializationError(
39        'Trying to re-initialize the binary manager with config %s'
40        % environment_config)
41  configs = [base_config.BaseConfig(TELEMETRY_PROJECT_CONFIG),
42             base_config.BaseConfig(CHROME_BINARY_CONFIG)]
43  if environment_config:
44    configs.insert(0, base_config.BaseConfig(environment_config))
45  _binary_manager = binary_manager.BinaryManager(configs)
46
47  devil_env.config.Initialize()
48
49
50def FetchPath(binary_name, arch, os_name, os_version=None):
51  """ Return a path to the appropriate executable for <binary_name>, downloading
52      from cloud storage if needed, or None if it cannot be found.
53  """
54  if _binary_manager is None:
55    raise exceptions.InitializationError(
56        'Called FetchPath with uninitialized binary manager.')
57  return _binary_manager.FetchPath(binary_name, arch, os_name, os_version)
58
59
60def LocalPath(binary_name, arch, os_name, os_version=None):
61  """ Return a local path to the given binary name, or None if an executable
62      cannot be found. Will not download the executable.
63      """
64  if _binary_manager is None:
65    raise exceptions.InitializationError(
66        'Called LocalPath with uninitialized binary manager.')
67  return _binary_manager.LocalPath(binary_name, arch, os_name, os_version)
68