Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: tools/grab_deps.py

Issue 191133005: git-sync-deps tool (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: AnotherPatchSet Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « docs/quickstart.md ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 git_utils
9 import misc_utils
10 import os
11 import subprocess
12 import sys
13
14
15 DEPS_FILE_DIRECTORY = os.path.join(os.path.dirname(__file__), os.pardir)
16 DEPS_FILE_PATH = os.path.join(DEPS_FILE_DIRECTORY, 'DEPS')
17
18
19 def useage():
epoger 2014/04/11 18:28:39 useage -> usage
hal.canary 2014/04/11 18:36:21 Done.
20 sys.stderr.write(
21 'Useage: run to grab Skia dependencies, with optional platform support:\n')
22 sys.stderr.write(' python %s' % __file__)
23 for deps_os in parse_file_to_dict(DEPS_FILE_PATH)['deps_os']:
24 sys.stderr.write(' [%s]' % deps_os)
25 sys.stderr.write('\n\n')
26
27
28 def rm_directory_if_exists(directory):
29 if os.path.isdir(directory) and not os.path.islink(directory):
30 shutil.rmtree(directory)
31 elif os.path.lexists(directory):
32 os.remove(directory)
33
34
35 def git_checkout_to_directory(repo, checkoutable, directory, verbose=False):
36 """Checkout (and clone if needed) a Git repository.
37
38 param repo (string) the location of the repository, suitable
39 for passing to `git clone`.
40
41 param checkoutable (string) a tag, branch, or commit, suitable for
42 passing to `git checkout`
43
44 param directory (string) the path into which the repository
45 should be checked out.
46
47 raises an exception if any calls to git fail.
48 """
49 git = git_utils.git_executable()
50 assert git
51 try:
52 with misc_utils.ChangeDir(directory):
53 if verbose:
54 print '%s\n>>>> %s\n>>>> %s\n' % (directory, repo, checkoutable)
55 subprocess.check_call([git, 'fetch'])
56 subprocess.check_call([git, 'checkout', '--quiet', checkoutable])
57 except:
58 rm_directory_if_exists(directory)
59 subprocess.check_call([git, 'clone', repo, directory])
60 with misc_utils.ChangeDir(directory):
61 if verbose:
62 print '%s\n>>>> %s\n>>>> %s\n' % (directory, repo, checkoutable)
63 subprocess.check_call([git, 'checkout', '--quiet', checkoutable])
64
65
66 def parse_file_to_dict(path):
67 dictionary = {}
68 execfile(path, dictionary)
69 return dictionary
70
71
72 class DepsError(Exception):
73 pass
74
75
76 def main(argv):
77 deps = parse_file_to_dict(DEPS_FILE_PATH)
78 dependencies = deps['deps'].copy()
79 for arg in argv:
80 # Add OS-specific dependencies
81 if arg not in deps['deps_os']:
82 raise DepsError(
83 'Argument "%s" not found within deps_os keys %r' %
84 (arg, deps['deps_os'].keys()))
85 for dep in deps['deps_os'][arg]:
86 dependencies[dep] = deps['deps_os'][arg][dep]
87 for directory in dependencies:
88 if '@' in dependencies[directory]:
89 repo, checkoutable = dependencies[directory].split('@', 1)
90 else:
91 repo, checkoutable = dependencies[directory], 'origin/master'
92
93 with misc_utils.ChangeDir(DEPS_FILE_DIRECTORY):
94 git_checkout_to_directory(repo, checkoutable, directory, verbose=True)
95 return 0
96
97
98 if __name__ == '__main__':
99 try:
100 main(sys.argv[1:])
101 except DepsError:
102 useage()
103 exit(1)
104
105
OLDNEW
« no previous file with comments | « docs/quickstart.md ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698