OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright 2014 Google Inc. |
| 3 # |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 |
| 8 import sys |
| 9 import os |
| 10 import subprocess |
| 11 import git_utils |
| 12 import subprocess |
| 13 import misc_utils |
| 14 |
| 15 from DEPS import deps |
| 16 |
| 17 |
| 18 def rm_directory_if_exists(directory): |
| 19 if os.path.isdir(directory) and not os.path.islink(directory): |
| 20 shutil.rmtree(directory) |
| 21 elif os.path.lexists(directory): |
| 22 os.remove(directory) |
| 23 |
| 24 |
| 25 def git_checkout_to_directory(repo, checkout, directory, verbose=False): |
| 26 """TODO(halcanary): document this function. |
| 27 """ |
| 28 git = git_utils.git_executable() |
| 29 assert git |
| 30 if not checkout: |
| 31 checkout = 'origin/master' |
| 32 try: |
| 33 with misc_utils.ChangeDir(directory): |
| 34 if verbose: |
| 35 print '%s\n>>>> %s\n>>>> %s\n' % (directory, repo, checkout) |
| 36 subprocess.check_call([git, 'fetch']) |
| 37 subprocess.check_call([git, 'checkout', '--quiet', checkout]) |
| 38 except: |
| 39 rm_directory_if_exists(directory) |
| 40 subprocess.check_call([git, 'clone', repo, directory]) |
| 41 with misc_utils.ChangeDir(directory): |
| 42 if verbose: |
| 43 print '%s\n>>>> %s\n>>>> %s\n' % (directory, repo, checkout) |
| 44 subprocess.check_call([git, 'checkout', '--quiet', checkout]) |
| 45 |
| 46 |
| 47 def main(argv): |
| 48 dependencies = deps["ALL"].copy() |
| 49 for arg in argv: |
| 50 if arg not in deps: |
| 51 print arg, '?' |
| 52 exit(1) |
| 53 for dep in deps[arg]: |
| 54 dependencies[dep] = deps[arg][dep] |
| 55 for directory in dependencies: |
| 56 repo, checkout = dependencies[directory] |
| 57 git_checkout_to_directory(repo, checkout, directory, verbose=True) |
| 58 |
| 59 |
| 60 if __name__ == '__main__': |
| 61 main(sys.argv[1:]) |
| 62 |
OLD | NEW |