| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 | 5 |
| 6 """Client-side script to send a try job to the try server. It communicates to | 6 """Client-side script to send a try job to the try server. It communicates to |
| 7 the try server by either writting to a svn repository or by directly connecting | 7 the try server by either writting to a svn repository or by directly connecting |
| 8 to the server by HTTP. | 8 to the server by HTTP. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import datetime | 11 import datetime |
| 12 import errno | 12 import errno |
| 13 import getpass | 13 import getpass |
| 14 import itertools | 14 import itertools |
| 15 import json | 15 import json |
| 16 import logging | 16 import logging |
| 17 import optparse | 17 import optparse |
| 18 import os | 18 import os |
| 19 import posixpath | 19 import posixpath |
| 20 import re | 20 import re |
| 21 import shutil | 21 import shutil |
| 22 import sys | 22 import sys |
| 23 import tempfile | 23 import tempfile |
| 24 import urllib | 24 import urllib |
| 25 import urllib2 |
| 25 | 26 |
| 26 import breakpad # pylint: disable=W0611 | 27 import breakpad # pylint: disable=W0611 |
| 27 | 28 |
| 28 import gcl | 29 import gcl |
| 29 import fix_encoding | 30 import fix_encoding |
| 30 import gclient_utils | 31 import gclient_utils |
| 31 import scm | 32 import scm |
| 32 import subprocess2 | 33 import subprocess2 |
| 33 | 34 |
| 34 | 35 |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 raise NoTryServerAccess('Please use the --host option to specify the try ' | 437 raise NoTryServerAccess('Please use the --host option to specify the try ' |
| 437 'server host to connect to.') | 438 'server host to connect to.') |
| 438 if not options.port: | 439 if not options.port: |
| 439 raise NoTryServerAccess('Please use the --port option to specify the try ' | 440 raise NoTryServerAccess('Please use the --port option to specify the try ' |
| 440 'server port to connect to.') | 441 'server port to connect to.') |
| 441 | 442 |
| 442 values = _ParseSendChangeOptions(bot_spec, options) | 443 values = _ParseSendChangeOptions(bot_spec, options) |
| 443 values.append(('patch', options.diff)) | 444 values.append(('patch', options.diff)) |
| 444 | 445 |
| 445 url = 'http://%s:%s/send_try_patch' % (options.host, options.port) | 446 url = 'http://%s:%s/send_try_patch' % (options.host, options.port) |
| 446 proxies = None | |
| 447 if options.proxy: | |
| 448 if options.proxy.lower() == 'none': | |
| 449 # Effectively disable HTTP_PROXY or Internet settings proxy setup. | |
| 450 proxies = {} | |
| 451 else: | |
| 452 proxies = {'http': options.proxy, 'https': options.proxy} | |
| 453 | 447 |
| 454 logging.info('Sending by HTTP') | 448 logging.info('Sending by HTTP') |
| 455 logging.info(''.join("%s=%s\n" % (k, v) for k, v in values)) | 449 logging.info(''.join("%s=%s\n" % (k, v) for k, v in values)) |
| 456 logging.info(url) | 450 logging.info(url) |
| 457 logging.info(options.diff) | 451 logging.info(options.diff) |
| 458 if options.dry_run: | 452 if options.dry_run: |
| 459 return | 453 return |
| 460 | 454 |
| 461 try: | 455 try: |
| 462 logging.info('Opening connection...') | 456 logging.info('Opening connection...') |
| 463 connection = urllib.urlopen(url, urllib.urlencode(values), proxies=proxies) | 457 connection = urllib2.urlopen(url, urllib.urlencode(values)) |
| 464 logging.info('Done') | 458 logging.info('Done') |
| 465 except IOError, e: | 459 except IOError, e: |
| 466 logging.info(str(e)) | 460 logging.info(str(e)) |
| 467 if bot_spec and len(e.args) > 2 and e.args[2] == 'got a bad status line': | 461 if bot_spec and len(e.args) > 2 and e.args[2] == 'got a bad status line': |
| 468 raise NoTryServerAccess('%s is unaccessible. Bad --bot argument?' % url) | 462 raise NoTryServerAccess('%s is unaccessible. Bad --bot argument?' % url) |
| 469 else: | 463 else: |
| 470 raise NoTryServerAccess('%s is unaccessible. Reason: %s' % (url, | 464 raise NoTryServerAccess('%s is unaccessible. Reason: %s' % (url, |
| 471 str(e.args))) | 465 str(e.args))) |
| 472 if not connection: | 466 if not connection: |
| 473 raise NoTryServerAccess('%s is unaccessible.' % url) | 467 raise NoTryServerAccess('%s is unaccessible.' % url) |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 group = optparse.OptionGroup(parser, "Access the try server by HTTP") | 708 group = optparse.OptionGroup(parser, "Access the try server by HTTP") |
| 715 group.add_option("--use_http", | 709 group.add_option("--use_http", |
| 716 action="store_const", | 710 action="store_const", |
| 717 const=_SendChangeHTTP, | 711 const=_SendChangeHTTP, |
| 718 dest="send_patch", | 712 dest="send_patch", |
| 719 help="Use HTTP to talk to the try server [default]") | 713 help="Use HTTP to talk to the try server [default]") |
| 720 group.add_option("-H", "--host", | 714 group.add_option("-H", "--host", |
| 721 help="Host address") | 715 help="Host address") |
| 722 group.add_option("-P", "--port", type="int", | 716 group.add_option("-P", "--port", type="int", |
| 723 help="HTTP port") | 717 help="HTTP port") |
| 724 group.add_option("--proxy", | |
| 725 help="HTTP proxy") | |
| 726 parser.add_option_group(group) | 718 parser.add_option_group(group) |
| 727 | 719 |
| 728 group = optparse.OptionGroup(parser, "Access the try server with SVN") | 720 group = optparse.OptionGroup(parser, "Access the try server with SVN") |
| 729 group.add_option("--use_svn", | 721 group.add_option("--use_svn", |
| 730 action="store_const", | 722 action="store_const", |
| 731 const=_SendChangeSVN, | 723 const=_SendChangeSVN, |
| 732 dest="send_patch", | 724 dest="send_patch", |
| 733 help="Use SVN to talk to the try server") | 725 help="Use SVN to talk to the try server") |
| 734 group.add_option("-S", "--svn_repo", | 726 group.add_option("-S", "--svn_repo", |
| 735 metavar="SVN_URL", | 727 metavar="SVN_URL", |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 can_svn = options.svn_repo | 826 can_svn = options.svn_repo |
| 835 # If there was no transport selected yet, now we must have enough data to | 827 # If there was no transport selected yet, now we must have enough data to |
| 836 # select one. | 828 # select one. |
| 837 if not options.send_patch and not (can_http or can_svn): | 829 if not options.send_patch and not (can_http or can_svn): |
| 838 parser.error('Please specify an access method.') | 830 parser.error('Please specify an access method.') |
| 839 | 831 |
| 840 # Convert options.diff into the content of the diff. | 832 # Convert options.diff into the content of the diff. |
| 841 if options.url: | 833 if options.url: |
| 842 if options.files: | 834 if options.files: |
| 843 parser.error('You cannot specify files and --url at the same time.') | 835 parser.error('You cannot specify files and --url at the same time.') |
| 844 options.diff = urllib.urlopen(options.url).read() | 836 options.diff = urllib2.urlopen(options.url).read() |
| 845 elif options.diff: | 837 elif options.diff: |
| 846 if options.files: | 838 if options.files: |
| 847 parser.error('You cannot specify files and --diff at the same time.') | 839 parser.error('You cannot specify files and --diff at the same time.') |
| 848 options.diff = gclient_utils.FileRead(options.diff, 'rb') | 840 options.diff = gclient_utils.FileRead(options.diff, 'rb') |
| 849 elif options.issue and options.patchset is None: | 841 elif options.issue and options.patchset is None: |
| 850 # Retrieve the patch from rietveld when the diff is not specified. | 842 # Retrieve the patch from rietveld when the diff is not specified. |
| 851 # When patchset is specified, it's because it's done by gcl/git-try. | 843 # When patchset is specified, it's because it's done by gcl/git-try. |
| 852 api_url = '%s/api/%d' % (options.rietveld_url, options.issue) | 844 api_url = '%s/api/%d' % (options.rietveld_url, options.issue) |
| 853 logging.debug(api_url) | 845 logging.debug(api_url) |
| 854 contents = json.loads(urllib.urlopen(api_url).read()) | 846 contents = json.loads(urllib2.urlopen(api_url).read()) |
| 855 options.patchset = contents['patchsets'][-1] | 847 options.patchset = contents['patchsets'][-1] |
| 856 diff_url = ('%s/download/issue%d_%d.diff' % | 848 diff_url = ('%s/download/issue%d_%d.diff' % |
| 857 (options.rietveld_url, options.issue, options.patchset)) | 849 (options.rietveld_url, options.issue, options.patchset)) |
| 858 diff = GetMungedDiff('', urllib.urlopen(diff_url).readlines()) | 850 diff = GetMungedDiff('', urllib2.urlopen(diff_url).readlines()) |
| 859 options.diff = ''.join(diff[0]) | 851 options.diff = ''.join(diff[0]) |
| 860 changed_files = diff[1] | 852 changed_files = diff[1] |
| 861 else: | 853 else: |
| 862 # Use this as the base. | 854 # Use this as the base. |
| 863 root = checkouts[0].checkout_root | 855 root = checkouts[0].checkout_root |
| 864 diffs = [] | 856 diffs = [] |
| 865 for checkout in checkouts: | 857 for checkout in checkouts: |
| 866 raw_diff = checkout.GenerateDiff() | 858 raw_diff = checkout.GenerateDiff() |
| 867 if not raw_diff: | 859 if not raw_diff: |
| 868 continue | 860 continue |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 return 1 | 928 return 1 |
| 937 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 929 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 938 print >> sys.stderr, e | 930 print >> sys.stderr, e |
| 939 return 1 | 931 return 1 |
| 940 return 0 | 932 return 0 |
| 941 | 933 |
| 942 | 934 |
| 943 if __name__ == "__main__": | 935 if __name__ == "__main__": |
| 944 fix_encoding.fix_encoding() | 936 fix_encoding.fix_encoding() |
| 945 sys.exit(TryChange(None, None, False)) | 937 sys.exit(TryChange(None, None, False)) |
| OLD | NEW |