Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Minimal tool to download doclava from Google storage when building for | |
| 7 Android.""" | |
| 8 | |
| 9 import os | |
| 10 import shutil | |
| 11 import subprocess | |
| 12 import sys | |
| 13 | |
| 14 | |
| 15 # Its existence signifies an Android checkout. | |
| 16 ANDROID_ONLY_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), | |
| 17 os.pardir, os.pardir, | |
| 18 'third_party', 'android_tools') | |
| 19 | |
| 20 | |
| 21 def ReadFile(filename): | |
| 22 with file(filename, 'r') as f: | |
| 23 return f.read().strip() | |
| 24 | |
| 25 | |
| 26 def WriteFile(filename, content): | |
| 27 assert not os.path.exists(filename) | |
| 28 with file(filename, 'w') as f: | |
| 29 f.write(content) | |
| 30 f.write('\n') | |
| 31 | |
| 32 | |
| 33 def main(): | |
| 34 # Some Windows bots inadvertently have third_party/android_tools installed, | |
| 35 # but are unable to run download_from_google_storage because depot_tools | |
| 36 # is not in their path, so avoid failure and bail. | |
| 37 if sys.platform == 'win32': | |
| 38 return 0 | |
| 39 if not os.path.exists(ANDROID_ONLY_DIR): | |
| 40 return 0 | |
| 41 | |
| 42 outdir = os.path.join('src', 'buildtools', 'android', 'doclava') | |
| 43 tarball = outdir + '.tar.gz' | |
| 44 sha1file = tarball + '.sha1' | |
| 45 stampfile = tarball + '.stamp' | |
| 46 | |
| 47 checksum = ReadFile(sha1file) | |
| 48 | |
| 49 if os.path.exists(stampfile): | |
| 50 if (os.path.exists(tarball) and | |
| 51 os.path.exists(outdir) and | |
| 52 checksum == ReadFile(stampfile)): | |
| 53 return 0 | |
| 54 else: | |
| 55 os.unlink(stampfile) | |
| 56 | |
| 57 subprocess.check_call([ | |
| 58 'download_from_google_storage', | |
| 59 '--no_resume', | |
| 60 '--no_auth', | |
| 61 '--bucket', 'chromium-doclava', | |
| 62 '-s', sha1file]) | |
|
agrieve
2016/04/11 17:12:56
You should add a comment saying why --extract does
| |
| 63 assert os.path.exists(tarball) | |
| 64 | |
| 65 if os.path.exists(outdir): | |
| 66 shutil.rmtree(outdir) | |
| 67 assert not os.path.exists(outdir) | |
| 68 os.makedirs(outdir) | |
| 69 assert os.path.exists(outdir) | |
| 70 | |
| 71 print "Extracting", tarball | |
| 72 subprocess.check_call(['tar', 'axf', os.path.abspath(tarball)], cwd=outdir) | |
|
agrieve
2016/04/11 17:12:57
Probably better to use Python's tarfile module for
| |
| 73 | |
| 74 WriteFile(stampfile, checksum) | |
| 75 return 0 | |
| 76 | |
| 77 if __name__ == '__main__': | |
| 78 sys.exit(main()) | |
| OLD | NEW |