OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 '''Utility to update the SDK manifest file in the build_tools directory''' | 6 '''Utility to update the SDK manifest file in the build_tools directory''' |
7 | 7 |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import re | 10 import re |
11 import sdk_update | 11 import sdk_update |
12 import string | 12 import string |
13 import subprocess | 13 import subprocess |
14 import sys | 14 import sys |
| 15 import urllib2 |
15 | 16 |
16 HELP='''"Usage: %prog [-b bundle] [options]" | 17 HELP='''"Usage: %prog [-b bundle] [options]" |
17 | 18 |
18 Actions for particular bundles: | 19 Actions for particular bundles: |
19 sdk_tools: Upload the most recently built nacl_sdk.zip and sdk_tools.tgz | 20 sdk_tools: Upload the most recently built nacl_sdk.zip and sdk_tools.tgz |
20 files to the server and update the manifest file | 21 files to the server and update the manifest file |
21 pepper_??: Download the latest pepper builds off the appropriate branch, | 22 pepper_??: Download the latest pepper builds off the appropriate branch, |
22 upload these files to the appropriate location on the server, and | 23 upload these files to the appropriate location on the server, and |
23 update the manifest file. | 24 update the manifest file. |
24 <others>: Only update manifest file -- you'll need to upload the file yourself | 25 <others>: Only update manifest file -- you'll need to upload the file yourself |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 if options.manifest_version is not None: | 158 if options.manifest_version is not None: |
158 self._UpdateManifestVersion(options) | 159 self._UpdateManifestVersion(options) |
159 # Keep a copy of bundle_name, which will be consumed by UpdateBundle, for | 160 # Keep a copy of bundle_name, which will be consumed by UpdateBundle, for |
160 # use in _VerifyAllOptionsConsumed below. | 161 # use in _VerifyAllOptionsConsumed below. |
161 bundle_name = options.bundle_name | 162 bundle_name = options.bundle_name |
162 if bundle_name is not None: | 163 if bundle_name is not None: |
163 self._UpdateBundle(options) | 164 self._UpdateBundle(options) |
164 self._VerifyAllOptionsConsumed(options, bundle_name) | 165 self._VerifyAllOptionsConsumed(options, bundle_name) |
165 self._ValidateManifest() | 166 self._ValidateManifest() |
166 | 167 |
| 168 def ValidateManifestLinks(self): |
| 169 '''Validates all the links in the manifest file and throws if one is bad''' |
| 170 valid = True |
| 171 for bundle in self._manifest_data[sdk_update.BUNDLES_KEY]: |
| 172 for archive in bundle.GetArchives(): |
| 173 stream = None |
| 174 try: |
| 175 print "Checking size of data at link: %s" % archive.GetUrl() |
| 176 stream = urllib2.urlopen(archive.GetUrl()) |
| 177 server_size = int(stream.info()[sdk_update.HTTP_CONTENT_LENGTH]) |
| 178 if server_size != archive.GetSize(): |
| 179 sys.stderr.write('Size mismatch for %s. Expected %s but got %s\n' % |
| 180 (archive.GetUrl(), archive.GetSize(), server_size)) |
| 181 sys.stderr.flush() |
| 182 valid = False |
| 183 finally: |
| 184 if stream: |
| 185 stream.close() |
| 186 if not valid: |
| 187 raise Error('Files on server do not match the manifest file') |
| 188 |
167 | 189 |
168 class GsUtil(object): | 190 class GsUtil(object): |
169 def __init__(self, gsutil): | 191 def __init__(self, gsutil): |
170 '''gsutil is the path to the gsutil executable''' | 192 '''gsutil is the path to the gsutil executable''' |
171 self.gsutil = gsutil | 193 self.gsutil = gsutil |
172 self.root = 'gs://nativeclient-mirror/nacl/nacl_sdk' | 194 self.root = 'gs://nativeclient-mirror/nacl/nacl_sdk' |
173 | 195 |
174 def GetURI(self, path): | 196 def GetURI(self, path): |
175 '''Return the full gs:// URI for a given relative path''' | 197 '''Return the full gs:// URI for a given relative path''' |
176 return '/'.join([self.root, path]) | 198 return '/'.join([self.root, path]) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 if it doesn't already exists. Raises an Error if the manifest doesn't | 326 if it doesn't already exists. Raises an Error if the manifest doesn't |
305 validate after updating. | 327 validate after updating. |
306 | 328 |
307 Args: | 329 Args: |
308 options: option data''' | 330 options: option data''' |
309 # UpdateManifest does not know how to deal with file-related options | 331 # UpdateManifest does not know how to deal with file-related options |
310 self._manifest.UpdateManifest(self.options) | 332 self._manifest.UpdateManifest(self.options) |
311 self.WriteFile() | 333 self.WriteFile() |
312 | 334 |
313 | 335 |
| 336 def CommandPush(options, args, manifest_file): |
| 337 '''Check the manifest file and push it to the server if it's okay''' |
| 338 print 'Running Push with options=%s and args=%s' % (options, args) |
| 339 manifest = manifest_file._manifest |
| 340 manifest.UpdateManifest(options) |
| 341 print 'Validating links within manifest file' |
| 342 manifest.ValidateManifestLinks() |
| 343 print 'Copying manifest file to server' |
| 344 manifest_file.gsutil.Copy(options.manifest_file, 'naclsdk_manifest.json') |
| 345 |
| 346 |
314 def main(argv): | 347 def main(argv): |
315 '''Main entry for update_manifest.py''' | 348 '''Main entry for update_manifest.py''' |
316 | 349 |
317 buildtools_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 350 buildtools_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
318 parser = optparse.OptionParser(usage=HELP) | 351 parser = optparse.OptionParser(usage=HELP) |
319 | 352 |
320 # Setup options | 353 # Setup options |
321 parser.add_option( | 354 parser.add_option( |
322 '-a', '--archive-id', dest='archive_id', | 355 '-a', '--archive-id', dest='archive_id', |
323 default=None, | 356 default=None, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 default=None, | 421 default=None, |
389 help='Required for new manifest files: ' | 422 help='Required for new manifest files: ' |
390 'Version number for the manifest.') | 423 'Version number for the manifest.') |
391 parser.add_option( | 424 parser.add_option( |
392 '-W', '--win-archive', dest='win_arch_url', | 425 '-W', '--win-archive', dest='win_arch_url', |
393 default=None, | 426 default=None, |
394 help='URL for the Windows archive.') | 427 help='URL for the Windows archive.') |
395 | 428 |
396 # Parse options and arguments and check. | 429 # Parse options and arguments and check. |
397 (options, args) = parser.parse_args(argv) | 430 (options, args) = parser.parse_args(argv) |
398 if len(args) > 0: | 431 manifest_file = UpdateSDKManifestFile(options) |
399 parser.error('These arguments were not understood: %s' % args) | 432 if len(args) == 0: |
| 433 manifest_file.HandleBundles() |
| 434 manifest_file.UpdateWithOptions() |
| 435 return 0 |
400 | 436 |
401 manifest_file = UpdateSDKManifestFile(options) | 437 COMMANDS = { |
402 manifest_file.HandleBundles() | 438 'push': CommandPush |
403 manifest_file.UpdateWithOptions() | 439 } |
404 | 440 def CommandUnknown(options, args, manifest_file): |
| 441 raise Error("Unknown command %s" % args[0]) |
| 442 try: |
| 443 COMMANDS.get(args[0], CommandUnknown)(options, args, manifest_file) |
| 444 except Error as error: |
| 445 print "Error: %s" % error |
| 446 return 1 |
405 return 0 | 447 return 0 |
406 | 448 |
407 | 449 |
408 if __name__ == '__main__': | 450 if __name__ == '__main__': |
409 sys.exit(main(sys.argv[1:])) | 451 sys.exit(main(sys.argv[1:])) |
OLD | NEW |