Chromium Code Reviews| Index: tools/grab_deps.py |
| diff --git a/tools/grab_deps.py b/tools/grab_deps.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..4977b352cedfb67a2b5241307e7ba5f761a3d327 |
| --- /dev/null |
| +++ b/tools/grab_deps.py |
| @@ -0,0 +1,105 @@ |
| +#!/usr/bin/python |
| +# Copyright 2014 Google Inc. |
| +# |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| + |
| +import git_utils |
| +import misc_utils |
| +import os |
| +import subprocess |
| +import sys |
| + |
| + |
| +DEPS_FILE_DIRECTORY = os.path.join(os.path.dirname(__file__), os.pardir) |
| +DEPS_FILE_PATH = os.path.join(DEPS_FILE_DIRECTORY, 'DEPS') |
| + |
| + |
| +def useage(): |
|
epoger
2014/04/11 18:28:39
useage -> usage
hal.canary
2014/04/11 18:36:21
Done.
|
| + sys.stderr.write( |
| + 'Useage: run to grab Skia dependencies, with optional platform support:\n') |
| + sys.stderr.write(' python %s' % __file__) |
| + for deps_os in parse_file_to_dict(DEPS_FILE_PATH)['deps_os']: |
| + sys.stderr.write(' [%s]' % deps_os) |
| + sys.stderr.write('\n\n') |
| + |
| + |
| +def rm_directory_if_exists(directory): |
| + if os.path.isdir(directory) and not os.path.islink(directory): |
| + shutil.rmtree(directory) |
| + elif os.path.lexists(directory): |
| + os.remove(directory) |
| + |
| + |
| +def git_checkout_to_directory(repo, checkoutable, directory, verbose=False): |
| + """Checkout (and clone if needed) a Git repository. |
| + |
| + param repo (string) the location of the repository, suitable |
| + for passing to `git clone`. |
| + |
| + param checkoutable (string) a tag, branch, or commit, suitable for |
| + passing to `git checkout` |
| + |
| + param directory (string) the path into which the repository |
| + should be checked out. |
| + |
| + raises an exception if any calls to git fail. |
| + """ |
| + git = git_utils.git_executable() |
| + assert git |
| + try: |
| + with misc_utils.ChangeDir(directory): |
| + if verbose: |
| + print '%s\n>>>> %s\n>>>> %s\n' % (directory, repo, checkoutable) |
| + subprocess.check_call([git, 'fetch']) |
| + subprocess.check_call([git, 'checkout', '--quiet', checkoutable]) |
| + except: |
| + rm_directory_if_exists(directory) |
| + subprocess.check_call([git, 'clone', repo, directory]) |
| + with misc_utils.ChangeDir(directory): |
| + if verbose: |
| + print '%s\n>>>> %s\n>>>> %s\n' % (directory, repo, checkoutable) |
| + subprocess.check_call([git, 'checkout', '--quiet', checkoutable]) |
| + |
| + |
| +def parse_file_to_dict(path): |
| + dictionary = {} |
| + execfile(path, dictionary) |
| + return dictionary |
| + |
| + |
| +class DepsError(Exception): |
| + pass |
| + |
| + |
| +def main(argv): |
| + deps = parse_file_to_dict(DEPS_FILE_PATH) |
| + dependencies = deps['deps'].copy() |
| + for arg in argv: |
| + # Add OS-specific dependencies |
| + if arg not in deps['deps_os']: |
| + raise DepsError( |
| + 'Argument "%s" not found within deps_os keys %r' % |
| + (arg, deps['deps_os'].keys())) |
| + for dep in deps['deps_os'][arg]: |
| + dependencies[dep] = deps['deps_os'][arg][dep] |
| + for directory in dependencies: |
| + if '@' in dependencies[directory]: |
| + repo, checkoutable = dependencies[directory].split('@', 1) |
| + else: |
| + repo, checkoutable = dependencies[directory], 'origin/master' |
| + |
| + with misc_utils.ChangeDir(DEPS_FILE_DIRECTORY): |
| + git_checkout_to_directory(repo, checkoutable, directory, verbose=True) |
| + return 0 |
| + |
| + |
| +if __name__ == '__main__': |
| + try: |
| + main(sys.argv[1:]) |
| + except DepsError: |
| + useage() |
| + exit(1) |
| + |
| + |