| 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 """Applies an issue from Rietveld. | 6 """Applies an issue from Rietveld. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import getpass | 9 import getpass |
| 10 import json |
| 10 import logging | 11 import logging |
| 11 import optparse | 12 import optparse |
| 12 import os | 13 import os |
| 13 import subprocess | 14 import subprocess |
| 14 import sys | 15 import sys |
| 15 import urllib2 | 16 import urllib2 |
| 16 | 17 |
| 17 import breakpad # pylint: disable=W0611 | 18 import breakpad # pylint: disable=W0611 |
| 18 | 19 |
| 20 import annotated_gclient |
| 19 import checkout | 21 import checkout |
| 20 import fix_encoding | 22 import fix_encoding |
| 21 import gclient_utils | 23 import gclient_utils |
| 22 import rietveld | 24 import rietveld |
| 23 import scm | 25 import scm |
| 24 | 26 |
| 25 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 27 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 26 | 28 |
| 27 | 29 |
| 28 class Unbuffered(object): | 30 class Unbuffered(object): |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 '--root_dir', | 62 '--root_dir', |
| 61 default=os.getcwd(), | 63 default=os.getcwd(), |
| 62 help='Root directory to apply the patch') | 64 help='Root directory to apply the patch') |
| 63 parser.add_option( | 65 parser.add_option( |
| 64 '-s', | 66 '-s', |
| 65 '--server', | 67 '--server', |
| 66 default='http://codereview.chromium.org', | 68 default='http://codereview.chromium.org', |
| 67 help='Rietveld server') | 69 help='Rietveld server') |
| 68 parser.add_option('--no-auth', action='store_true', | 70 parser.add_option('--no-auth', action='store_true', |
| 69 help='Do not attempt authenticated requests.') | 71 help='Do not attempt authenticated requests.') |
| 72 parser.add_option('--revision-mapping', default='{}', |
| 73 help='When running gclient, annotate the got_revisions ' |
| 74 'using the revision-mapping.') |
| 70 options, args = parser.parse_args() | 75 options, args = parser.parse_args() |
| 71 logging.basicConfig( | 76 logging.basicConfig( |
| 72 format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', | 77 format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', |
| 73 level=[logging.WARNING, logging.INFO, logging.DEBUG][ | 78 level=[logging.WARNING, logging.INFO, logging.DEBUG][ |
| 74 min(2, options.verbose)]) | 79 min(2, options.verbose)]) |
| 75 if args: | 80 if args: |
| 76 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) | 81 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) |
| 77 if not options.issue: | 82 if not options.issue: |
| 78 parser.error('Require --issue') | 83 parser.error('Require --issue') |
| 79 options.server = options.server.rstrip('/') | 84 options.server = options.server.rstrip('/') |
| 80 if not options.server: | 85 if not options.server: |
| 81 parser.error('Require a valid server') | 86 parser.error('Require a valid server') |
| 82 | 87 |
| 88 options.revision_mapping = json.loads(options.revision_mapping) |
| 89 |
| 83 if options.password == '-': | 90 if options.password == '-': |
| 84 print('Reading password') | 91 print('Reading password') |
| 85 options.password = sys.stdin.readline().strip() | 92 options.password = sys.stdin.readline().strip() |
| 86 | 93 |
| 87 print('Connecting to %s' % options.server) | 94 print('Connecting to %s' % options.server) |
| 88 # Always try un-authenticated first. | 95 # Always try un-authenticated first. |
| 89 # TODO(maruel): Use OAuth2 properly so we don't hit rate-limiting on login | 96 # TODO(maruel): Use OAuth2 properly so we don't hit rate-limiting on login |
| 90 # attempts. | 97 # attempts. |
| 91 # Bad except clauses order (HTTPError is an ancestor class of | 98 # Bad except clauses order (HTTPError is an ancestor class of |
| 92 # ClientLoginError) | 99 # ClientLoginError) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 if 'DEPS' in map(os.path.basename, patchset.filenames): | 178 if 'DEPS' in map(os.path.basename, patchset.filenames): |
| 172 gclient_root = gclient_utils.FindGclientRoot(full_dir) | 179 gclient_root = gclient_utils.FindGclientRoot(full_dir) |
| 173 if gclient_root and scm_type: | 180 if gclient_root and scm_type: |
| 174 print( | 181 print( |
| 175 'A DEPS file was updated inside a gclient checkout, running gclient ' | 182 'A DEPS file was updated inside a gclient checkout, running gclient ' |
| 176 'sync.') | 183 'sync.') |
| 177 base_rev = 'BASE' if scm_type == 'svn' else 'HEAD' | 184 base_rev = 'BASE' if scm_type == 'svn' else 'HEAD' |
| 178 gclient_path = os.path.join(BASE_DIR, 'gclient') | 185 gclient_path = os.path.join(BASE_DIR, 'gclient') |
| 179 if sys.platform == 'win32': | 186 if sys.platform == 'win32': |
| 180 gclient_path += '.bat' | 187 gclient_path += '.bat' |
| 181 return subprocess.call( | 188 with annotated_gclient.temp_filename('gclient') as f: |
| 182 [ | 189 cmd = [ |
| 183 gclient_path, 'sync', | 190 gclient_path, 'sync', |
| 184 '--revision', base_rev, | 191 '--revision', base_rev, |
| 185 '--nohooks', | 192 '--nohooks', |
| 186 '--delete_unversioned_trees', | 193 '--delete_unversioned_trees', |
| 187 ], | 194 ] |
| 188 cwd=gclient_root) | 195 if options.revision_mapping: |
| 196 cmd.extend(['--output-json', f]) |
| 197 |
| 198 retcode = subprocess.call(cmd, cwd=gclient_root) |
| 199 |
| 200 if retcode == 0 and options.revision_mapping: |
| 201 revisions = annotated_gclient.parse_got_revision( |
| 202 f, options.revision_mapping) |
| 203 annotated_gclient.emit_buildprops(revisions) |
| 204 |
| 205 return retcode |
| 189 return 0 | 206 return 0 |
| 190 | 207 |
| 191 | 208 |
| 192 if __name__ == "__main__": | 209 if __name__ == "__main__": |
| 193 fix_encoding.fix_encoding() | 210 fix_encoding.fix_encoding() |
| 194 sys.exit(main()) | 211 sys.exit(main()) |
| OLD | NEW |