| 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 '''A simple tool to update the Native Client SDK to the latest version''' | 6 '''A simple tool to update the Native Client SDK to the latest version''' |
| 7 | 7 |
| 8 import cStringIO | 8 import cStringIO |
| 9 import errno | 9 import errno |
| 10 import exceptions | 10 import exceptions |
| 11 import hashlib | 11 import hashlib |
| 12 import json | 12 import json |
| 13 import optparse | 13 import optparse |
| 14 import os | 14 import os |
| 15 import shutil | 15 import shutil |
| 16 import subprocess | 16 import subprocess |
| 17 import sys | 17 import sys |
| 18 import tarfile | 18 import tarfile |
| 19 import tempfile | 19 import tempfile |
| 20 import time | 20 import time |
| 21 import urllib2 | 21 import urllib2 |
| 22 import urlparse | 22 import urlparse |
| 23 | 23 |
| 24 | 24 |
| 25 #------------------------------------------------------------------------------ | 25 #------------------------------------------------------------------------------ |
| 26 # Constants | 26 # Constants |
| 27 | 27 |
| 28 # Bump the MINOR_REV every time you check this file in. | 28 # Bump the MINOR_REV every time you check this file in. |
| 29 MAJOR_REV = 1 | 29 MAJOR_REV = 1 |
| 30 MINOR_REV = 12 | 30 MINOR_REV = 13 |
| 31 | 31 |
| 32 GLOBAL_HELP = '''Usage: naclsdk [options] command [command_options] | 32 GLOBAL_HELP = '''Usage: naclsdk [options] command [command_options] |
| 33 | 33 |
| 34 naclsdk is a simple utility that updates the Native Client (NaCl) | 34 naclsdk is a simple utility that updates the Native Client (NaCl) |
| 35 Software Developer's Kit (SDK). Each component is kept as a 'bundle' that | 35 Software Developer's Kit (SDK). Each component is kept as a 'bundle' that |
| 36 this utility can download as as subdirectory into the SDK. | 36 this utility can download as as subdirectory into the SDK. |
| 37 | 37 |
| 38 Commands: | 38 Commands: |
| 39 help [command] - Get either general or command-specific help | 39 help [command] - Get either general or command-specific help |
| 40 list - Lists the available bundles | 40 list - Lists the available bundles |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 469 |
| 470 def Update(self, url): | 470 def Update(self, url): |
| 471 ''' Update the archive with the new url. Automatically update the | 471 ''' Update the archive with the new url. Automatically update the |
| 472 archive's size and checksum fields. Raises an Error if the url is | 472 archive's size and checksum fields. Raises an Error if the url is |
| 473 is invalid. ''' | 473 is invalid. ''' |
| 474 self['url'] = url | 474 self['url'] = url |
| 475 sha1, size = self.ComputeSha1AndSize() | 475 sha1, size = self.ComputeSha1AndSize() |
| 476 self['size'] = size | 476 self['size'] = size |
| 477 self['checksum'] = {'sha1': sha1} | 477 self['checksum'] = {'sha1': sha1} |
| 478 | 478 |
| 479 def GetUrl(self): |
| 480 '''Returns the URL of this Archive''' |
| 481 return self['url'] |
| 482 |
| 483 def GetSize(self): |
| 484 '''Returns the size of this archive, in bytes''' |
| 485 return int(self['size']) |
| 486 |
| 487 def GetChecksum(self, type='sha1'): |
| 488 '''Returns a given cryptographic checksum of the archive''' |
| 489 return self['checksum'][type] |
| 490 |
| 479 | 491 |
| 480 class Bundle(dict): | 492 class Bundle(dict): |
| 481 ''' A placeholder for sdk bundle information. We derive Bundle from | 493 ''' A placeholder for sdk bundle information. We derive Bundle from |
| 482 dict so that it is easily serializable.''' | 494 dict so that it is easily serializable.''' |
| 483 def __init__(self, obj): | 495 def __init__(self, obj): |
| 484 ''' Create a new bundle with the given bundle name.''' | 496 ''' Create a new bundle with the given bundle name.''' |
| 485 if isinstance(obj, str) or isinstance(obj, unicode): | 497 if isinstance(obj, str) or isinstance(obj, unicode): |
| 486 dict.__init__(self, [(ARCHIVES_KEY, []), (NAME_KEY, obj)]) | 498 dict.__init__(self, [(ARCHIVES_KEY, []), (NAME_KEY, obj)]) |
| 487 else: | 499 else: |
| 488 dict.__init__(self, obj) | 500 dict.__init__(self, obj) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 | 587 |
| 576 Args: | 588 Args: |
| 577 host_os: name of host os whose archive must be updated or created. | 589 host_os: name of host os whose archive must be updated or created. |
| 578 url: the new url for the archive.''' | 590 url: the new url for the archive.''' |
| 579 archive = self.GetArchive(host_os) | 591 archive = self.GetArchive(host_os) |
| 580 if not archive: | 592 if not archive: |
| 581 archive = Archive(host_os_name=host_os) | 593 archive = Archive(host_os_name=host_os) |
| 582 self[ARCHIVES_KEY].append(archive) | 594 self[ARCHIVES_KEY].append(archive) |
| 583 archive.Update(url) | 595 archive.Update(url) |
| 584 | 596 |
| 597 def GetArchives(self): |
| 598 '''Returns all the archives in this bundle''' |
| 599 return self[ARCHIVES_KEY] |
| 600 |
| 585 | 601 |
| 586 class SDKManifest(object): | 602 class SDKManifest(object): |
| 587 '''This class contains utilities for manipulation an SDK manifest string | 603 '''This class contains utilities for manipulation an SDK manifest string |
| 588 | 604 |
| 589 For ease of unit-testing, this class should not contain any file I/O. | 605 For ease of unit-testing, this class should not contain any file I/O. |
| 590 ''' | 606 ''' |
| 591 | 607 |
| 592 def __init__(self): | 608 def __init__(self): |
| 593 '''Create a new SDKManifest object with default contents''' | 609 '''Create a new SDKManifest object with default contents''' |
| 594 self.MANIFEST_VERSION = 1 | 610 self.MANIFEST_VERSION = 1 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 | 1042 |
| 1027 return 0 # Success | 1043 return 0 # Success |
| 1028 | 1044 |
| 1029 | 1045 |
| 1030 if __name__ == '__main__': | 1046 if __name__ == '__main__': |
| 1031 try: | 1047 try: |
| 1032 sys.exit(main(sys.argv[1:])) | 1048 sys.exit(main(sys.argv[1:])) |
| 1033 except Error as error: | 1049 except Error as error: |
| 1034 print "Error: %s" % error | 1050 print "Error: %s" % error |
| 1035 sys.exit(1) | 1051 sys.exit(1) |
| OLD | NEW |