| 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 json |
| 14 import logging | 15 import logging |
| 15 import optparse | 16 import optparse |
| 16 import os | 17 import os |
| 17 import posixpath | 18 import posixpath |
| 18 import re | 19 import re |
| 19 import shutil | 20 import shutil |
| 20 import sys | 21 import sys |
| 21 import tempfile | 22 import tempfile |
| 22 import urllib | 23 import urllib |
| 23 | 24 |
| 24 try: | |
| 25 import simplejson as json # pylint: disable=F0401 | |
| 26 except ImportError: | |
| 27 try: | |
| 28 import json # pylint: disable=F0401 | |
| 29 except ImportError: | |
| 30 # Import the one included in depot_tools. | |
| 31 sys.path.append(os.path.join(os.path.dirname(__file__), 'third_party')) | |
| 32 import simplejson as json # pylint: disable=F0401 | |
| 33 | |
| 34 import breakpad # pylint: disable=W0611 | 25 import breakpad # pylint: disable=W0611 |
| 35 | 26 |
| 36 import gcl | 27 import gcl |
| 37 import fix_encoding | 28 import fix_encoding |
| 38 import gclient_utils | 29 import gclient_utils |
| 39 import scm | 30 import scm |
| 40 import subprocess2 | 31 import subprocess2 |
| 41 | 32 |
| 42 | 33 |
| 43 __version__ = '1.2' | 34 __version__ = '1.2' |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 if options.files: | 728 if options.files: |
| 738 parser.error('You cannot specify files and --url at the same time.') | 729 parser.error('You cannot specify files and --url at the same time.') |
| 739 options.diff = urllib.urlopen(options.url).read() | 730 options.diff = urllib.urlopen(options.url).read() |
| 740 elif options.diff: | 731 elif options.diff: |
| 741 if options.files: | 732 if options.files: |
| 742 parser.error('You cannot specify files and --diff at the same time.') | 733 parser.error('You cannot specify files and --diff at the same time.') |
| 743 options.diff = gclient_utils.FileRead(options.diff, 'rb') | 734 options.diff = gclient_utils.FileRead(options.diff, 'rb') |
| 744 elif options.issue and options.patchset is None: | 735 elif options.issue and options.patchset is None: |
| 745 # Retrieve the patch from rietveld when the diff is not specified. | 736 # Retrieve the patch from rietveld when the diff is not specified. |
| 746 # When patchset is specified, it's because it's done by gcl/git-try. | 737 # When patchset is specified, it's because it's done by gcl/git-try. |
| 747 if json is None: | |
| 748 parser.error('json or simplejson library is missing, please install.') | |
| 749 api_url = '%s/api/%d' % (options.rietveld_url, options.issue) | 738 api_url = '%s/api/%d' % (options.rietveld_url, options.issue) |
| 750 logging.debug(api_url) | 739 logging.debug(api_url) |
| 751 contents = json.loads(urllib.urlopen(api_url).read()) | 740 contents = json.loads(urllib.urlopen(api_url).read()) |
| 752 options.patchset = contents['patchsets'][-1] | 741 options.patchset = contents['patchsets'][-1] |
| 753 diff_url = ('%s/download/issue%d_%d.diff' % | 742 diff_url = ('%s/download/issue%d_%d.diff' % |
| 754 (options.rietveld_url, options.issue, options.patchset)) | 743 (options.rietveld_url, options.issue, options.patchset)) |
| 755 diff = GetMungedDiff('', urllib.urlopen(diff_url).readlines()) | 744 diff = GetMungedDiff('', urllib.urlopen(diff_url).readlines()) |
| 756 options.diff = ''.join(diff[0]) | 745 options.diff = ''.join(diff[0]) |
| 757 changed_files = diff[1] | 746 changed_files = diff[1] |
| 758 else: | 747 else: |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 return 1 | 837 return 1 |
| 849 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 838 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 850 print >> sys.stderr, e | 839 print >> sys.stderr, e |
| 851 return 1 | 840 return 1 |
| 852 return 0 | 841 return 0 |
| 853 | 842 |
| 854 | 843 |
| 855 if __name__ == "__main__": | 844 if __name__ == "__main__": |
| 856 fix_encoding.fix_encoding() | 845 fix_encoding.fix_encoding() |
| 857 sys.exit(TryChange(None, None, False)) | 846 sys.exit(TryChange(None, None, False)) |
| OLD | NEW |