OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import download | 5 import download |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 from sdk_update_common import Error | 8 from sdk_update_common import Error |
9 import sdk_update_common | 9 import sdk_update_common |
10 import sys | 10 import sys |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 if tar_file: | 125 if tar_file: |
126 tar_file.Close() | 126 tar_file.Close() |
127 | 127 |
128 # Remove the archive. | 128 # Remove the archive. |
129 os.remove(archive_path) | 129 os.remove(archive_path) |
130 | 130 |
131 | 131 |
132 def Update(delegate, remote_manifest, local_manifest, bundle_names, force): | 132 def Update(delegate, remote_manifest, local_manifest, bundle_names, force): |
133 valid_bundles = set([bundle.name for bundle in remote_manifest.GetBundles()]) | 133 valid_bundles = set([bundle.name for bundle in remote_manifest.GetBundles()]) |
134 requested_bundles = _GetRequestedBundlesFromArgs(remote_manifest, | 134 requested_bundles = _GetRequestedBundleNamesFromArgs(remote_manifest, |
135 bundle_names) | 135 bundle_names) |
136 invalid_bundles = requested_bundles - valid_bundles | 136 invalid_bundles = requested_bundles - valid_bundles |
137 if invalid_bundles: | 137 if invalid_bundles: |
138 logging.warn('Ignoring unknown bundle(s): %s' % ( | 138 logging.warn('Ignoring unknown bundle(s): %s' % ( |
139 ', '.join(invalid_bundles))) | 139 ', '.join(invalid_bundles))) |
140 requested_bundles -= invalid_bundles | 140 requested_bundles -= invalid_bundles |
141 | 141 |
142 if SDK_TOOLS in requested_bundles: | 142 if SDK_TOOLS in requested_bundles: |
143 logging.warn('Updating sdk_tools happens automatically. ' | 143 logging.warn('Updating sdk_tools happens automatically. ' |
144 'Ignoring manual update request.') | 144 'Ignoring manual update request.') |
145 requested_bundles.discard(SDK_TOOLS) | 145 requested_bundles.discard(SDK_TOOLS) |
(...skipping 22 matching lines...) Expand all Loading... |
168 % (bundle_name,)) | 168 % (bundle_name,)) |
169 return | 169 return |
170 | 170 |
171 _UpdateBundle(delegate, bundle, local_manifest) | 171 _UpdateBundle(delegate, bundle, local_manifest) |
172 else: | 172 else: |
173 print '%s is already up-to-date.' % (bundle.name,) | 173 print '%s is already up-to-date.' % (bundle.name,) |
174 else: | 174 else: |
175 logging.error('Bundle %s does not exist.' % (bundle_name,)) | 175 logging.error('Bundle %s does not exist.' % (bundle_name,)) |
176 | 176 |
177 | 177 |
178 def _GetRequestedBundlesFromArgs(remote_manifest, requested_bundles): | 178 def _GetRequestedBundleNamesFromArgs(remote_manifest, requested_bundles): |
179 requested_bundles = set(requested_bundles) | 179 requested_bundles = set(requested_bundles) |
180 if RECOMMENDED in requested_bundles: | 180 if RECOMMENDED in requested_bundles: |
181 requested_bundles.discard(RECOMMENDED) | 181 requested_bundles.discard(RECOMMENDED) |
182 requested_bundles |= set(_GetRecommendedBundles(remote_manifest)) | 182 requested_bundles |= set(_GetRecommendedBundleNames(remote_manifest)) |
183 | 183 |
184 return requested_bundles | 184 return requested_bundles |
185 | 185 |
186 | 186 |
187 def _GetRecommendedBundles(remote_manifest): | 187 def _GetRecommendedBundleNames(remote_manifest): |
188 return [bundle for bundle in remote_manifest.GetBundles() if | 188 return [bundle.name for bundle in remote_manifest.GetBundles() if |
189 bundle.recommended] | 189 bundle.recommended] |
190 | 190 |
191 | 191 |
192 def _BundleNeedsUpdate(delegate, local_manifest, bundle): | 192 def _BundleNeedsUpdate(delegate, local_manifest, bundle): |
193 # Always update the bundle if the directory doesn't exist; | 193 # Always update the bundle if the directory doesn't exist; |
194 # the user may have deleted it. | 194 # the user may have deleted it. |
195 if not delegate.BundleDirectoryExists(bundle.name): | 195 if not delegate.BundleDirectoryExists(bundle.name): |
196 return True | 196 return True |
197 | 197 |
198 return local_manifest.BundleNeedsUpdate(bundle) | 198 return local_manifest.BundleNeedsUpdate(bundle) |
(...skipping 11 matching lines...) Expand all Loading... |
210 _ValidateArchive(archive, sha1, size) | 210 _ValidateArchive(archive, sha1, size) |
211 | 211 |
212 print 'Updating bundle %s to version %s, revision %s' % ( | 212 print 'Updating bundle %s to version %s, revision %s' % ( |
213 bundle.name, bundle.version, bundle.revision) | 213 bundle.name, bundle.version, bundle.revision) |
214 extract_dir = bundle.name + '_update' | 214 extract_dir = bundle.name + '_update' |
215 | 215 |
216 repath_dir = bundle.get('repath', None) | 216 repath_dir = bundle.get('repath', None) |
217 if repath_dir: | 217 if repath_dir: |
218 # If repath is specified: | 218 # If repath is specified: |
219 # The files are extracted to nacl_sdk/<bundle.name>_update/<repath>/... | 219 # The files are extracted to nacl_sdk/<bundle.name>_update/<repath>/... |
220 # The destination directory is nacl_sdk/<repath>/... | 220 # The destination directory is nacl_sdk/<bundle.name>/... |
221 rename_from_dir = os.path.join(extract_dir, repath_dir) | 221 rename_from_dir = os.path.join(extract_dir, repath_dir) |
222 rename_to_dir = repath_dir | |
223 else: | 222 else: |
224 # If no repath is specified: | 223 # If no repath is specified: |
225 # The files are extracted to nacl_sdk/<bundle.name>_update/... | 224 # The files are extracted to nacl_sdk/<bundle.name>_update/... |
226 # The destination directory is nacl_sdk/<bundle.name>/... | 225 # The destination directory is nacl_sdk/<bundle.name>/... |
227 rename_from_dir = extract_dir | 226 rename_from_dir = extract_dir |
228 rename_to_dir = bundle.name | 227 |
| 228 rename_to_dir = bundle.name |
229 | 229 |
230 delegate.ExtractArchive(dest_filename, extract_dir, rename_from_dir, | 230 delegate.ExtractArchive(dest_filename, extract_dir, rename_from_dir, |
231 rename_to_dir) | 231 rename_to_dir) |
232 | 232 |
233 logging.info('Updating local manifest to include bundle %s' % (bundle.name)) | 233 logging.info('Updating local manifest to include bundle %s' % (bundle.name)) |
234 local_manifest.MergeBundle(bundle) | 234 local_manifest.MergeBundle(bundle) |
235 | 235 |
236 | 236 |
237 def _GetFilenameFromURL(url): | 237 def _GetFilenameFromURL(url): |
238 _, _, path, _, _, _ = urlparse.urlparse(url) | 238 _, _, path, _, _, _ = urlparse.urlparse(url) |
239 return path.split('/')[-1] | 239 return path.split('/')[-1] |
240 | 240 |
241 | 241 |
242 def _ValidateArchive(archive, actual_sha1, actual_size): | 242 def _ValidateArchive(archive, actual_sha1, actual_size): |
243 if actual_sha1 != archive.GetChecksum(): | 243 if actual_sha1 != archive.GetChecksum(): |
244 raise Error('SHA1 checksum mismatch on "%s". Expected %s but got %s' % ( | 244 raise Error('SHA1 checksum mismatch on "%s". Expected %s but got %s' % ( |
245 archive.name, archive.GetChecksum(), actual_sha1)) | 245 archive.name, archive.GetChecksum(), actual_sha1)) |
246 if actual_size != archive.size: | 246 if actual_size != archive.size: |
247 raise Error('Size mismatch on "%s". Expected %s but got %s bytes' % ( | 247 raise Error('Size mismatch on "%s". Expected %s but got %s bytes' % ( |
248 archive.name, archive.size, actual_size)) | 248 archive.name, archive.size, actual_size)) |
OLD | NEW |