Add DependencyInfo and DepedencyManager exceptions.
[chromium-blink-merge.git] / tools / telemetry / catapult_base / dependency_manager / dependency_info.py
blobf5138daa17ce54c1ee8538b2067a54b3a51b3839
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.
6 class DependencyInfo(object):
7 def __init__(self, dependency, platform, config_file, cs_bucket=None,
8 cs_hash=None, download_path=None, cs_remote_path=None,
9 local_paths=None):
10 """ Container for the information needed for each dependency/platform pair
11 in the dependency_manager.
13 Information about the file:
14 dependency: Name of the dependency.
15 platform: Name of the platform to be run on.
16 config_file: Path to the config_file this information came from. Used for
17 error messages to improve debugging.
19 Information used for downloading from cloud storage:
20 cs_bucket: The cloud_storage bucket the dependency is located in.
21 cs_hash: The hash of the file stored in cloud_storage.
22 download_path: Where the file should be downloaded to.
23 cs_remote_path: Where the file is stored in the cloud_storage bucket.
25 local_paths: A list of paths to search in order for a local file.
26 """
27 # TODO(aiolos): update the above doc string for A) the usage of zip files
28 # and B) supporting lists of local_paths to be checked for most recently
29 # changed files.
30 if not dependency or not platform:
31 raise ValueError(
32 'Must supply both a dependency and platform to DependencyInfo')
34 self._dependency = dependency
35 self._platform = platform
36 self._config_files = [config_file]
37 self._local_paths = local_paths or []
38 self._download_path = download_path
39 self._cs_remote_path = cs_remote_path
40 self._cs_bucket = cs_bucket
41 self._cs_hash = cs_hash
42 self.VerifyCloudStorageInfo()
44 def Update(self, new_dep_info, append_to_front):
45 """Add the information from |new_dep_info| to this instance.
47 append_to_front: Whether new local_paths should be appended to the front of
48 the local_paths list, or the end.
49 """
50 self._config_files.extend(new_dep_info.config_files)
51 if (self.dependency != new_dep_info.dependency or
52 self.platform != new_dep_info.platform):
53 raise ValueError(
54 'Cannot update DependencyInfo with different dependency or platform.'
55 'Existing dep: %s, existing platform: %s. New dep: %s, new platform:'
56 '%s. Config_files conflicting: %s' % (
57 self.dependency, self.platform, new_dep_info.dependency,
58 new_dep_info.platform, self.config_files))
59 if new_dep_info.has_cs_info:
60 if self.has_cs_info:
61 raise ValueError(
62 'Overriding cloud_storage data is not allowed when updating a '
63 'DependencyInfo. Conflict in dependency %s on platform %s in '
64 'config_files: %s.' % (self.dependency, self.platform,
65 self.config_files))
66 else:
67 self._download_path = new_dep_info.download_path
68 self._cs_remote_path = new_dep_info.cs_remote_path
69 self._cs_bucket = new_dep_info.cs_bucket
70 self._cs_hash = new_dep_info.cs_hash
71 if new_dep_info.local_paths:
72 if append_to_front:
73 self._local_paths = [path for path in self._local_paths if
74 path not in new_dep_info.local_paths]
75 self._local_paths[0:0] = new_dep_info.local_paths
76 else:
77 for path in new_dep_info.local_paths:
78 if path not in self._local_paths:
79 self._local_paths.append(path)
81 @property
82 def dependency(self):
83 return self._dependency
85 @property
86 def platform(self):
87 return self._platform
89 @property
90 def config_files(self):
91 return self._config_files
93 @property
94 def local_paths(self):
95 return self._local_paths
97 @property
98 def download_path(self):
99 return self._download_path
101 @property
102 def cs_remote_path(self):
103 return self._cs_remote_path
105 @property
106 def cs_bucket(self):
107 return self._cs_bucket
109 @property
110 def cs_hash(self):
111 return self._cs_hash
113 @property
114 def has_cs_info(self):
115 self.VerifyCloudStorageInfo()
116 return self.cs_hash
118 def VerifyCloudStorageInfo(self):
119 """Ensure either all or none of the needed remote information is specified.
121 if ((self.cs_bucket or self.cs_remote_path or self.download_path or
122 self.cs_hash) and not (self.cs_bucket and self.cs_remote_path and
123 self.download_path and self.cs_hash)):
124 raise ValueError(
125 'Attempted to partially initialize cloud storage data for '
126 'dependency: %s, platform: %s, download_path: %s, '
127 'cs_remote_path: %s, cs_bucket %s, cs_hash %s' % (
128 self.dependency, self.platform, self.download_path,
129 self.cs_remote_path, self.cs_bucket, self.cs_hash))