| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Native Client Authors. All rights reserved. | 2 # Copyright 2015 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 """Scan online pkg packages and download all files | 5 """Scan online pkg packages and download all files |
| 6 | 6 |
| 7 This script is intended to be run periodically and is called | 7 This script is intended to be run periodically and is called |
| 8 by build_repo.sh script to build repository. | 8 by build_repo.sh script to build repository. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 files_to_download = [] | 41 files_to_download = [] |
| 42 filenames = [] | 42 filenames = [] |
| 43 download_dir = os.path.join(naclports.package_index.PREBUILT_ROOT, | 43 download_dir = os.path.join(naclports.package_index.PREBUILT_ROOT, |
| 44 'pkg', pkg_dir) | 44 'pkg', pkg_dir) |
| 45 if not os.path.exists(download_dir): | 45 if not os.path.exists(download_dir): |
| 46 os.makedirs(download_dir) | 46 os.makedirs(download_dir) |
| 47 | 47 |
| 48 for file_info in files: | 48 for file_info in files: |
| 49 basename = os.path.basename(file_info.url) | 49 basename = os.path.basename(file_info.url) |
| 50 file_info.name = os.path.join(download_dir, basename) | 50 file_info.name = os.path.join(download_dir, basename) |
| 51 file_info.rel_name = file_info.name[len(naclports.paths.NACLPORTS_ROOT)+1:] |
| 51 filenames.append((file_info.name, file_info.url)) | 52 filenames.append((file_info.name, file_info.url)) |
| 52 if os.path.exists(file_info.name): | 53 if os.path.exists(file_info.name): |
| 53 if not check_hashes or CheckHash(file_info.name, file_info.md5): | 54 if not check_hashes or CheckHash(file_info.name, file_info.md5): |
| 54 Log('Up-to-date: %s' % file_info.name) | 55 Log('Up-to-date: %s' % file_info.rel_name) |
| 55 continue | 56 continue |
| 56 files_to_download.append(file_info) | 57 files_to_download.append(file_info) |
| 57 | 58 |
| 58 def Check(file_info): | 59 def Check(file_info): |
| 59 if check_hashes and not CheckHash(file_info.name, file_info.md5): | 60 if check_hashes and not CheckHash(file_info.name, file_info.md5): |
| 60 raise naclports.Error( | 61 raise naclports.Error( |
| 61 'Checksum failed: %s\nExpected=%s\nActual=%s' % | 62 'Checksum failed: %s\nExpected=%s\nActual=%s' % |
| 62 (file_info.name, file_info.md5, GetHash(file_info.name))) | 63 (file_info.rel_name, file_info.md5, GetHash(file_info.name))) |
| 63 | 64 |
| 64 if not files_to_download: | 65 if not files_to_download: |
| 65 Log('All files up-to-date') | 66 Log('All files up-to-date') |
| 66 else: | 67 else: |
| 67 total_size = sum(f.size for f in files_to_download) | 68 total_size = sum(f.size for f in files_to_download) |
| 68 Log('Need to download %d/%d files [%s]' % | 69 Log('Need to download %d/%d files [%s]' % |
| 69 (len(files_to_download), len(files), FormatSize(total_size))) | 70 (len(files_to_download), len(files), FormatSize(total_size))) |
| 70 | 71 |
| 71 gsutil = FindGsutil() | 72 gsutil = FindGsutil() |
| 72 if parallel: | 73 if parallel: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 DownloadFiles(pkg, all_files, not args.skip_md5, args.parallel) | 144 DownloadFiles(pkg, all_files, not args.skip_md5, args.parallel) |
| 144 Log('Done') | 145 Log('Done') |
| 145 return 0 | 146 return 0 |
| 146 | 147 |
| 147 if __name__ == '__main__': | 148 if __name__ == '__main__': |
| 148 try: | 149 try: |
| 149 sys.exit(main(sys.argv[1:])) | 150 sys.exit(main(sys.argv[1:])) |
| 150 except naclports.Error as e: | 151 except naclports.Error as e: |
| 151 sys.stderr.write('%s\n' % e) | 152 sys.stderr.write('%s\n' % e) |
| 152 sys.exit(-1) | 153 sys.exit(-1) |
| OLD | NEW |