| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 254 |
| 255 url = 'http://%s:%s/send_try_patch' % (options.host, options.port) | 255 url = 'http://%s:%s/send_try_patch' % (options.host, options.port) |
| 256 proxies = None | 256 proxies = None |
| 257 if options.proxy: | 257 if options.proxy: |
| 258 if options.proxy.lower() == 'none': | 258 if options.proxy.lower() == 'none': |
| 259 # Effectively disable HTTP_PROXY or Internet settings proxy setup. | 259 # Effectively disable HTTP_PROXY or Internet settings proxy setup. |
| 260 proxies = {} | 260 proxies = {} |
| 261 else: | 261 else: |
| 262 proxies = {'http': options.proxy, 'https': options.proxy} | 262 proxies = {'http': options.proxy, 'https': options.proxy} |
| 263 | 263 |
| 264 logging.warning('Sending by HTTP') |
| 264 logging.info(description) | 265 logging.info(description) |
| 265 logging.info(url) | 266 logging.info(url) |
| 266 logging.info(options.diff) | 267 logging.info(options.diff) |
| 267 if options.dry_run: | 268 if options.dry_run: |
| 268 return | 269 return |
| 269 | 270 |
| 270 try: | 271 try: |
| 271 connection = urllib.urlopen(url, urllib.urlencode(values), proxies=proxies) | 272 connection = urllib.urlopen(url, urllib.urlencode(values), proxies=proxies) |
| 272 except IOError, e: | 273 except IOError, e: |
| 273 logging.warning(str(e)) | 274 logging.warning(str(e)) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 286 | 287 |
| 287 def _SendChangeSVN(options): | 288 def _SendChangeSVN(options): |
| 288 """Send a change to the try server by committing a diff file on a subversion | 289 """Send a change to the try server by committing a diff file on a subversion |
| 289 server.""" | 290 server.""" |
| 290 if not options.svn_repo: | 291 if not options.svn_repo: |
| 291 raise NoTryServerAccess('Please use the --svn_repo option to specify the' | 292 raise NoTryServerAccess('Please use the --svn_repo option to specify the' |
| 292 ' try server svn repository to connect to.') | 293 ' try server svn repository to connect to.') |
| 293 | 294 |
| 294 values = _ParseSendChangeOptions(options) | 295 values = _ParseSendChangeOptions(options) |
| 295 description = ''.join("%s=%s\n" % (k,v) for (k,v) in values.iteritems()) | 296 description = ''.join("%s=%s\n" % (k,v) for (k,v) in values.iteritems()) |
| 297 logging.warning('Sending by SVN') |
| 296 logging.info(description) | 298 logging.info(description) |
| 297 logging.info(options.svn_repo) | 299 logging.info(options.svn_repo) |
| 298 logging.info(options.diff) | 300 logging.info(options.diff) |
| 299 if options.dry_run: | 301 if options.dry_run: |
| 300 return | 302 return |
| 301 | 303 |
| 302 # Do an empty checkout. | 304 # Do an empty checkout. |
| 303 temp_dir = tempfile.mkdtemp() | 305 temp_dir = tempfile.mkdtemp() |
| 304 temp_file = tempfile.NamedTemporaryFile() | 306 temp_file = tempfile.NamedTemporaryFile() |
| 305 try: | 307 try: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 gclient_utils.CheckCall(["svn", "commit", full_path, '--file', | 340 gclient_utils.CheckCall(["svn", "commit", full_path, '--file', |
| 339 temp_file.name], print_error=False) | 341 temp_file.name], print_error=False) |
| 340 except gclient_utils.CheckCallError, e: | 342 except gclient_utils.CheckCallError, e: |
| 341 raise NoTryServerAccess(' '.join(e.command) + '\nOuput:\n' + | 343 raise NoTryServerAccess(' '.join(e.command) + '\nOuput:\n' + |
| 342 e.stdout) | 344 e.stdout) |
| 343 finally: | 345 finally: |
| 344 temp_file.close() | 346 temp_file.close() |
| 345 shutil.rmtree(temp_dir, True) | 347 shutil.rmtree(temp_dir, True) |
| 346 | 348 |
| 347 | 349 |
| 350 def PrintSuccess(options): |
| 351 if not options.dry_run: |
| 352 text = 'Patch \'%s\' sent to try server' % options.name |
| 353 if options.bot: |
| 354 text += ': %s' % ', '.join(options.bot) |
| 355 print(text) |
| 356 |
| 357 |
| 348 def GuessVCS(options, cwd): | 358 def GuessVCS(options, cwd): |
| 349 """Helper to guess the version control system. | 359 """Helper to guess the version control system. |
| 350 | 360 |
| 351 NOTE: Very similar to upload.GuessVCS. Doesn't look for hg since we don't | 361 NOTE: Very similar to upload.GuessVCS. Doesn't look for hg since we don't |
| 352 support it yet. | 362 support it yet. |
| 353 | 363 |
| 354 This examines the current directory, guesses which SCM we're using, and | 364 This examines the current directory, guesses which SCM we're using, and |
| 355 returns an instance of the appropriate class. Exit with an error if we can't | 365 returns an instance of the appropriate class. Exit with an error if we can't |
| 356 figure it out. | 366 figure it out. |
| 357 | 367 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 checkouts = [] | 514 checkouts = [] |
| 505 checkouts.append(GuessVCS(options, os.getcwd())) | 515 checkouts.append(GuessVCS(options, os.getcwd())) |
| 506 checkouts[0].AutomagicalSettings() | 516 checkouts[0].AutomagicalSettings() |
| 507 for item in options.sub_rep: | 517 for item in options.sub_rep: |
| 508 checkout = GuessVCS(options, item) | 518 checkout = GuessVCS(options, item) |
| 509 if checkout.GetLocalRoot() in [c.GetLocalRoot() for c in checkouts]: | 519 if checkout.GetLocalRoot() in [c.GetLocalRoot() for c in checkouts]: |
| 510 parser.error('Specified the root %s two times.' % | 520 parser.error('Specified the root %s two times.' % |
| 511 checkout.GetLocalRoot()) | 521 checkout.GetLocalRoot()) |
| 512 checkouts.append(checkout) | 522 checkouts.append(checkout) |
| 513 | 523 |
| 524 can_http = options.port and options.host |
| 525 can_svn = options.svn_repo |
| 514 # If there was no transport selected yet, now we must have enough data to | 526 # If there was no transport selected yet, now we must have enough data to |
| 515 # select one. | 527 # select one. |
| 516 if not options.send_patch: | 528 if not options.send_patch and not (can_http or can_svn): |
| 517 if options.port and options.host: | 529 parser.error('Please specify an access method.') |
| 518 options.send_patch = _SendChangeHTTP | |
| 519 elif options.svn_repo: | |
| 520 options.send_patch = _SendChangeSVN | |
| 521 else: | |
| 522 parser.error('Please specify an access method.') | |
| 523 | 530 |
| 524 # Convert options.diff into the content of the diff. | 531 # Convert options.diff into the content of the diff. |
| 525 if options.url: | 532 if options.url: |
| 526 if options.files: | 533 if options.files: |
| 527 parser.error('You cannot specify files and --url at the same time.') | 534 parser.error('You cannot specify files and --url at the same time.') |
| 528 options.diff = urllib.urlopen(options.url).read() | 535 options.diff = urllib.urlopen(options.url).read() |
| 529 elif options.diff: | 536 elif options.diff: |
| 530 if options.files: | 537 if options.files: |
| 531 parser.error('You cannot specify files and --diff at the same time.') | 538 parser.error('You cannot specify files and --diff at the same time.') |
| 532 options.diff = gclient_utils.FileRead(options.diff, 'rb') | 539 options.diff = gclient_utils.FileRead(options.diff, 'rb') |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 else: | 575 else: |
| 569 options.name = 'Unnamed' | 576 options.name = 'Unnamed' |
| 570 print('Note: use --name NAME to change the try job name.') | 577 print('Note: use --name NAME to change the try job name.') |
| 571 if not options.email: | 578 if not options.email: |
| 572 parser.error('Using an anonymous checkout. Please use --email or set ' | 579 parser.error('Using an anonymous checkout. Please use --email or set ' |
| 573 'the TRYBOT_RESULTS_EMAIL_ADDRESS environment variable.') | 580 'the TRYBOT_RESULTS_EMAIL_ADDRESS environment variable.') |
| 574 else: | 581 else: |
| 575 print('Results will be emailed to: ' + options.email) | 582 print('Results will be emailed to: ' + options.email) |
| 576 | 583 |
| 577 # Send the patch. | 584 # Send the patch. |
| 578 options.send_patch(options) | 585 if options.send_patch: |
| 579 if not options.dry_run: | 586 # If forced. |
| 580 text = 'Patch \'%s\' sent to try server' % options.name | 587 options.send_patch(options) |
| 581 if options.bot: | 588 PrintSuccess(options) |
| 582 text += ': %s' % ', '.join(options.bot) | 589 return 0 |
| 583 print(text) | 590 try: |
| 591 if can_http: |
| 592 _SendChangeHTTP(options) |
| 593 PrintSuccess(options) |
| 594 return 0 |
| 595 except NoTryServerAccess: |
| 596 if not can_svn: |
| 597 raise |
| 598 _SendChangeSVN(options) |
| 599 PrintSuccess(options) |
| 600 return 0 |
| 584 except (InvalidScript, NoTryServerAccess), e: | 601 except (InvalidScript, NoTryServerAccess), e: |
| 585 if swallow_exception: | 602 if swallow_exception: |
| 586 return 1 | 603 return 1 |
| 587 print e | 604 print e |
| 588 return 1 | 605 return 1 |
| 589 return 0 | 606 return 0 |
| 590 | 607 |
| 591 | 608 |
| 592 if __name__ == "__main__": | 609 if __name__ == "__main__": |
| 593 sys.exit(TryChange(None, [], False)) | 610 sys.exit(TryChange(None, [], False)) |
| OLD | NEW |