Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: tools/telemetry/catapult_base/dependency_manager/dependency_info.py

Issue 1391403003: Add priority groups to local paths in the dependency manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5
6 class DependencyInfo(object): 5 class DependencyInfo(object):
7 def __init__(self, dependency, platform, config_file, cs_bucket=None, 6 def __init__(self, dependency, platform, config_file, cs_bucket=None,
8 cs_hash=None, download_path=None, cs_remote_path=None, 7 cs_hash=None, download_path=None, cs_remote_path=None,
9 version_in_cs=None, unzip_path=None, 8 version_in_cs=None, unzip_path=None,
10 path_within_archive=None, local_paths=None): 9 path_within_archive=None, local_paths=None):
11 """ Container for the information needed for each dependency/platform pair 10 """ Container for the information needed for each dependency/platform pair
12 in the dependency_manager. 11 in the dependency_manager.
13 12
14 Args: 13 Args:
15 Required: 14 Required:
16 dependency: Name of the dependency. 15 dependency: Name of the dependency.
17 platform: Name of the platform to be run on. 16 platform: Name of the platform to be run on.
18 config_file: Path to the config_file this information came from. Used 17 config_file: Path to the config_file this information came from. Used
19 for error messages to improve debugging. 18 for error messages to improve debugging.
20 19
21 Minimum required for downloading from cloud storage: 20 Minimum required for downloading from cloud storage:
22 cs_bucket: The cloud storage bucket the dependency is located in. 21 cs_bucket: The cloud storage bucket the dependency is located in.
23 cs_hash: The hash of the file stored in cloud storage. 22 cs_hash: The hash of the file stored in cloud storage.
24 download_path: Where the file should be downloaded to. 23 download_path: Where the file should be downloaded to.
25 cs_remote_path: Where the file is stored in the cloud storage bucket. 24 cs_remote_path: Where the file is stored in the cloud storage bucket.
26 25
27 Optional for downloading from cloud storage: 26 Optional for downloading from cloud storage:
28 version: The version of the file stored in cloud storage. 27 version: The version of the file stored in cloud storage.
29 28
30 Optional: 29 Optional:
31 local_paths: A list of paths to search in order for a local file. 30 local_paths: A list of paths to search in order for a local file.
nednguyen 2015/10/09 16:20:07 Docstring needs update
aiolos (Not reviewing) 2015/10/09 16:52:00 Agreed, but I'm going to wait until the form of th
32 """ 31 """
33 # TODO(aiolos): update the above doc string for A) the usage of zip files 32 # TODO(aiolos): update the above doc string for A) the usage of zip files
34 # and B) supporting lists of local_paths to be checked for most recently 33 # and B) supporting lists of local_paths to be checked for most recently
35 # changed files. 34 # changed files.
36 if not dependency or not platform: 35 if not dependency or not platform:
37 raise ValueError( 36 raise ValueError(
38 'Must supply both a dependency and platform to DependencyInfo') 37 'Must supply both a dependency and platform to DependencyInfo')
39 38
40 self._dependency = dependency 39 self._dependency = dependency
41 self._platform = platform 40 self._platform = platform
42 self._config_files = [config_file] 41 self._config_files = [config_file]
43 self._local_paths = local_paths or [] 42 self._local_paths = self._ParseLocalPaths(local_paths)
nednguyen 2015/10/09 16:20:07 self._local_paths_groups
aiolos (Not reviewing) 2015/10/09 16:52:00 See my response in the comment on _ParseLocalPaths
44 self._download_path = download_path 43 self._download_path = download_path
45 self._cs_remote_path = cs_remote_path 44 self._cs_remote_path = cs_remote_path
46 self._cs_bucket = cs_bucket 45 self._cs_bucket = cs_bucket
47 self._cs_hash = cs_hash 46 self._cs_hash = cs_hash
48 self._version_in_cs = version_in_cs 47 self._version_in_cs = version_in_cs
49 self.VerifyCloudStorageInfo() 48 self._VerifyCloudStorageInfo()
50 49
51 def Update(self, new_dep_info): 50 def Update(self, new_dep_info):
52 """Add the information from |new_dep_info| to this instance. 51 """Add the information from |new_dep_info| to this instance.
53 """ 52 """
54 self._config_files.extend(new_dep_info.config_files) 53 self._config_files.extend(new_dep_info.config_files)
55 if (self.dependency != new_dep_info.dependency or 54 if (self.dependency != new_dep_info.dependency or
56 self.platform != new_dep_info.platform): 55 self.platform != new_dep_info.platform):
57 raise ValueError( 56 raise ValueError(
58 'Cannot update DependencyInfo with different dependency or platform.' 57 'Cannot update DependencyInfo with different dependency or platform.'
59 'Existing dep: %s, existing platform: %s. New dep: %s, new platform:' 58 'Existing dep: %s, existing platform: %s. New dep: %s, new platform:'
60 '%s. Config_files conflicting: %s' % ( 59 '%s. Config_files conflicting: %s' % (
61 self.dependency, self.platform, new_dep_info.dependency, 60 self.dependency, self.platform, new_dep_info.dependency,
62 new_dep_info.platform, self.config_files)) 61 new_dep_info.platform, self.config_files))
63 if new_dep_info.has_cs_info: 62 if new_dep_info.has_cs_info:
64 if self.has_cs_info: 63 if self.has_cs_info:
65 raise ValueError( 64 raise ValueError(
66 'Overriding cloud storage data is not allowed when updating a ' 65 'Overriding cloud storage data is not allowed when updating a '
67 'DependencyInfo. Conflict in dependency %s on platform %s in ' 66 'DependencyInfo. Conflict in dependency %s on platform %s in '
68 'config_files: %s.' % (self.dependency, self.platform, 67 'config_files: %s.' % (self.dependency, self.platform,
69 self.config_files)) 68 self.config_files))
70 else: 69 else:
71 self._download_path = new_dep_info.download_path 70 self._download_path = new_dep_info.download_path
72 self._cs_remote_path = new_dep_info.cs_remote_path 71 self._cs_remote_path = new_dep_info.cs_remote_path
73 self._cs_bucket = new_dep_info.cs_bucket 72 self._cs_bucket = new_dep_info.cs_bucket
74 self._cs_hash = new_dep_info.cs_hash 73 self._cs_hash = new_dep_info.cs_hash
75 self._version_in_cs = new_dep_info.version_in_cs 74 self._version_in_cs = new_dep_info.version_in_cs
76 if new_dep_info.local_paths: 75 if new_dep_info.local_paths:
77 for path in new_dep_info.local_paths: 76 for priority_group in new_dep_info.local_paths:
78 if path not in self._local_paths: 77 group_list = []
79 self._local_paths.append(path) 78 for path in priority_group:
79 if not self.IsPathInLocalPaths(path):
80 group_list.append(path)
81 if group_list:
82 self._local_paths.append(group_list)
83
84 def IsPathInLocalPaths(self, path):
85 return any(path in priority_group for priority_group in self._local_paths)
80 86
81 @property 87 @property
82 def dependency(self): 88 def dependency(self):
83 return self._dependency 89 return self._dependency
84 90
85 @property 91 @property
86 def platform(self): 92 def platform(self):
87 return self._platform 93 return self._platform
88 94
89 @property 95 @property
90 def config_files(self): 96 def config_files(self):
91 return self._config_files 97 return self._config_files
92 98
93 @property 99 @property
94 def local_paths(self): 100 def local_paths(self):
nednguyen 2015/10/09 16:20:07 This should be local_paths_groups
aiolos (Not reviewing) 2015/10/09 16:52:00 Same.
95 return self._local_paths 101 return self._local_paths
96 102
97 @property 103 @property
98 def download_path(self): 104 def download_path(self):
99 return self._download_path 105 return self._download_path
100 106
101 @property 107 @property
102 def cs_remote_path(self): 108 def cs_remote_path(self):
103 return self._cs_remote_path 109 return self._cs_remote_path
104 110
105 @property 111 @property
106 def cs_bucket(self): 112 def cs_bucket(self):
107 return self._cs_bucket 113 return self._cs_bucket
108 114
109 @property 115 @property
110 def cs_hash(self): 116 def cs_hash(self):
111 return self._cs_hash 117 return self._cs_hash
112 118
113 @property 119 @property
114 def version_in_cs(self): 120 def version_in_cs(self):
115 return self._version_in_cs 121 return self._version_in_cs
116 122
117 @property 123 @property
118 def has_cs_info(self): 124 def has_cs_info(self):
119 self.VerifyCloudStorageInfo() 125 self._VerifyCloudStorageInfo()
120 return self.cs_hash 126 return self.cs_hash
121 127
122 def VerifyCloudStorageInfo(self): 128 @staticmethod
129 def _ParseLocalPaths(local_paths):
nednguyen 2015/10/09 16:20:07 We should restrict the type of local_paths to list
aiolos (Not reviewing) 2015/10/09 16:52:00 I'm not sure why that's surprising, since priority
nednguyen 2015/10/09 17:04:04 The fact that priority groups is an optional featu
130 if not local_paths:
131 return []
132 list_of_lists = []
133 for element in local_paths:
134 if isinstance(element, basestring):
135 list_of_lists.append([element])
136 else:
137 list_of_lists.append(element)
138 return list_of_lists
139
140 def _VerifyCloudStorageInfo(self):
123 """Ensure either all or none of the needed remote information is specified. 141 """Ensure either all or none of the needed remote information is specified.
124 """ 142 """
125 if ((self.cs_bucket or self.cs_remote_path or self.download_path or 143 if ((self.cs_bucket or self.cs_remote_path or self.download_path or
126 self.cs_hash or self._version_in_cs) and not (self.cs_bucket and 144 self.cs_hash or self._version_in_cs) and not (self.cs_bucket and
127 self.cs_remote_path and self.download_path and self.cs_hash)): 145 self.cs_remote_path and self.download_path and self.cs_hash)):
128 raise ValueError( 146 raise ValueError(
129 'Attempted to partially initialize cloud storage data for ' 147 'Attempted to partially initialize cloud storage data for '
130 'dependency: %s, platform: %s, download_path: %s, ' 148 'dependency: %s, platform: %s, download_path: %s, '
131 'cs_remote_path: %s, cs_bucket %s, cs_hash %s, version_in_cs %s' % ( 149 'cs_remote_path: %s, cs_bucket %s, cs_hash %s, version_in_cs %s' % (
132 self.dependency, self.platform, self.download_path, 150 self.dependency, self.platform, self.download_path,
133 self.cs_remote_path, self.cs_bucket, self.cs_hash, 151 self.cs_remote_path, self.cs_bucket, self.cs_hash,
134 self._version_in_cs)) 152 self._version_in_cs))
135 153
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698