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 | 10 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 if (values.get('bot') and len(e.args) > 2 and | 324 if (values.get('bot') and len(e.args) > 2 and |
| 325 e.args[2] == 'got a bad status line'): | 325 e.args[2] == 'got a bad status line'): |
| 326 raise NoTryServerAccess('%s is unaccessible. Bad --bot argument?' % url) | 326 raise NoTryServerAccess('%s is unaccessible. Bad --bot argument?' % url) |
| 327 else: | 327 else: |
| 328 raise NoTryServerAccess('%s is unaccessible. Reason: %s' % (url, | 328 raise NoTryServerAccess('%s is unaccessible. Reason: %s' % (url, |
| 329 str(e.args))) | 329 str(e.args))) |
| 330 if not connection: | 330 if not connection: |
| 331 raise NoTryServerAccess('%s is unaccessible.' % url) | 331 raise NoTryServerAccess('%s is unaccessible.' % url) |
| 332 if connection.read() != 'OK': | 332 if connection.read() != 'OK': |
| 333 raise NoTryServerAccess('%s is unaccessible.' % url) | 333 raise NoTryServerAccess('%s is unaccessible.' % url) |
| 334 return options.name | |
| 335 | 334 |
| 336 | 335 |
| 337 def _SendChangeSVN(options): | 336 def _SendChangeSVN(options): |
| 338 """Send a change to the try server by committing a diff file on a subversion | 337 """Send a change to the try server by committing a diff file on a subversion |
| 339 server.""" | 338 server.""" |
| 340 if not options.svn_repo: | 339 if not options.svn_repo: |
| 341 raise NoTryServerAccess('Please use the --svn_repo option to specify the' | 340 raise NoTryServerAccess('Please use the --svn_repo option to specify the' |
| 342 ' try server svn repository to connect to.') | 341 ' try server svn repository to connect to.') |
| 343 | 342 |
| 344 values = _ParseSendChangeOptions(options) | 343 values = _ParseSendChangeOptions(options) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 file.write(options.diff) | 386 file.write(options.diff) |
| 388 file.close() | 387 file.close() |
| 389 RunCommand(["svn", "add", full_path]) | 388 RunCommand(["svn", "add", full_path]) |
| 390 temp_file.write(description) | 389 temp_file.write(description) |
| 391 temp_file.flush() | 390 temp_file.flush() |
| 392 RunCommand(["svn", "commit", full_path, '--file', | 391 RunCommand(["svn", "commit", full_path, '--file', |
| 393 temp_file_name]) | 392 temp_file_name]) |
| 394 finally: | 393 finally: |
| 395 temp_file.close() | 394 temp_file.close() |
| 396 shutil.rmtree(temp_dir, True) | 395 shutil.rmtree(temp_dir, True) |
| 397 return options.name | |
| 398 | 396 |
| 399 | 397 |
| 400 def GuessVCS(options): | 398 def GuessVCS(options): |
| 401 """Helper to guess the version control system. | 399 """Helper to guess the version control system. |
| 402 | 400 |
| 403 NOTE: Very similar to upload.GuessVCS. Doesn't look for hg since we don't | 401 NOTE: Very similar to upload.GuessVCS. Doesn't look for hg since we don't |
| 404 support it yet. | 402 support it yet. |
| 405 | 403 |
| 406 This examines the current directory, guesses which SCM we're using, and | 404 This examines the current directory, guesses which SCM we're using, and |
| 407 returns an instance of the appropriate class. Exit with an error if we can't | 405 returns an instance of the appropriate class. Exit with an error if we can't |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 version=__version__, | 449 version=__version__, |
| 452 prog=prog) | 450 prog=prog) |
| 453 | 451 |
| 454 group = optparse.OptionGroup(parser, "Result and status") | 452 group = optparse.OptionGroup(parser, "Result and status") |
| 455 group.add_option("-u", "--user", default=getpass.getuser(), | 453 group.add_option("-u", "--user", default=getpass.getuser(), |
| 456 help="Owner user name [default: %default]") | 454 help="Owner user name [default: %default]") |
| 457 group.add_option("-e", "--email", default=os.environ.get('EMAIL_ADDRESS'), | 455 group.add_option("-e", "--email", default=os.environ.get('EMAIL_ADDRESS'), |
| 458 help="Email address where to send the results. Use the " | 456 help="Email address where to send the results. Use the " |
| 459 "EMAIL_ADDRESS environment variable to set the default " | 457 "EMAIL_ADDRESS environment variable to set the default " |
| 460 "email address [default: %default]") | 458 "email address [default: %default]") |
| 461 group.add_option("-n", "--name", default='Unnamed', | 459 group.add_option("-n", "--name", |
| 462 help="Descriptive name of the try job") | 460 help="Descriptive name of the try job") |
| 463 group.add_option("--issue", type='int', | 461 group.add_option("--issue", type='int', |
| 464 help="Update rietveld issue try job status") | 462 help="Update rietveld issue try job status") |
| 465 group.add_option("--patchset", type='int', | 463 group.add_option("--patchset", type='int', |
| 466 help="Update rietveld issue try job status") | 464 help="Update rietveld issue try job status") |
| 467 parser.add_option_group(group) | 465 parser.add_option_group(group) |
| 468 | 466 |
| 469 group = optparse.OptionGroup(parser, "Try job options") | 467 group = optparse.OptionGroup(parser, "Try job options") |
| 470 group.add_option("-b", "--bot", action="append", | 468 group.add_option("-b", "--bot", action="append", |
| 471 help="Only use specifics build slaves, ex: '--bot win' to " | 469 help="Only use specifics build slaves, ex: '--bot win' to " |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 elif options.svn_repo: | 547 elif options.svn_repo: |
| 550 options.send_patch = _SendChangeSVN | 548 options.send_patch = _SendChangeSVN |
| 551 | 549 |
| 552 if len(args) == 1 and args[0] == 'help': | 550 if len(args) == 1 and args[0] == 'help': |
| 553 parser.print_help() | 551 parser.print_help() |
| 554 if (not options.files and (not options.issue and options.patchset) and | 552 if (not options.files and (not options.issue and options.patchset) and |
| 555 not options.diff and not options.url): | 553 not options.diff and not options.url): |
| 556 # TODO(maruel): It should just try the modified files showing up in a | 554 # TODO(maruel): It should just try the modified files showing up in a |
| 557 # svn status. | 555 # svn status. |
| 558 print "Nothing to try, changelist is empty." | 556 print "Nothing to try, changelist is empty." |
| 559 return | 557 return 1 |
| 560 | 558 |
| 561 try: | 559 try: |
| 562 # Convert options.diff into the content of the diff. | 560 # Convert options.diff into the content of the diff. |
| 563 if options.url: | 561 if options.url: |
| 564 options.diff = urllib.urlopen(options.url).read() | 562 options.diff = urllib.urlopen(options.url).read() |
| 565 elif options.diff: | 563 elif options.diff: |
| 566 options.diff = gcl.ReadFile(options.diff) | 564 options.diff = gcl.ReadFile(options.diff) |
| 567 # Process the VCS in any case at least to retrieve the email address. | 565 # Process the VCS in any case at least to retrieve the email address. |
| 568 try: | 566 try: |
| 569 options.scm = GuessVCS(options) | 567 options.scm = GuessVCS(options) |
| 570 options.scm.ProcessOptions() | 568 options.scm.ProcessOptions() |
| 571 except NoTryServerAccess, e: | 569 except NoTryServerAccess, e: |
| 572 # If we got the diff, we don't care. | 570 # If we got the diff, we don't care. |
| 573 if not options.diff: | 571 if not options.diff: |
| 574 raise | 572 raise |
| 575 | 573 |
| 576 # Get try slaves from PRESUBMIT.py files if not specified. | 574 # Get try slaves from PRESUBMIT.py files if not specified. |
| 577 if not options.bot: | 575 if not options.bot: |
| 576 if options.url: | |
|
Nicolas Sylvain
2009/11/03 18:49:00
why? It makes total sense to me to specify url byt
| |
| 577 print('You need to specify which bots to use.') | |
| 578 return 1 | |
| 578 root_presubmit = gcl.GetCachedFile('PRESUBMIT.py', use_root=True) | 579 root_presubmit = gcl.GetCachedFile('PRESUBMIT.py', use_root=True) |
| 579 options.bot = presubmit_support.DoGetTrySlaves(options.scm.GetFileNames(), | 580 options.bot = presubmit_support.DoGetTrySlaves(options.scm.GetFileNames(), |
| 580 options.scm.GetLocalRoot(), | 581 options.scm.GetLocalRoot(), |
| 581 root_presubmit, | 582 root_presubmit, |
| 582 False, | 583 False, |
| 583 sys.stdout) | 584 sys.stdout) |
| 584 | 585 |
| 586 if options.name is None: | |
| 587 if options.issue: | |
| 588 patch_name = 'Issue %s' % options.issue | |
| 589 else: | |
| 590 options.name = 'Unnamed' | |
| 591 print('Note: use --name NAME to change the try job name.') | |
| 592 if not options.email: | |
| 593 print('Warning: try job email will be sent to %s@google.com or ' | |
| 594 'something like that. Who knows? Set EMAIL_ADDRESS to override.' | |
| 595 % option.user) | |
| 596 | |
| 585 # Send the patch. | 597 # Send the patch. |
| 586 patch_name = options.send_patch(options) | 598 options.send_patch(options) |
| 587 print 'Patch \'%s\' sent to try server: %s' % (patch_name, | 599 print 'Patch \'%s\' sent to try server: %s' % (options.name, |
| 588 ', '.join(options.bot)) | 600 ', '.join(options.bot)) |
| 589 if patch_name == 'Unnamed': | |
| 590 print "Note: use --name NAME to change the try's name." | |
| 591 except (InvalidScript, NoTryServerAccess), e: | 601 except (InvalidScript, NoTryServerAccess), e: |
| 592 if swallow_exception: | 602 if swallow_exception: |
| 593 return | 603 return 1 |
| 594 print e | 604 print e |
| 605 return 1 | |
| 606 return 0 | |
| 595 | 607 |
| 596 | 608 |
| 597 if __name__ == "__main__": | 609 if __name__ == "__main__": |
| 598 TryChange(None, None, False) | 610 sys.exit(TryChange(None, None, False)) |
| OLD | NEW |