| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2014 Google Inc. | 2 # Copyright 2014 Google Inc. |
| 3 # | 3 # |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 | 7 |
| 8 """Parse a DEPS file and git checkout all of the dependencies. | 8 """Parse a DEPS file and git checkout all of the dependencies. |
| 9 | 9 |
| 10 Args: | 10 Args: |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if verbose: | 141 if verbose: |
| 142 sys.stdout.write('%s\n @ %s\n' % (directory, checkoutable)) # Success. | 142 sys.stdout.write('%s\n @ %s\n' % (directory, checkoutable)) # Success. |
| 143 | 143 |
| 144 | 144 |
| 145 def parse_file_to_dict(path): | 145 def parse_file_to_dict(path): |
| 146 dictionary = {} | 146 dictionary = {} |
| 147 execfile(path, dictionary) | 147 execfile(path, dictionary) |
| 148 return dictionary | 148 return dictionary |
| 149 | 149 |
| 150 | 150 |
| 151 class DepsError(Exception): | 151 def git_sync_deps(deps_file_path, command_line_os_requests, verbose): |
| 152 """Raised if deps_os is a bad key. | |
| 153 """ | |
| 154 pass | |
| 155 | |
| 156 | |
| 157 def git_sync_deps(deps_file_path, deps_os_list, verbose): | |
| 158 """Grab dependencies, with optional platform support. | 152 """Grab dependencies, with optional platform support. |
| 159 | 153 |
| 160 Args: | 154 Args: |
| 161 deps_file_path (string) Path to the DEPS file. | 155 deps_file_path (string) Path to the DEPS file. |
| 162 | 156 |
| 163 deps_os_list (list of strings) Can be empty list. List of | 157 command_line_os_requests (list of strings) Can be empty list. |
| 164 strings that should each be a key in the deps_os | 158 List of strings that should each be a key in the deps_os |
| 165 dictionary in the DEPS file. | 159 dictionary in the DEPS file. |
| 166 | 160 |
| 167 Raises DepsError exception and git Exceptions. | 161 Raises git Exceptions. |
| 168 """ | 162 """ |
| 169 git = git_executable() | 163 git = git_executable() |
| 170 assert git | 164 assert git |
| 171 | 165 |
| 172 deps_file_directory = os.path.dirname(deps_file_path) | 166 deps_file_directory = os.path.dirname(deps_file_path) |
| 173 deps = parse_file_to_dict(deps_file_path) | 167 deps_file = parse_file_to_dict(deps_file_path) |
| 174 dependencies = deps['deps'].copy() | 168 dependencies = deps_file['deps'].copy() |
| 175 for deps_os in deps_os_list: | 169 os_specific_dependencies = deps_file.get('deps_os', []) |
| 170 for os_name in command_line_os_requests: |
| 176 # Add OS-specific dependencies | 171 # Add OS-specific dependencies |
| 177 if deps_os not in deps['deps_os']: | 172 if os_name in os_specific_dependencies: |
| 178 raise DepsError( | 173 dependencies.update(os_specific_dependencies[os_name]) |
| 179 'Argument "%s" not found within deps_os keys %r' % | |
| 180 (deps_os, deps['deps_os'].keys())) | |
| 181 for dep in deps['deps_os'][deps_os]: | |
| 182 dependencies[dep] = deps['deps_os'][deps_os][dep] | |
| 183 list_of_arg_lists = [] | 174 list_of_arg_lists = [] |
| 184 for directory in dependencies: | 175 for directory in dependencies: |
| 185 if '@' in dependencies[directory]: | 176 if '@' in dependencies[directory]: |
| 186 repo, checkoutable = dependencies[directory].split('@', 1) | 177 repo, checkoutable = dependencies[directory].split('@', 1) |
| 187 else: | 178 else: |
| 188 repo, checkoutable = dependencies[directory], 'origin/master' | 179 repo, checkoutable = dependencies[directory], 'origin/master' |
| 189 | 180 |
| 190 relative_directory = os.path.join(deps_file_directory, directory) | 181 relative_directory = os.path.join(deps_file_directory, directory) |
| 191 | 182 |
| 192 list_of_arg_lists.append( | 183 list_of_arg_lists.append( |
| 193 (git, repo, checkoutable, relative_directory, verbose)) | 184 (git, repo, checkoutable, relative_directory, verbose)) |
| 194 | 185 |
| 195 multithread(git_checkout_to_directory, list_of_arg_lists) | 186 multithread(git_checkout_to_directory, list_of_arg_lists) |
| 196 | 187 |
| 197 for directory in deps.get('recursedeps', []): | 188 for directory in deps_file.get('recursedeps', []): |
| 198 recursive_path = os.path.join(deps_file_directory, directory, 'DEPS') | 189 recursive_path = os.path.join(deps_file_directory, directory, 'DEPS') |
| 199 git_sync_deps(recursive_path, deps_os_list, verbose) | 190 git_sync_deps(recursive_path, command_line_os_requests, verbose) |
| 200 | 191 |
| 201 | 192 |
| 202 def multithread(function, list_of_arg_lists): | 193 def multithread(function, list_of_arg_lists): |
| 203 # for args in list_of_arg_lists: | 194 # for args in list_of_arg_lists: |
| 204 # function(*args) | 195 # function(*args) |
| 205 # return | 196 # return |
| 206 threads = [] | 197 threads = [] |
| 207 for args in list_of_arg_lists: | 198 for args in list_of_arg_lists: |
| 208 thread = threading.Thread(None, function, None, args) | 199 thread = threading.Thread(None, function, None, args) |
| 209 thread.start() | 200 thread.start() |
| 210 threads.append(thread) | 201 threads.append(thread) |
| 211 for thread in threads: | 202 for thread in threads: |
| 212 thread.join() | 203 thread.join() |
| 213 | 204 |
| 214 | 205 |
| 215 def main(argv): | 206 def main(argv): |
| 216 deps_file_path = os.environ.get('GIT_SYNC_DEPS_PATH', DEFAULT_DEPS_PATH) | 207 deps_file_path = os.environ.get('GIT_SYNC_DEPS_PATH', DEFAULT_DEPS_PATH) |
| 217 verbose = not bool(os.environ.get('GIT_SYNC_DEPS_QUIET', False)) | 208 verbose = not bool(os.environ.get('GIT_SYNC_DEPS_QUIET', False)) |
| 218 try: | 209 |
| 219 git_sync_deps(deps_file_path, argv, verbose) | 210 if '--help' in argv or '-h' in argv: |
| 220 return 0 | |
| 221 except DepsError: | |
| 222 usage(deps_file_path) | 211 usage(deps_file_path) |
| 223 return 1 | 212 return 1 |
| 224 | 213 |
| 214 git_sync_deps(deps_file_path, argv, verbose) |
| 215 return 0 |
| 216 |
| 225 | 217 |
| 226 if __name__ == '__main__': | 218 if __name__ == '__main__': |
| 227 exit(main(sys.argv[1:])) | 219 exit(main(sys.argv[1:])) |
| OLD | NEW |