Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 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 """Client-side script to send a try job to the try server. It communicates to | 5 """Client-side script to send a try job to the try server. It communicates to |
| 6 the try server by either writting to a svn repository or by directly connecting | 6 the try server by either writting to a svn repository or by directly connecting |
| 7 to the server by HTTP. | 7 to the server by HTTP. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import datetime | 10 import datetime |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 except gclient_utils.CheckCallError, e: | 386 except gclient_utils.CheckCallError, e: |
| 387 if e.retcode != errno.ENOENT and e.retcode != 128: | 387 if e.retcode != errno.ENOENT and e.retcode != 128: |
| 388 # ENOENT == 2 = they don't have git installed. | 388 # ENOENT == 2 = they don't have git installed. |
| 389 # 128 = git error code when not in a repo. | 389 # 128 = git error code when not in a repo. |
| 390 logging.warn(e.retcode) | 390 logging.warn(e.retcode) |
| 391 raise | 391 raise |
| 392 raise NoTryServerAccess("Could not guess version control system. " | 392 raise NoTryServerAccess("Could not guess version control system. " |
| 393 "Are you in a working copy directory?") | 393 "Are you in a working copy directory?") |
| 394 | 394 |
| 395 | 395 |
| 396 def GetMungedDiff(path_diff, diff): | |
| 397 # Munge paths to match svn. | |
| 398 for i in range(len(diff)): | |
| 399 if diff[i].startswith('--- ') or diff[i].startswith('+++ '): | |
| 400 new_file = posixpath.join(path_diff, diff[i][4:]).replace('\\', '/') | |
| 401 diff[i] = diff[i][0:4] + new_file | |
| 402 return diff | |
| 403 | |
| 404 | |
| 396 def TryChange(argv, | 405 def TryChange(argv, |
| 397 file_list, | 406 file_list, |
| 398 swallow_exception, | 407 swallow_exception, |
| 399 prog=None): | 408 prog=None): |
| 400 """ | 409 """ |
| 401 Args: | 410 Args: |
| 402 argv: Arguments and options. | 411 argv: Arguments and options. |
| 403 file_list: Default value to pass to --file. | 412 file_list: Default value to pass to --file. |
| 404 swallow_exception: Whether we raise or swallow exceptions. | 413 swallow_exception: Whether we raise or swallow exceptions. |
| 405 """ | 414 """ |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 420 "variable or EMAIL_ADDRESS to set the email address " | 429 "variable or EMAIL_ADDRESS to set the email address " |
| 421 "the try bots report results to [default: %default]") | 430 "the try bots report results to [default: %default]") |
| 422 group.add_option("-n", "--name", | 431 group.add_option("-n", "--name", |
| 423 help="Descriptive name of the try job") | 432 help="Descriptive name of the try job") |
| 424 group.add_option("--issue", type='int', | 433 group.add_option("--issue", type='int', |
| 425 help="Update rietveld issue try job status") | 434 help="Update rietveld issue try job status") |
| 426 group.add_option("--patchset", type='int', | 435 group.add_option("--patchset", type='int', |
| 427 help="Update rietveld issue try job status") | 436 help="Update rietveld issue try job status") |
| 428 group.add_option("--dry_run", action='store_true', | 437 group.add_option("--dry_run", action='store_true', |
| 429 help="Just prints the diff and quits") | 438 help="Just prints the diff and quits") |
| 439 group.add_option("--rietveld_url", | |
| 440 help="The code review url.") | |
| 430 parser.add_option_group(group) | 441 parser.add_option_group(group) |
| 431 | 442 |
| 432 group = optparse.OptionGroup(parser, "Try job options") | 443 group = optparse.OptionGroup(parser, "Try job options") |
| 433 group.add_option("-b", "--bot", action="append", | 444 group.add_option("-b", "--bot", action="append", |
| 434 help="Only use specifics build slaves, ex: '--bot win' to " | 445 help="Only use specifics build slaves, ex: '--bot win' to " |
| 435 "run the try job only on the 'win' slave; see the try " | 446 "run the try job only on the 'win' slave; see the try " |
| 436 "server waterfall for the slave's name") | 447 "server waterfall for the slave's name") |
| 437 group.add_option("-r", "--revision", | 448 group.add_option("-r", "--revision", |
| 438 help="Revision to use for the try job; default: the " | 449 help="Revision to use for the try job; default: the " |
| 439 "revision will be determined by the try server; see " | 450 "revision will be determined by the try server; see " |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 | 562 |
| 552 # Convert options.diff into the content of the diff. | 563 # Convert options.diff into the content of the diff. |
| 553 if options.url: | 564 if options.url: |
| 554 if options.files: | 565 if options.files: |
| 555 parser.error('You cannot specify files and --url at the same time.') | 566 parser.error('You cannot specify files and --url at the same time.') |
| 556 options.diff = urllib.urlopen(options.url).read() | 567 options.diff = urllib.urlopen(options.url).read() |
| 557 elif options.diff: | 568 elif options.diff: |
| 558 if options.files: | 569 if options.files: |
| 559 parser.error('You cannot specify files and --diff at the same time.') | 570 parser.error('You cannot specify files and --diff at the same time.') |
| 560 options.diff = gclient_utils.FileRead(options.diff, 'rb') | 571 options.diff = gclient_utils.FileRead(options.diff, 'rb') |
| 572 elif options.issue: | |
| 573 # Retrieve the patch from rietveld when the diff is not specified. | |
| 574 try: | |
| 575 import simplejson | |
| 576 except ImportError: | |
| 577 parser.error('simplejson library is missing, please install.') | |
| 578 api_url = 'http://%s/api/%d' % (options.rietveld_url, options.issue) | |
| 579 contents = simplejson.loads(urllib.urlopen(api_url).read()) | |
| 580 diff_url = ('http://%s/download/issue%d_%d.diff' % | |
|
Nico
2010/01/10 04:55:49
…then this branch is taken and api_url is http://N
| |
| 581 (options.rietveld_url, options.issue, contents['patchsets'][-1])) | |
| 582 diff = GetMungedDiff('', urllib.urlopen(diff_url).readlines()) | |
|
Nico
2010/01/10 05:02:44
wait, do i read this right? does this mean that th
| |
| 583 options.diff = ''.join(diff) | |
| 561 else: | 584 else: |
| 562 # Use this as the base. | 585 # Use this as the base. |
| 563 root = checkouts[0].checkout_root | 586 root = checkouts[0].checkout_root |
| 564 diffs = [] | 587 diffs = [] |
| 565 for checkout in checkouts: | 588 for checkout in checkouts: |
| 566 diff = checkout.GenerateDiff().splitlines(True) | 589 diff = checkout.GenerateDiff().splitlines(True) |
| 590 path_diff = gclient_utils.PathDifference(root, checkout.checkout_root) | |
| 567 # Munge it. | 591 # Munge it. |
| 568 path_diff = gclient_utils.PathDifference(root, checkout.checkout_root) | 592 diffs.extend(GetMungedDiff(path_diff, diff)) |
| 569 for i in range(len(diff)): | |
| 570 if diff[i].startswith('--- ') or diff[i].startswith('+++ '): | |
| 571 new_file = posixpath.join(path_diff, diff[i][4:]).replace('\\', '/') | |
| 572 diff[i] = diff[i][0:4] + new_file | |
| 573 diffs.extend(diff) | |
| 574 options.diff = ''.join(diffs) | 593 options.diff = ''.join(diffs) |
| 575 | 594 |
| 576 if not options.bot: | 595 if not options.bot: |
| 577 # Get try slaves from PRESUBMIT.py files if not specified. | 596 # Get try slaves from PRESUBMIT.py files if not specified. |
| 578 # Even if the diff comes from options.url, use the local checkout for bot | 597 # Even if the diff comes from options.url, use the local checkout for bot |
| 579 # selection. | 598 # selection. |
| 580 try: | 599 try: |
| 581 import presubmit_support | 600 import presubmit_support |
| 582 root_presubmit = checkouts[0].ReadRootFile('PRESUBMIT.py') | 601 root_presubmit = checkouts[0].ReadRootFile('PRESUBMIT.py') |
| 583 options.bot = presubmit_support.DoGetTrySlaves( | 602 options.bot = presubmit_support.DoGetTrySlaves( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 except (InvalidScript, NoTryServerAccess), e: | 642 except (InvalidScript, NoTryServerAccess), e: |
| 624 if swallow_exception: | 643 if swallow_exception: |
| 625 return 1 | 644 return 1 |
| 626 print e | 645 print e |
| 627 return 1 | 646 return 1 |
| 628 return 0 | 647 return 0 |
| 629 | 648 |
| 630 | 649 |
| 631 if __name__ == "__main__": | 650 if __name__ == "__main__": |
| 632 sys.exit(TryChange(None, [], False)) | 651 sys.exit(TryChange(None, [], False)) |
| OLD | NEW |