| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Meta checkout manager supporting both Subversion and GIT. | 6 """Meta checkout manager supporting both Subversion and GIT. |
| 7 | 7 |
| 8 Files | 8 Files |
| 9 .gclient : Current client configuration, written by 'config' command. | 9 .gclient : Current client configuration, written by 'config' command. |
| 10 Format is a Python script defining 'solutions', a list whose | 10 Format is a Python script defining 'solutions', a list whose |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 if d in deps and deps[d] != url: | 307 if d in deps and deps[d] != url: |
| 308 raise gclient_utils.Error( | 308 raise gclient_utils.Error( |
| 309 "Solutions have conflicting versions of dependency \"%s\"" % d) | 309 "Solutions have conflicting versions of dependency \"%s\"" % d) |
| 310 if d in solution_urls and solution_urls[d] != url: | 310 if d in solution_urls and solution_urls[d] != url: |
| 311 raise gclient_utils.Error( | 311 raise gclient_utils.Error( |
| 312 "Dependency \"%s\" conflicts with specified solution" % d) | 312 "Dependency \"%s\" conflicts with specified solution" % d) |
| 313 # Grab the dependency. | 313 # Grab the dependency. |
| 314 deps[d] = url | 314 deps[d] = url |
| 315 return deps | 315 return deps |
| 316 | 316 |
| 317 def _RunHookAction(self, hook_dict, matching_file_list): | |
| 318 """Runs the action from a single hook.""" | |
| 319 logging.info(hook_dict) | |
| 320 logging.info(matching_file_list) | |
| 321 command = hook_dict['action'][:] | |
| 322 if command[0] == 'python': | |
| 323 # If the hook specified "python" as the first item, the action is a | |
| 324 # Python script. Run it by starting a new copy of the same | |
| 325 # interpreter. | |
| 326 command[0] = sys.executable | |
| 327 | |
| 328 if '$matching_files' in command: | |
| 329 splice_index = command.index('$matching_files') | |
| 330 command[splice_index:splice_index + 1] = matching_file_list | |
| 331 | |
| 332 # Use a discrete exit status code of 2 to indicate that a hook action | |
| 333 # failed. Users of this script may wish to treat hook action failures | |
| 334 # differently from VC failures. | |
| 335 return gclient_utils.SubprocessCall(command, self.root_dir(), fail_status=2) | |
| 336 | |
| 337 def _RunHooks(self, command, file_list, is_using_git): | 317 def _RunHooks(self, command, file_list, is_using_git): |
| 338 """Evaluates all hooks, running actions as needed. | 318 """Evaluates all hooks, running actions as needed. |
| 339 """ | 319 """ |
| 340 # Hooks only run for these command types. | 320 # Hooks only run for these command types. |
| 341 if not command in ('update', 'revert', 'runhooks'): | 321 if not command in ('update', 'revert', 'runhooks'): |
| 342 return | 322 return |
| 343 | 323 |
| 344 # Hooks only run when --nohooks is not specified | 324 # Hooks only run when --nohooks is not specified |
| 345 if self._options.nohooks: | 325 if self._options.nohooks: |
| 346 return | 326 return |
| (...skipping 13 matching lines...) Expand all Loading... |
| 360 return | 340 return |
| 361 | 341 |
| 362 # Run hooks on the basis of whether the files from the gclient operation | 342 # Run hooks on the basis of whether the files from the gclient operation |
| 363 # match each hook's pattern. | 343 # match each hook's pattern. |
| 364 for hook_dict in hooks: | 344 for hook_dict in hooks: |
| 365 pattern = re.compile(hook_dict['pattern']) | 345 pattern = re.compile(hook_dict['pattern']) |
| 366 matching_file_list = [f for f in file_list if pattern.search(f)] | 346 matching_file_list = [f for f in file_list if pattern.search(f)] |
| 367 if matching_file_list: | 347 if matching_file_list: |
| 368 self._RunHookAction(hook_dict, matching_file_list) | 348 self._RunHookAction(hook_dict, matching_file_list) |
| 369 | 349 |
| 350 def _RunHookAction(self, hook_dict, matching_file_list): |
| 351 """Runs the action from a single hook.""" |
| 352 logging.info(hook_dict) |
| 353 logging.info(matching_file_list) |
| 354 command = hook_dict['action'][:] |
| 355 if command[0] == 'python': |
| 356 # If the hook specified "python" as the first item, the action is a |
| 357 # Python script. Run it by starting a new copy of the same |
| 358 # interpreter. |
| 359 command[0] = sys.executable |
| 360 |
| 361 if '$matching_files' in command: |
| 362 splice_index = command.index('$matching_files') |
| 363 command[splice_index:splice_index + 1] = matching_file_list |
| 364 |
| 365 # Use a discrete exit status code of 2 to indicate that a hook action |
| 366 # failed. Users of this script may wish to treat hook action failures |
| 367 # differently from VC failures. |
| 368 return gclient_utils.SubprocessCall(command, self.root_dir(), fail_status=2) |
| 369 |
| 370 def root_dir(self): | 370 def root_dir(self): |
| 371 return self.parent.root_dir() | 371 return self.parent.root_dir() |
| 372 | 372 |
| 373 def enforced_os(self): | 373 def enforced_os(self): |
| 374 return self.parent.enforced_os() | 374 return self.parent.enforced_os() |
| 375 | 375 |
| 376 def recursion_limit(self): | 376 def recursion_limit(self): |
| 377 return self.parent.recursion_limit() - 1 | 377 return self.parent.recursion_limit() - 1 |
| 378 | 378 |
| 379 def tree(self, force_all): | 379 def tree(self, force_all): |
| (...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 return CMDhelp(parser, argv) | 1191 return CMDhelp(parser, argv) |
| 1192 except gclient_utils.Error, e: | 1192 except gclient_utils.Error, e: |
| 1193 print >> sys.stderr, 'Error: %s' % str(e) | 1193 print >> sys.stderr, 'Error: %s' % str(e) |
| 1194 return 1 | 1194 return 1 |
| 1195 | 1195 |
| 1196 | 1196 |
| 1197 if '__main__' == __name__: | 1197 if '__main__' == __name__: |
| 1198 sys.exit(Main(sys.argv[1:])) | 1198 sys.exit(Main(sys.argv[1:])) |
| 1199 | 1199 |
| 1200 # vim: ts=2:sw=2:tw=80:et: | 1200 # vim: ts=2:sw=2:tw=80:et: |
| OLD | NEW |