Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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 | |
| 17 | GMSCORE_DEPS = '/google/data/ro/teams/gmscore-size/deps' |
| 18 | |
| 19 | def parse_options(): |
| 20 | return optparse.OptionParser().parse_args() |
| 21 | |
| 22 | def extract_dir(filename): |
| 23 | return filename[0:len(filename) - len('.tar.gz')] |
| 24 | |
| 25 | def unpack_archive(filename): |
| 26 | dest_dir = extract_dir(filename) |
| 27 | if os.path.exists(dest_dir): |
| 28 | print 'Deleting existing dir %s' % dest_dir |
| 29 | shutil.rmtree(dest_dir) |
| 30 | dirname = os.path.dirname(os.path.abspath(filename)) |
| 31 | with tarfile.open(filename, 'r:gz') as tar: |
| 32 | tar.extractall(path=dirname) |
| 33 | |
| 34 | def Main(): |
| 35 | (options, args) = parse_options() |
| 36 | assert len(args) == 1 |
| 37 | sha1_file = args[0] |
| 38 | dest = sha1_file[:-5] |
| 39 | print 'Ensuring %s' % dest |
| 40 | with open(sha1_file, 'r') as input_sha: |
| 41 | sha1 = input_sha.readline() |
| 42 | if os.path.exists(dest) and utils.get_sha1(dest) == sha1: |
| 43 | print 'sha1 matches, not downloading' |
| 44 | dest_dir = extract_dir(dest) |
| 45 | if os.path.exists(dest_dir): |
| 46 | print 'destination directory exists, no extraction' |
| 47 | else: |
| 48 | unpack_archive(dest) |
| 49 | return |
| 50 | src = os.path.join(GMSCORE_DEPS, sha1) |
| 51 | if not os.path.exists(src): |
| 52 | print 'File (%s) does not exist on x20' % src |
Stephan Herhut | 79d66bd | 2017-09-20 09:18:57 +0200 | [diff] [blame] | 53 | print 'Maybe pass -Pno_internal to your gradle invocation' |
| 54 | return 42 |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 55 | print 'Downloading %s to %s' % (src, dest) |
| 56 | shutil.copyfile(src, dest) |
| 57 | unpack_archive(dest) |
| 58 | |
| 59 | if __name__ == '__main__': |
| 60 | sys.exit(Main()) |