Christoffer Quist Adamsen | fb2caf8 | 2021-06-01 13:50:30 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 2 | # Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file |
| 3 | # for details. All rights reserved. Use of this source code is governed by a |
| 4 | # BSD-style license that can be found in the LICENSE file. |
| 5 | |
| 6 | # Script for downloading from x20 a dependency in the same way we use cloud |
| 7 | # storage. |
| 8 | |
| 9 | import optparse |
| 10 | import os |
| 11 | import shutil |
| 12 | import subprocess |
| 13 | import sys |
| 14 | import tarfile |
| 15 | import utils |
| 16 | |
Jeffrey van Gogh | 5dac448 | 2018-01-24 02:36:38 -0800 | [diff] [blame] | 17 | GMSCORE_DEPS = '/google/data/ro/teams/r8/deps' |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 18 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 19 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 20 | def parse_options(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 21 | return optparse.OptionParser().parse_args() |
| 22 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 23 | |
Jean-Marie Henaff | 7a64eec | 2018-05-31 15:30:35 +0200 | [diff] [blame] | 24 | def download(src, dest): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 25 | print('Downloading %s to %s' % (src, dest)) |
| 26 | shutil.copyfile(src, dest) |
| 27 | utils.unpack_archive(dest) |
| 28 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 29 | |
| 30 | def Main(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 31 | (options, args) = parse_options() |
| 32 | assert len(args) == 1 |
| 33 | sha1_file = args[0] |
| 34 | dest = sha1_file[:-5] |
| 35 | print('Ensuring %s' % dest) |
| 36 | with open(sha1_file, 'r') as input_sha: |
| 37 | sha1 = input_sha.readline() |
| 38 | if os.path.exists(dest) and utils.get_sha1(dest) == sha1: |
| 39 | print('sha1 matches, not downloading') |
| 40 | dest_dir = utils.extract_dir(dest) |
| 41 | if os.path.exists(dest_dir): |
| 42 | print('destination directory exists, no extraction') |
| 43 | else: |
| 44 | utils.unpack_archive(dest) |
| 45 | return |
| 46 | src = os.path.join(GMSCORE_DEPS, sha1) |
| 47 | if not os.path.exists(src): |
| 48 | print('File (%s) does not exist on x20' % src) |
| 49 | print('Maybe pass -Pno_internal to your gradle invocation') |
| 50 | return 42 |
| 51 | download(src, dest) |
| 52 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 53 | |
| 54 | if __name__ == '__main__': |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 55 | sys.exit(Main()) |