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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 __version__ = '1.2' | 39 __version__ = '1.2' |
40 | 40 |
41 | 41 |
42 # Constants | 42 # Constants |
43 HELP_STRING = "Sorry, Tryserver is not available." | 43 HELP_STRING = "Sorry, Tryserver is not available." |
44 USAGE = r"""%prog [options] | 44 USAGE = r"""%prog [options] |
45 | 45 |
46 Client-side script to send a try job to the try server. It communicates to | 46 Client-side script to send a try job to the try server. It communicates to |
47 the try server by either writting to a svn repository or by directly connecting | 47 the try server by either writting to a svn repository or by directly connecting |
48 to the server by HTTP. | 48 to the server by HTTP.""" |
49 | 49 |
| 50 EPILOG = """ |
50 Examples: | 51 Examples: |
| 52 Send a patch directly from rietveld: |
| 53 %(prog)s -R codereview.chromium.org/1337 |
| 54 --email recipient@example.com --root src |
| 55 |
51 Try a change against a particular revision: | 56 Try a change against a particular revision: |
52 %prog -r 123 | 57 %(prog)s -r 123 |
53 | 58 |
54 A git patch off a web site (git inserts a/ and b/) and fix the base dir: | 59 A git patch off a web site (git inserts a/ and b/) and fix the base dir: |
55 %prog --url http://url/to/patch.diff --patchlevel 1 --root src | 60 %(prog)s --url http://url/to/patch.diff --patchlevel 1 --root src |
56 | |
57 Or from rietveld: | |
58 %prog -R codereview.chromium.org/1337 --email me@example.com --root src | |
59 | 61 |
60 Use svn to store the try job, specify an alternate email address and use a | 62 Use svn to store the try job, specify an alternate email address and use a |
61 premade diff file on the local drive: | 63 premade diff file on the local drive: |
62 %prog --email user@example.com | 64 %(prog)s --email user@example.com |
63 --svn_repo svn://svn.chromium.org/chrome-try/try --diff foo.diff | 65 --svn_repo svn://svn.chromium.org/chrome-try/try --diff foo.diff |
64 | 66 |
65 Running only on a 'mac' slave with revision 123 and clobber first; specify | 67 Running only on a 'mac' slave with revision 123 and clobber first; specify |
66 manually the 3 source files to use for the try job: | 68 manually the 3 source files to use for the try job: |
67 %prog --bot mac --revision 123 --clobber -f src/a.cc -f src/a.h | 69 %(prog)s --bot mac --revision 123 --clobber -f src/a.cc -f src/a.h |
68 -f include/b.h | 70 -f include/b.h |
69 | |
70 When called from gcl, use the format gcl try <change_name>. | |
71 """ | 71 """ |
72 | 72 |
73 class InvalidScript(Exception): | 73 class InvalidScript(Exception): |
74 def __str__(self): | 74 def __str__(self): |
75 return self.args[0] + '\n' + HELP_STRING | 75 return self.args[0] + '\n' + HELP_STRING |
76 | 76 |
77 | 77 |
78 class NoTryServerAccess(Exception): | 78 class NoTryServerAccess(Exception): |
79 def __str__(self): | 79 def __str__(self): |
80 return self.args[0] + '\n' + HELP_STRING | 80 return self.args[0] + '\n' + HELP_STRING |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 for i in range(len(diff)): | 442 for i in range(len(diff)): |
443 if diff[i].startswith('--- ') or diff[i].startswith('+++ '): | 443 if diff[i].startswith('--- ') or diff[i].startswith('+++ '): |
444 new_file = posixpath.join(path_diff, diff[i][4:]).replace('\\', '/') | 444 new_file = posixpath.join(path_diff, diff[i][4:]).replace('\\', '/') |
445 diff[i] = diff[i][0:4] + new_file | 445 diff[i] = diff[i][0:4] + new_file |
446 return diff | 446 return diff |
447 | 447 |
448 | 448 |
449 def TryChange(argv, | 449 def TryChange(argv, |
450 file_list, | 450 file_list, |
451 swallow_exception, | 451 swallow_exception, |
452 prog=None): | 452 prog=None, |
| 453 extra_epilog=None): |
453 """ | 454 """ |
454 Args: | 455 Args: |
455 argv: Arguments and options. | 456 argv: Arguments and options. |
456 file_list: Default value to pass to --file. | 457 file_list: Default value to pass to --file. |
457 swallow_exception: Whether we raise or swallow exceptions. | 458 swallow_exception: Whether we raise or swallow exceptions. |
458 """ | 459 """ |
459 # Parse argv | 460 # Parse argv |
| 461 epilog = EPILOG % { 'prog': prog } |
| 462 if extra_epilog: |
| 463 epilog += extra_epilog |
460 parser = optparse.OptionParser(usage=USAGE, | 464 parser = optparse.OptionParser(usage=USAGE, |
461 version=__version__, | 465 version=__version__, |
462 prog=prog) | 466 prog=prog, |
| 467 epilog=epilog) |
| 468 # Remove epilog formatting |
| 469 parser.format_epilog = lambda x: parser.epilog |
463 parser.add_option("-v", "--verbose", action="count", default=0, | 470 parser.add_option("-v", "--verbose", action="count", default=0, |
464 help="Prints debugging infos") | 471 help="Prints debugging infos") |
465 group = optparse.OptionGroup(parser, "Result and status") | 472 group = optparse.OptionGroup(parser, "Result and status") |
466 group.add_option("-u", "--user", default=getpass.getuser(), | 473 group.add_option("-u", "--user", default=getpass.getuser(), |
467 help="Owner user name [default: %default]") | 474 help="Owner user name [default: %default]") |
468 group.add_option("-e", "--email", | 475 group.add_option("-e", "--email", |
469 default=os.environ.get('TRYBOT_RESULTS_EMAIL_ADDRESS', | 476 default=os.environ.get('TRYBOT_RESULTS_EMAIL_ADDRESS', |
470 os.environ.get('EMAIL_ADDRESS')), | 477 os.environ.get('EMAIL_ADDRESS')), |
471 help="Email address where to send the results. Use either " | 478 help="Email address where to send the results. Use either " |
472 "the TRYBOT_RESULTS_EMAIL_ADDRESS environment " | 479 "the TRYBOT_RESULTS_EMAIL_ADDRESS environment " |
473 "variable or EMAIL_ADDRESS to set the email address " | 480 "variable or EMAIL_ADDRESS to set the email address " |
474 "the try bots report results to [default: %default]") | 481 "the try bots report results to [default: %default]") |
475 group.add_option("-n", "--name", | 482 group.add_option("-n", "--name", |
476 help="Descriptive name of the try job") | 483 help="Descriptive name of the try job") |
477 group.add_option("--issue", type='int', | 484 group.add_option("--issue", type='int', |
478 help="Update rietveld issue try job status") | 485 help="Update rietveld issue try job status") |
479 group.add_option("--patchset", type='int', | 486 group.add_option("--patchset", type='int', |
480 help="Update rietveld issue try job status. This is " | 487 help="Update rietveld issue try job status. This is " |
481 "optional if --issue is used, In that case, the " | 488 "optional if --issue is used, In that case, the " |
482 "latest patchset will be used.") | 489 "latest patchset will be used.") |
483 group.add_option("--dry_run", action='store_true', | 490 group.add_option("--dry_run", action='store_true', |
484 help="Just prints the diff and quits") | 491 help="Just prints the diff and quits") |
485 group.add_option("-R", "--rietveld_url", default="codereview.appspot.com", | |
486 metavar="URL", | |
487 help="The root code review url. Default:%default") | |
488 parser.add_option_group(group) | 492 parser.add_option_group(group) |
489 | 493 |
490 group = optparse.OptionGroup(parser, "Try job options") | 494 group = optparse.OptionGroup(parser, "Try job options") |
491 group.add_option("-b", "--bot", action="append", | 495 group.add_option("-b", "--bot", action="append", |
492 help="Only use specifics build slaves, ex: '--bot win' to " | 496 help="Only use specifics build slaves, ex: '--bot win' to " |
493 "run the try job only on the 'win' slave; see the try " | 497 "run the try job only on the 'win' slave; see the try " |
494 "server waterfall for the slave's name") | 498 "server waterfall for the slave's name") |
495 group.add_option("-r", "--revision", | 499 group.add_option("-r", "--revision", |
496 help="Revision to use for the try job; default: the " | 500 help="Revision to use for the try job; default: the " |
497 "revision will be determined by the try server; see " | 501 "revision will be determined by the try server; see " |
(...skipping 20 matching lines...) Expand all Loading... |
518 parser.add_option_group(group) | 522 parser.add_option_group(group) |
519 | 523 |
520 group = optparse.OptionGroup(parser, "Patch to run") | 524 group = optparse.OptionGroup(parser, "Patch to run") |
521 group.add_option("-f", "--file", default=file_list, dest="files", | 525 group.add_option("-f", "--file", default=file_list, dest="files", |
522 metavar="FILE", action="append", | 526 metavar="FILE", action="append", |
523 help="Use many times to list the files to include in the " | 527 help="Use many times to list the files to include in the " |
524 "try, relative to the repository root") | 528 "try, relative to the repository root") |
525 group.add_option("--diff", | 529 group.add_option("--diff", |
526 help="File containing the diff to try") | 530 help="File containing the diff to try") |
527 group.add_option("--url", | 531 group.add_option("--url", |
528 help="Url where to grab a patch") | 532 help="Url where to grab a patch, e.g. " |
| 533 "http://example.com/x.diff") |
| 534 group.add_option("-R", "--rietveld_url", default="codereview.appspot.com", |
| 535 metavar="URL", |
| 536 help="Has 2 usages, both refer to the rietveld instance: " |
| 537 "Specify which code review patch to use as the try job " |
| 538 "or rietveld instance to update the try job results " |
| 539 "Default:%default") |
529 group.add_option("--root", | 540 group.add_option("--root", |
530 help="Root to use for the patch; base subdirectory for " | 541 help="Root to use for the patch; base subdirectory for " |
531 "patch created in a subdirectory") | 542 "patch created in a subdirectory") |
532 group.add_option("-p", "--patchlevel", type='int', metavar="LEVEL", | 543 group.add_option("-p", "--patchlevel", type='int', metavar="LEVEL", |
533 help="Used as -pN parameter to patch") | 544 help="Used as -pN parameter to patch") |
534 group.add_option("-s", "--sub_rep", action="append", default=[], | 545 group.add_option("-s", "--sub_rep", action="append", default=[], |
535 help="Subcheckout to use in addition. This is mainly " | 546 help="Subcheckout to use in addition. This is mainly " |
536 "useful for gclient-style checkouts. Use @rev or " | 547 "useful for gclient-style checkouts. Use @rev or " |
537 "@branch or @branch1..branch2 to specify the " | 548 "@branch or @branch1..branch2 to specify the " |
538 "revision/branch to diff against.") | 549 "revision/branch to diff against.") |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 except (InvalidScript, NoTryServerAccess), e: | 735 except (InvalidScript, NoTryServerAccess), e: |
725 if swallow_exception: | 736 if swallow_exception: |
726 return 1 | 737 return 1 |
727 print e | 738 print e |
728 return 1 | 739 return 1 |
729 return 0 | 740 return 0 |
730 | 741 |
731 | 742 |
732 if __name__ == "__main__": | 743 if __name__ == "__main__": |
733 sys.exit(TryChange(None, [], False)) | 744 sys.exit(TryChange(None, [], False)) |
OLD | NEW |