blob: 5f64684f14e2a1151440c0150d1162703a29771b [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001#!/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
9import optparse
10import os
11import shutil
12import subprocess
13import sys
14import tarfile
15import utils
16
Jeffrey van Gogh5dac4482018-01-24 02:36:38 -080017GMSCORE_DEPS = '/google/data/ro/teams/r8/deps'
Mads Ager418d1ca2017-05-22 09:35:49 +020018
19def parse_options():
20 return optparse.OptionParser().parse_args()
21
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020022def download(src, dest):
23 print 'Downloading %s to %s' % (src, dest)
24 shutil.copyfile(src, dest)
25 utils.unpack_archive(dest)
Mads Ager418d1ca2017-05-22 09:35:49 +020026
27def Main():
28 (options, args) = parse_options()
29 assert len(args) == 1
30 sha1_file = args[0]
31 dest = sha1_file[:-5]
32 print 'Ensuring %s' % dest
33 with open(sha1_file, 'r') as input_sha:
34 sha1 = input_sha.readline()
35 if os.path.exists(dest) and utils.get_sha1(dest) == sha1:
36 print 'sha1 matches, not downloading'
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020037 dest_dir = utils.extract_dir(dest)
Mads Ager418d1ca2017-05-22 09:35:49 +020038 if os.path.exists(dest_dir):
39 print 'destination directory exists, no extraction'
40 else:
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020041 utils.unpack_archive(dest)
Mads Ager418d1ca2017-05-22 09:35:49 +020042 return
43 src = os.path.join(GMSCORE_DEPS, sha1)
44 if not os.path.exists(src):
45 print 'File (%s) does not exist on x20' % src
Stephan Herhut79d66bd2017-09-20 09:18:57 +020046 print 'Maybe pass -Pno_internal to your gradle invocation'
47 return 42
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020048 download(src, dest)
Mads Ager418d1ca2017-05-22 09:35:49 +020049
50if __name__ == '__main__':
51 sys.exit(Main())