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,
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.
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
30 if not dependency
or not platform
:
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.
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
):
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
:
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
,
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
:
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
77 for path
in new_dep_info
.local_paths
:
78 if path
not in self
._local
_paths
:
79 self
._local
_paths
.append(path
)
83 return self
._dependency
90 def config_files(self
):
91 return self
._config
_files
94 def local_paths(self
):
95 return self
._local
_paths
98 def download_path(self
):
99 return self
._download
_path
102 def cs_remote_path(self
):
103 return self
._cs
_remote
_path
107 return self
._cs
_bucket
114 def has_cs_info(self
):
115 self
.VerifyCloudStorageInfo()
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
)):
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
))