OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 if options.manifest_version is not None: | 157 if options.manifest_version is not None: |
157 self._UpdateManifestVersion(options) | 158 self._UpdateManifestVersion(options) |
158 # Keep a copy of bundle_name, which will be consumed by UpdateBundle, for | 159 # Keep a copy of bundle_name, which will be consumed by UpdateBundle, for |
159 # use in _VerifyAllOptionsConsumed below. | 160 # use in _VerifyAllOptionsConsumed below. |
160 bundle_name = options.bundle_name | 161 bundle_name = options.bundle_name |
161 if bundle_name is not None: | 162 if bundle_name is not None: |
162 self._UpdateBundle(options) | 163 self._UpdateBundle(options) |
163 self._VerifyAllOptionsConsumed(options, bundle_name) | 164 self._VerifyAllOptionsConsumed(options, bundle_name) |
164 self._ValidateManifest() | 165 self._ValidateManifest() |
165 | 166 |
| 167 def ValidateManifestLinks(self): |
| 168 '''Validates all the links in the manifest file and throws if one is bad''' |
| 169 valid = True |
| 170 for bundle in self._manifest_data[sdk_update.BUNDLES_KEY]: |
| 171 for archive in bundle.GetArchives(): |
| 172 stream = None |
| 173 try: |
| 174 print "Checking size of data at link: %s" % archive.GetUrl() |
| 175 stream = urllib2.urlopen(archive.GetUrl()) |
| 176 server_size = int(stream.info()[sdk_update.HTTP_CONTENT_LENGTH]) |
| 177 if server_size != archive.GetSize(): |
| 178 sys.stderr.write('Size mismatch for %s. Expected %s but got %s\n' % |
| 179 (archive.GetUrl(), archive.GetSize(), server_size)) |
| 180 sys.stderr.flush() |
| 181 valid = False |
| 182 finally: |
| 183 if stream: |
| 184 stream.close() |
| 185 if not valid: |
| 186 raise Error('Files on server do not match the manifest file') |
| 187 |
166 | 188 |
167 class GsUtil(object): | 189 class GsUtil(object): |
168 def __init__(self, gsutil): | 190 def __init__(self, gsutil): |
169 '''gsutil is the path to the gsutil executable''' | 191 '''gsutil is the path to the gsutil executable''' |
170 self.gsutil = gsutil | 192 self.gsutil = gsutil |
171 self.root = 'gs://nativeclient-mirror/nacl/nacl_sdk' | 193 self.root = 'gs://nativeclient-mirror/nacl/nacl_sdk' |
172 | 194 |
173 def GetURI(self, path): | 195 def GetURI(self, path): |
174 '''Return the full gs:// URI for a given relative path''' | 196 '''Return the full gs:// URI for a given relative path''' |
175 return '/'.join([self.root, path]) | 197 return '/'.join([self.root, path]) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 if it doesn't already exists. Raises an Error if the manifest doesn't | 316 if it doesn't already exists. Raises an Error if the manifest doesn't |
295 validate after updating. | 317 validate after updating. |
296 | 318 |
297 Args: | 319 Args: |
298 options: option data''' | 320 options: option data''' |
299 # UpdateManifest does not know how to deal with file-related options | 321 # UpdateManifest does not know how to deal with file-related options |
300 self._manifest.UpdateManifest(self.options) | 322 self._manifest.UpdateManifest(self.options) |
301 self.WriteFile() | 323 self.WriteFile() |
302 | 324 |
303 | 325 |
| 326 def CommandPush(options, args, manifest_file): |
| 327 '''Check the manifest file and push it to the server if it's okay''' |
| 328 print 'Running Push with options=%s and args=%s' % (options, args) |
| 329 manifest = manifest_file._manifest |
| 330 manifest.UpdateManifest(options) |
| 331 print 'Validating links within manifest file' |
| 332 manifest.ValidateManifestLinks() |
| 333 print 'Copying manifest file to server' |
| 334 manifest_file.gsutil.Copy(options.manifest_file, 'naclsdk_manifest.json') |
| 335 |
| 336 |
304 def main(argv): | 337 def main(argv): |
305 '''Main entry for update_manifest.py''' | 338 '''Main entry for update_manifest.py''' |
306 | 339 |
307 buildtools_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 340 buildtools_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
308 parser = optparse.OptionParser(usage=HELP) | 341 parser = optparse.OptionParser(usage=HELP) |
309 | 342 |
310 # Setup options | 343 # Setup options |
311 parser.add_option( | 344 parser.add_option( |
312 '-b', '--bundle-version', dest='bundle_version', | 345 '-b', '--bundle-version', dest='bundle_version', |
313 type='int', | 346 type='int', |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 default=None, | 404 default=None, |
372 help='Required for new manifest files: ' | 405 help='Required for new manifest files: ' |
373 'Version number for the manifest.') | 406 'Version number for the manifest.') |
374 parser.add_option( | 407 parser.add_option( |
375 '-W', '--win-archive', dest='win_arch_url', | 408 '-W', '--win-archive', dest='win_arch_url', |
376 default=None, | 409 default=None, |
377 help='URL for the Windows archive.') | 410 help='URL for the Windows archive.') |
378 | 411 |
379 # Parse options and arguments and check. | 412 # Parse options and arguments and check. |
380 (options, args) = parser.parse_args(argv) | 413 (options, args) = parser.parse_args(argv) |
381 if len(args) > 0: | 414 manifest_file = UpdateSDKManifestFile(options) |
382 parser.error('These arguments were not understood: %s' % args) | 415 if len(args) == 0: |
| 416 manifest_file.HandleBundles() |
| 417 manifest_file.UpdateWithOptions() |
| 418 return 0 |
383 | 419 |
384 manifest_file = UpdateSDKManifestFile(options) | 420 COMMANDS = { |
385 manifest_file.HandleBundles() | 421 'push': CommandPush |
386 manifest_file.UpdateWithOptions() | 422 } |
387 | 423 def CommandUnknown(options, args, manifest_file): |
| 424 raise Error("Unknown command %s" % args[0]) |
| 425 try: |
| 426 COMMANDS.get(args[0], CommandUnknown)(options, args, manifest_file) |
| 427 except Error as error: |
| 428 print "Error: %s" % error |
| 429 return 1 |
388 return 0 | 430 return 0 |
389 | 431 |
390 if __name__ == '__main__': | 432 if __name__ == '__main__': |
391 sys.exit(main(sys.argv[1:])) | 433 sys.exit(main(sys.argv[1:])) |
OLD | NEW |