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 23 matching lines...) Expand all Loading... |
34 # Constants | 34 # Constants |
35 HELP_STRING = "Sorry, Tryserver is not available." | 35 HELP_STRING = "Sorry, Tryserver is not available." |
36 USAGE = r"""%prog [options] | 36 USAGE = r"""%prog [options] |
37 | 37 |
38 Client-side script to send a try job to the try server. It communicates to | 38 Client-side script to send a try job to the try server. It communicates to |
39 the try server by either writting to a svn repository or by directly connecting | 39 the try server by either writting to a svn repository or by directly connecting |
40 to the server by HTTP. | 40 to the server by HTTP. |
41 | 41 |
42 Examples: | 42 Examples: |
43 Try a change against a particular revision: | 43 Try a change against a particular revision: |
44 %prog change_name -r 123 | 44 %prog -r 123 |
45 | 45 |
46 A git patch off a web site (git inserts a/ and b/) and fix the base dir: | 46 A git patch off a web site (git inserts a/ and b/) and fix the base dir: |
47 %prog --url http://url/to/patch.diff --patchlevel 1 --root src | 47 %prog --url http://url/to/patch.diff --patchlevel 1 --root src |
48 | 48 |
| 49 Or from rietveld: |
| 50 %prog -R codereview.chromium.org/1337 --email me@example.com --root src |
| 51 |
49 Use svn to store the try job, specify an alternate email address and use a | 52 Use svn to store the try job, specify an alternate email address and use a |
50 premade diff file on the local drive: | 53 premade diff file on the local drive: |
51 %prog --email user@example.com | 54 %prog --email user@example.com |
52 --svn_repo svn://svn.chromium.org/chrome-try/try --diff foo.diff | 55 --svn_repo svn://svn.chromium.org/chrome-try/try --diff foo.diff |
53 | 56 |
54 Running only on a 'mac' slave with revision 123 and clobber first; specify | 57 Running only on a 'mac' slave with revision 123 and clobber first; specify |
55 manually the 3 source files to use for the try job: | 58 manually the 3 source files to use for the try job: |
56 %prog --bot mac --revision 123 --clobber -f src/a.cc -f src/a.h | 59 %prog --bot mac --revision 123 --clobber -f src/a.cc -f src/a.h |
57 -f include/b.h | 60 -f include/b.h |
58 | 61 |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 os.environ.get('EMAIL_ADDRESS')), | 450 os.environ.get('EMAIL_ADDRESS')), |
448 help="Email address where to send the results. Use either " | 451 help="Email address where to send the results. Use either " |
449 "the TRYBOT_RESULTS_EMAIL_ADDRESS environment " | 452 "the TRYBOT_RESULTS_EMAIL_ADDRESS environment " |
450 "variable or EMAIL_ADDRESS to set the email address " | 453 "variable or EMAIL_ADDRESS to set the email address " |
451 "the try bots report results to [default: %default]") | 454 "the try bots report results to [default: %default]") |
452 group.add_option("-n", "--name", | 455 group.add_option("-n", "--name", |
453 help="Descriptive name of the try job") | 456 help="Descriptive name of the try job") |
454 group.add_option("--issue", type='int', | 457 group.add_option("--issue", type='int', |
455 help="Update rietveld issue try job status") | 458 help="Update rietveld issue try job status") |
456 group.add_option("--patchset", type='int', | 459 group.add_option("--patchset", type='int', |
457 help="Update rietveld issue try job status") | 460 help="Update rietveld issue try job status. This is " |
| 461 "optional if --issue is used, In that case, the " |
| 462 "latest patchset will be used.") |
458 group.add_option("--dry_run", action='store_true', | 463 group.add_option("--dry_run", action='store_true', |
459 help="Just prints the diff and quits") | 464 help="Just prints the diff and quits") |
460 group.add_option("--rietveld_url", | 465 group.add_option("-R", "--rietveld_url", default="codereview.appspot.com", |
461 help="The code review url.") | 466 metavar="URL", |
| 467 help="The root code review url. Default:%default") |
462 parser.add_option_group(group) | 468 parser.add_option_group(group) |
463 | 469 |
464 group = optparse.OptionGroup(parser, "Try job options") | 470 group = optparse.OptionGroup(parser, "Try job options") |
465 group.add_option("-b", "--bot", action="append", | 471 group.add_option("-b", "--bot", action="append", |
466 help="Only use specifics build slaves, ex: '--bot win' to " | 472 help="Only use specifics build slaves, ex: '--bot win' to " |
467 "run the try job only on the 'win' slave; see the try " | 473 "run the try job only on the 'win' slave; see the try " |
468 "server waterfall for the slave's name") | 474 "server waterfall for the slave's name") |
469 group.add_option("-r", "--revision", | 475 group.add_option("-r", "--revision", |
470 help="Revision to use for the try job; default: the " | 476 help="Revision to use for the try job; default: the " |
471 "revision will be determined by the try server; see " | 477 "revision will be determined by the try server; see " |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 logging.basicConfig(level=logging.ERROR) | 563 logging.basicConfig(level=logging.ERROR) |
558 elif options.verbose == 1: | 564 elif options.verbose == 1: |
559 logging.basicConfig(level=logging.WARNING) | 565 logging.basicConfig(level=logging.WARNING) |
560 elif options.verbose == 2: | 566 elif options.verbose == 2: |
561 logging.basicConfig(level=logging.INFO) | 567 logging.basicConfig(level=logging.INFO) |
562 elif options.verbose > 2: | 568 elif options.verbose > 2: |
563 logging.basicConfig(level=logging.DEBUG) | 569 logging.basicConfig(level=logging.DEBUG) |
564 | 570 |
565 logging.debug(argv) | 571 logging.debug(argv) |
566 | 572 |
| 573 if options.rietveld_url: |
| 574 # Try to extract the review number if possible and fix the protocol. |
| 575 if not '://' in options.rietveld_url: |
| 576 options.rietveld_url = 'http://' + options.rietveld_url |
| 577 match = re.match(r'^(.*)/(\d+)$', options.rietveld_url) |
| 578 if match: |
| 579 if options.issue or options.patchset: |
| 580 parser.error('Cannot use both --issue and use a review number url') |
| 581 options.issue = int(match.group(2)) |
| 582 options.rietveld_url = match.group(1) |
| 583 |
567 try: | 584 try: |
568 # Always include os.getcwd() in the checkout settings. | 585 # Always include os.getcwd() in the checkout settings. |
569 checkouts = [] | 586 checkouts = [] |
570 checkouts.append(GuessVCS(options, os.getcwd())) | 587 checkouts.append(GuessVCS(options, os.getcwd())) |
571 checkouts[0].AutomagicalSettings() | 588 checkouts[0].AutomagicalSettings() |
572 for item in options.sub_rep: | 589 for item in options.sub_rep: |
573 checkout = GuessVCS(options, os.path.join(checkouts[0].checkout_root, | 590 checkout = GuessVCS(options, os.path.join(checkouts[0].checkout_root, |
574 item)) | 591 item)) |
575 if checkout.checkout_root in [c.checkout_root for c in checkouts]: | 592 if checkout.checkout_root in [c.checkout_root for c in checkouts]: |
576 parser.error('Specified the root %s two times.' % | 593 parser.error('Specified the root %s two times.' % |
(...skipping 11 matching lines...) Expand all Loading... |
588 if options.url: | 605 if options.url: |
589 if options.files: | 606 if options.files: |
590 parser.error('You cannot specify files and --url at the same time.') | 607 parser.error('You cannot specify files and --url at the same time.') |
591 options.diff = urllib.urlopen(options.url).read() | 608 options.diff = urllib.urlopen(options.url).read() |
592 elif options.diff: | 609 elif options.diff: |
593 if options.files: | 610 if options.files: |
594 parser.error('You cannot specify files and --diff at the same time.') | 611 parser.error('You cannot specify files and --diff at the same time.') |
595 options.diff = gclient_utils.FileRead(options.diff, 'rb') | 612 options.diff = gclient_utils.FileRead(options.diff, 'rb') |
596 elif options.issue and options.patchset is None: | 613 elif options.issue and options.patchset is None: |
597 # Retrieve the patch from rietveld when the diff is not specified. | 614 # Retrieve the patch from rietveld when the diff is not specified. |
| 615 # When patchset is specified, it's because it's done by gcl/git-try. |
598 try: | 616 try: |
599 import simplejson | 617 import simplejson |
600 except ImportError: | 618 except ImportError: |
601 parser.error('simplejson library is missing, please install.') | 619 parser.error('simplejson library is missing, please install.') |
602 api_url = 'http://%s/api/%d' % (options.rietveld_url, options.issue) | 620 api_url = '%s/api/%d' % (options.rietveld_url, options.issue) |
| 621 logging.debug(api_url) |
603 contents = simplejson.loads(urllib.urlopen(api_url).read()) | 622 contents = simplejson.loads(urllib.urlopen(api_url).read()) |
604 diff_url = ('http://%s/download/issue%d_%d.diff' % | 623 options.patchset = contents['patchsets'][-1] |
605 (options.rietveld_url, options.issue, contents['patchsets'][-1])) | 624 diff_url = ('%s/download/issue%d_%d.diff' % |
| 625 (options.rietveld_url, options.issue, options.patchset)) |
606 diff = GetMungedDiff('', urllib.urlopen(diff_url).readlines()) | 626 diff = GetMungedDiff('', urllib.urlopen(diff_url).readlines()) |
607 options.diff = ''.join(diff) | 627 options.diff = ''.join(diff) |
608 else: | 628 else: |
609 # Use this as the base. | 629 # Use this as the base. |
610 root = checkouts[0].checkout_root | 630 root = checkouts[0].checkout_root |
611 diffs = [] | 631 diffs = [] |
612 for checkout in checkouts: | 632 for checkout in checkouts: |
613 diff = checkout.GenerateDiff().splitlines(True) | 633 diff = checkout.GenerateDiff().splitlines(True) |
614 path_diff = gclient_utils.PathDifference(root, checkout.checkout_root) | 634 path_diff = gclient_utils.PathDifference(root, checkout.checkout_root) |
615 # Munge it. | 635 # Munge it. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 except (InvalidScript, NoTryServerAccess), e: | 686 except (InvalidScript, NoTryServerAccess), e: |
667 if swallow_exception: | 687 if swallow_exception: |
668 return 1 | 688 return 1 |
669 print e | 689 print e |
670 return 1 | 690 return 1 |
671 return 0 | 691 return 0 |
672 | 692 |
673 | 693 |
674 if __name__ == "__main__": | 694 if __name__ == "__main__": |
675 sys.exit(TryChange(None, [], False)) | 695 sys.exit(TryChange(None, [], False)) |
OLD | NEW |