OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium 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 cygtar | 9 import cygtar |
10 import json | 10 import json |
(...skipping 30 matching lines...) Expand all Loading... |
41 sources - Manage external package sources | 41 sources - Manage external package sources |
42 | 42 |
43 Example Usage: | 43 Example Usage: |
44 naclsdk info pepper_canary | 44 naclsdk info pepper_canary |
45 naclsdk list | 45 naclsdk list |
46 naclsdk update --force pepper_17 | 46 naclsdk update --force pepper_17 |
47 naclsdk install recommended | 47 naclsdk install recommended |
48 naclsdk help update | 48 naclsdk help update |
49 naclsdk sources --list''' | 49 naclsdk sources --list''' |
50 | 50 |
51 CONFIG_FILENAME='naclsdk_config.json' | 51 CONFIG_FILENAME = 'naclsdk_config.json' |
52 MANIFEST_FILENAME='naclsdk_manifest2.json' | 52 MANIFEST_FILENAME = 'naclsdk_manifest2.json' |
53 SDK_TOOLS='sdk_tools' # the name for this tools directory | 53 SDK_TOOLS = 'sdk_tools' # the name for this tools directory |
54 USER_DATA_DIR='sdk_cache' | 54 USER_DATA_DIR = 'sdk_cache' |
55 | 55 |
56 HTTP_CONTENT_LENGTH = 'Content-Length' # HTTP Header field for content length | 56 HTTP_CONTENT_LENGTH = 'Content-Length' # HTTP Header field for content length |
57 | 57 |
58 | 58 |
59 #------------------------------------------------------------------------------ | 59 #------------------------------------------------------------------------------ |
60 # General Utilities | 60 # General Utilities |
61 | 61 |
62 | 62 |
63 _debug_mode = False | 63 _debug_mode = False |
64 _quiet_mode = False | 64 _quiet_mode = False |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 # If the installer has extension 'exe', assume it's a Windows NSIS-style | 127 # If the installer has extension 'exe', assume it's a Windows NSIS-style |
128 # installer that handles silent (/S) and relocated (/D) installs. | 128 # installer that handles silent (/S) and relocated (/D) installs. |
129 command = [installer, '/S', '/D=%s' % outdir] | 129 command = [installer, '/S', '/D=%s' % outdir] |
130 subprocess.check_call(command) | 130 subprocess.check_call(command) |
131 else: | 131 else: |
132 os.mkdir(outdir) | 132 os.mkdir(outdir) |
133 tar_file = None | 133 tar_file = None |
134 curpath = os.getcwd() | 134 curpath = os.getcwd() |
135 try: | 135 try: |
136 tar_file = cygtar.CygTar(installer, 'r', verbose=True) | 136 tar_file = cygtar.CygTar(installer, 'r', verbose=True) |
137 if outdir: os.chdir(outdir) | 137 if outdir: |
| 138 os.chdir(outdir) |
138 tar_file.Extract() | 139 tar_file.Extract() |
139 finally: | 140 finally: |
140 if tar_file: | 141 if tar_file: |
141 tar_file.Close() | 142 tar_file.Close() |
142 os.chdir(curpath) | 143 os.chdir(curpath) |
143 | 144 |
144 | 145 |
145 class ProgressFunction(object): | 146 class ProgressFunction(object): |
146 '''Create a progress function for a file with a given size''' | 147 '''Create a progress function for a file with a given size''' |
147 | 148 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 InfoPrint('Downloading %s' % archive.url) | 196 InfoPrint('Downloading %s' % archive.url) |
196 sha1, size = manifest_util.DownloadAndComputeHash( | 197 sha1, size = manifest_util.DownloadAndComputeHash( |
197 from_stream, | 198 from_stream, |
198 to_stream=to_stream, | 199 to_stream=to_stream, |
199 progress_func=progress_function) | 200 progress_func=progress_function) |
200 if size != content_length: | 201 if size != content_length: |
201 raise Error('Download size mismatch for %s.\n' | 202 raise Error('Download size mismatch for %s.\n' |
202 'Expected %s bytes but got %s' % | 203 'Expected %s bytes but got %s' % |
203 (archive.url, content_length, size)) | 204 (archive.url, content_length, size)) |
204 finally: | 205 finally: |
205 if from_stream: from_stream.close() | 206 if from_stream: |
| 207 from_stream.close() |
206 return sha1, size | 208 return sha1, size |
207 | 209 |
208 | 210 |
209 def LoadFromFile(path, obj): | 211 def LoadFromFile(path, obj): |
210 '''Returns a manifest loaded from the JSON file at |path|. | 212 '''Returns a manifest loaded from the JSON file at |path|. |
211 | 213 |
212 If the path does not exist or is invalid, returns unmodified object.''' | 214 If the path does not exist or is invalid, returns unmodified object.''' |
213 methodlist = [m for m in dir(obj) if callable(getattr(obj, m))] | 215 methodlist = [m for m in dir(obj) if callable(getattr(obj, m))] |
214 if 'LoadDataFromString' not in methodlist: | 216 if 'LoadDataFromString' not in methodlist: |
215 return obj | 217 return obj |
(...skipping 12 matching lines...) Expand all Loading... |
228 def LoadManifestFromURLs(urls): | 230 def LoadManifestFromURLs(urls): |
229 '''Returns a manifest loaded from |urls|, merged into one manifest.''' | 231 '''Returns a manifest loaded from |urls|, merged into one manifest.''' |
230 manifest = manifest_util.SDKManifest() | 232 manifest = manifest_util.SDKManifest() |
231 for url in urls: | 233 for url in urls: |
232 try: | 234 try: |
233 url_stream = UrlOpen(url) | 235 url_stream = UrlOpen(url) |
234 except urllib2.URLError as e: | 236 except urllib2.URLError as e: |
235 raise Error('Unable to open %s. [%s]' % (url, e)) | 237 raise Error('Unable to open %s. [%s]' % (url, e)) |
236 | 238 |
237 manifest_stream = cStringIO.StringIO() | 239 manifest_stream = cStringIO.StringIO() |
238 sha1, size = manifest_util.DownloadAndComputeHash(url_stream, | 240 manifest_util.DownloadAndComputeHash(url_stream, manifest_stream) |
239 manifest_stream) | |
240 temp_manifest = manifest_util.SDKManifest() | 241 temp_manifest = manifest_util.SDKManifest() |
241 temp_manifest.LoadDataFromString(manifest_stream.getvalue()) | 242 temp_manifest.LoadDataFromString(manifest_stream.getvalue()) |
242 | 243 |
243 manifest.MergeManifest(temp_manifest) | 244 manifest.MergeManifest(temp_manifest) |
244 | 245 |
245 def BundleFilter(bundle): | 246 def BundleFilter(bundle): |
246 # Only add this bundle if it's supported on this platform. | 247 # Only add this bundle if it's supported on this platform. |
247 return bundle.GetHostOSArchive() | 248 return bundle.GetHostOSArchive() |
248 | 249 |
249 manifest.FilterBundles(BundleFilter) | 250 manifest.FilterBundles(BundleFilter) |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 write manifest to disk. Use locks. | 485 write manifest to disk. Use locks. |
485 else: | 486 else: |
486 InfoPrint('bundle is up-to-date') | 487 InfoPrint('bundle is up-to-date') |
487 | 488 |
488 Targets: | 489 Targets: |
489 recommended: (default) Install/Update all recommended components | 490 recommended: (default) Install/Update all recommended components |
490 all: Install/Update all available components | 491 all: Install/Update all available components |
491 bundle_name: Install/Update only the given bundle | 492 bundle_name: Install/Update only the given bundle |
492 ''' | 493 ''' |
493 DebugPrint("Running Update command with: %s, %s" % (options, argv)) | 494 DebugPrint("Running Update command with: %s, %s" % (options, argv)) |
494 ALL='all' # Update all bundles | 495 ALL = 'all' # Update all bundles |
495 RECOMMENDED='recommended' # Only update the bundles with recommended=yes | 496 RECOMMENDED = 'recommended' # Only update the bundles with recommended=yes |
496 | 497 |
497 parser = optparse.OptionParser(usage=Update.__doc__) | 498 parser = optparse.OptionParser(usage=Update.__doc__) |
498 parser.add_option( | 499 parser.add_option( |
499 '-F', '--force', dest='force', | 500 '-F', '--force', dest='force', |
500 default=False, action='store_true', | 501 default=False, action='store_true', |
501 help='Force updating existing components that already exist') | 502 help='Force updating existing components that already exist') |
502 (update_options, args) = parser.parse_args(argv) | 503 (update_options, args) = parser.parse_args(argv) |
503 | 504 |
504 if len(args) == 0: | 505 if len(args) == 0: |
505 args = [RECOMMENDED] | 506 args = [RECOMMENDED] |
(...skipping 23 matching lines...) Expand all Loading... |
529 'Ignoring manual update request.') | 530 'Ignoring manual update request.') |
530 continue | 531 continue |
531 | 532 |
532 if not (bundle.name in args or | 533 if not (bundle.name in args or |
533 ALL in args or (RECOMMENDED in args and | 534 ALL in args or (RECOMMENDED in args and |
534 bundle[RECOMMENDED] == 'yes')): | 535 bundle[RECOMMENDED] == 'yes')): |
535 continue | 536 continue |
536 def UpdateBundle(): | 537 def UpdateBundle(): |
537 '''Helper to install a bundle''' | 538 '''Helper to install a bundle''' |
538 archive = bundle.GetHostOSArchive() | 539 archive = bundle.GetHostOSArchive() |
539 (scheme, host, path, _, _, _) = urlparse.urlparse(archive['url']) | 540 (_, _, path, _, _, _) = urlparse.urlparse(archive['url']) |
540 dest_filename = os.path.join(options.user_data_dir, path.split('/')[-1]) | 541 dest_filename = os.path.join(options.user_data_dir, path.split('/')[-1]) |
541 sha1, size = DownloadArchiveToFile(archive, dest_filename) | 542 sha1, size = DownloadArchiveToFile(archive, dest_filename) |
542 if sha1 != archive.GetChecksum(): | 543 if sha1 != archive.GetChecksum(): |
543 raise Error("SHA1 checksum mismatch on '%s'. Expected %s but got %s" % | 544 raise Error("SHA1 checksum mismatch on '%s'. Expected %s but got %s" % |
544 (bundle.name, archive.GetChecksum(), sha1)) | 545 (bundle.name, archive.GetChecksum(), sha1)) |
545 if size != archive.size: | 546 if size != archive.size: |
546 raise Error("Size mismatch on Archive. Expected %s but got %s bytes" % | 547 raise Error("Size mismatch on Archive. Expected %s but got %s bytes" % |
547 (archive.size, size)) | 548 (archive.size, size)) |
548 InfoPrint('Updating bundle %s to version %s, revision %s' % ( | 549 InfoPrint('Updating bundle %s to version %s, revision %s' % ( |
549 (bundle.name, bundle.version, bundle.revision))) | 550 (bundle.name, bundle.version, bundle.revision))) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 default=None, | 592 default=None, |
592 help='Add additional package source') | 593 help='Add additional package source') |
593 parser.add_option( | 594 parser.add_option( |
594 '-r', '--remove', dest='url_to_remove', | 595 '-r', '--remove', dest='url_to_remove', |
595 default=None, | 596 default=None, |
596 help='Remove package source (use \'all\' for all additional sources)') | 597 help='Remove package source (use \'all\' for all additional sources)') |
597 parser.add_option( | 598 parser.add_option( |
598 '-l', '--list', dest='do_list', | 599 '-l', '--list', dest='do_list', |
599 default=False, action='store_true', | 600 default=False, action='store_true', |
600 help='List additional package sources') | 601 help='List additional package sources') |
601 (source_options, args) = parser.parse_args(argv) | 602 source_options, _ = parser.parse_args(argv) |
602 | 603 |
603 write_config = False | 604 write_config = False |
604 if source_options.url_to_add: | 605 if source_options.url_to_add: |
605 config.AddSource(source_options.url_to_add) | 606 config.AddSource(source_options.url_to_add) |
606 write_config = True | 607 write_config = True |
607 elif source_options.url_to_remove: | 608 elif source_options.url_to_remove: |
608 if source_options.url_to_remove == 'all': | 609 if source_options.url_to_remove == 'all': |
609 config.RemoveAllSources() | 610 config.RemoveAllSources() |
610 else: | 611 else: |
611 config.RemoveSource(source_options.url_to_remove) | 612 config.RemoveSource(source_options.url_to_remove) |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 | 747 |
747 return 0 # Success | 748 return 0 # Success |
748 | 749 |
749 | 750 |
750 if __name__ == '__main__': | 751 if __name__ == '__main__': |
751 try: | 752 try: |
752 sys.exit(main(sys.argv[1:])) | 753 sys.exit(main(sys.argv[1:])) |
753 except Error as error: | 754 except Error as error: |
754 print "Error: %s" % error | 755 print "Error: %s" % error |
755 sys.exit(1) | 756 sys.exit(1) |
OLD | NEW |