diff options
author | mball@google.com <mball@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 23:23:03 +0000 |
---|---|---|
committer | mball@google.com <mball@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 23:23:03 +0000 |
commit | fad7db01be0bc8cf30027f9815d1ce933dd972e9 (patch) | |
tree | 8f719d8fc0f20f8fa09f54a2fa54058a1f5043f5 /native_client_sdk/src/build_tools | |
parent | 1c55814d24b7fd47eea38de4a5bc651dec0b9c66 (diff) | |
download | chromium_src-fad7db01be0bc8cf30027f9815d1ce933dd972e9.zip chromium_src-fad7db01be0bc8cf30027f9815d1ce933dd972e9.tar.gz chromium_src-fad7db01be0bc8cf30027f9815d1ce933dd972e9.tar.bz2 |
Merged in other half of NaCl SDK's r1387 change to update_manifest.py
original CL:
Updated update_manifest.py to push manifest files to server
http://codereview.chromium.org/8566045 (r1387, not this CL)
BUG=None
TEST=None
TBR=bradnelson
Review URL: http://codereview.chromium.org/8889029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113883 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk/src/build_tools')
3 files changed, 71 insertions, 7 deletions
diff --git a/native_client_sdk/src/build_tools/sdk_tools/sdk_update.py b/native_client_sdk/src/build_tools/sdk_tools/sdk_update.py index 297de9c..c57a14c 100755 --- a/native_client_sdk/src/build_tools/sdk_tools/sdk_update.py +++ b/native_client_sdk/src/build_tools/sdk_tools/sdk_update.py @@ -27,7 +27,7 @@ import urlparse # Bump the MINOR_REV every time you check this file in. MAJOR_REV = 1 -MINOR_REV = 12 +MINOR_REV = 13 GLOBAL_HELP = '''Usage: naclsdk [options] command [command_options] @@ -476,6 +476,18 @@ class Archive(dict): self['size'] = size self['checksum'] = {'sha1': sha1} + def GetUrl(self): + '''Returns the URL of this Archive''' + return self['url'] + + def GetSize(self): + '''Returns the size of this archive, in bytes''' + return int(self['size']) + + def GetChecksum(self, type='sha1'): + '''Returns a given cryptographic checksum of the archive''' + return self['checksum'][type] + class Bundle(dict): ''' A placeholder for sdk bundle information. We derive Bundle from @@ -582,6 +594,10 @@ class Bundle(dict): self[ARCHIVES_KEY].append(archive) archive.Update(url) + def GetArchives(self): + '''Returns all the archives in this bundle''' + return self[ARCHIVES_KEY] + class SDKManifest(object): '''This class contains utilities for manipulation an SDK manifest string diff --git a/native_client_sdk/src/build_tools/sdk_tools/update_manifest.py b/native_client_sdk/src/build_tools/sdk_tools/update_manifest.py index 0929688..8628dc0 100755 --- a/native_client_sdk/src/build_tools/sdk_tools/update_manifest.py +++ b/native_client_sdk/src/build_tools/sdk_tools/update_manifest.py @@ -12,6 +12,7 @@ import sdk_update import string import subprocess import sys +import urllib2 HELP='''"Usage: %prog [-b bundle] [options]" @@ -164,6 +165,27 @@ class UpdateSDKManifest(sdk_update.SDKManifest): self._VerifyAllOptionsConsumed(options, bundle_name) self._ValidateManifest() + def ValidateManifestLinks(self): + '''Validates all the links in the manifest file and throws if one is bad''' + valid = True + for bundle in self._manifest_data[sdk_update.BUNDLES_KEY]: + for archive in bundle.GetArchives(): + stream = None + try: + print "Checking size of data at link: %s" % archive.GetUrl() + stream = urllib2.urlopen(archive.GetUrl()) + server_size = int(stream.info()[sdk_update.HTTP_CONTENT_LENGTH]) + if server_size != archive.GetSize(): + sys.stderr.write('Size mismatch for %s. Expected %s but got %s\n' % + (archive.GetUrl(), archive.GetSize(), server_size)) + sys.stderr.flush() + valid = False + finally: + if stream: + stream.close() + if not valid: + raise Error('Files on server do not match the manifest file') + class GsUtil(object): def __init__(self, gsutil): @@ -311,6 +333,17 @@ class UpdateSDKManifestFile(sdk_update.SDKManifestFile): self.WriteFile() +def CommandPush(options, args, manifest_file): + '''Check the manifest file and push it to the server if it's okay''' + print 'Running Push with options=%s and args=%s' % (options, args) + manifest = manifest_file._manifest + manifest.UpdateManifest(options) + print 'Validating links within manifest file' + manifest.ValidateManifestLinks() + print 'Copying manifest file to server' + manifest_file.gsutil.Copy(options.manifest_file, 'naclsdk_manifest.json') + + def main(argv): '''Main entry for update_manifest.py''' @@ -395,13 +428,22 @@ def main(argv): # Parse options and arguments and check. (options, args) = parser.parse_args(argv) - if len(args) > 0: - parser.error('These arguments were not understood: %s' % args) - manifest_file = UpdateSDKManifestFile(options) - manifest_file.HandleBundles() - manifest_file.UpdateWithOptions() - + if len(args) == 0: + manifest_file.HandleBundles() + manifest_file.UpdateWithOptions() + return 0 + + COMMANDS = { + 'push': CommandPush + } + def CommandUnknown(options, args, manifest_file): + raise Error("Unknown command %s" % args[0]) + try: + COMMANDS.get(args[0], CommandUnknown)(options, args, manifest_file) + except Error as error: + print "Error: %s" % error + return 1 return 0 diff --git a/native_client_sdk/src/build_tools/tests/update_manifest_test.py b/native_client_sdk/src/build_tools/tests/update_manifest_test.py index 0e33207..529e38c 100755 --- a/native_client_sdk/src/build_tools/tests/update_manifest_test.py +++ b/native_client_sdk/src/build_tools/tests/update_manifest_test.py @@ -295,6 +295,12 @@ class TestUpdateManifest(unittest.TestCase): finally: RemoveFile(temp_filename) + def testPush(self): + '''Test whether the push function does the right thing''' + options = FakeOptions() + argv = ['-g', options.gsutil, 'push'] + update_manifest.main(argv) + def testHandleSDKTools(self): '''Test the handling of the sdk_tools bundle''' options = FakeOptions() |