Chromium Code Reviews| 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 """Commit queue executable. | 5 """Commit queue executable. |
| 6 | 6 |
| 7 Reuse Rietveld and the Chromium Try Server to process and automatically commit | 7 Reuse Rietveld and the Chromium Try Server to process and automatically commit |
| 8 patches. | 8 patches. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 if issue == self._only_issue: | 51 if issue == self._only_issue: |
| 52 data['commit'] = True | 52 data['commit'] = True |
| 53 return data | 53 return data |
| 54 | 54 |
| 55 def set_flag(self, issue, patchset, flag, value): | 55 def set_flag(self, issue, patchset, flag, value): |
| 56 if issue == self._only_issue and flag == 'commit' and value == 'False': | 56 if issue == self._only_issue and flag == 'commit' and value == 'False': |
| 57 self._only_issue = None | 57 self._only_issue = None |
| 58 return super(OnlyIssueRietveld, self).set_flag(issue, patchset, flag, value) | 58 return super(OnlyIssueRietveld, self).set_flag(issue, patchset, flag, value) |
| 59 | 59 |
| 60 | 60 |
| 61 class ReadOnlyRietveld(rietveld.Rietveld): | |
| 62 def __init__(self, url, email, password, extra_headers, only_issue): | |
| 63 super(ReadOnlyRietveld, self).__init__(url, email, password, extra_headers) | |
| 64 self._only_issue = only_issue | |
| 65 self._restricted = bool(only_issue) | |
| 66 | |
| 67 def _send(self, request_path, **kwargs): | |
| 68 """Ignore all post requests.""" | |
| 69 if kwargs.get('payload'): | |
| 70 logging.warn('Ignoring POST to %s', request_path) | |
| 71 return | |
| 72 return super(ReadOnlyRietveld, self)._send(request_path, **kwargs) | |
| 73 | |
| 74 def get_pending_issues(self): | |
| 75 """If it's set to return a single issue, only return this one.""" | |
| 76 if self._restricted: | |
| 77 if self._only_issue: | |
| 78 return [self._only_issue] | |
| 79 return [] | |
| 80 return super(ReadOnlyRietveld, self).get_pending_issues() | |
| 81 | |
| 82 def get_issue_properties(self, issue, messages): | |
| 83 """Hacks the result to fake that the issue has the commit bit set.""" | |
| 84 data = super(ReadOnlyRietveld, self).get_issue_properties(issue, messages) | |
| 85 if issue == self._only_issue: | |
| 86 data['commit'] = True | |
| 87 return data | |
| 88 | |
| 89 def set_flag(self, issue, patchset, flag, value): | |
| 90 if issue == self._only_issue and flag == 'commit' and value == 'False': | |
| 91 self._only_issue = None | |
| 92 return super(ReadOnlyRietveld, self).set_flag(issue, patchset, flag, value) | |
| 93 | |
| 94 | |
| 95 class FakeCheckout(object): | 61 class FakeCheckout(object): |
| 96 def __init__(self): | 62 def __init__(self): |
| 97 self.project_path = os.getcwd() | 63 self.project_path = os.getcwd() |
| 98 self.project_name = os.path.basename(self.project_path) | 64 self.project_name = os.path.basename(self.project_path) |
| 99 | 65 |
| 100 @staticmethod | 66 @staticmethod |
| 101 def prepare(_revision): | 67 def prepare(_revision): |
| 102 logging.info('FakeCheckout is syncing') | 68 logging.info('FakeCheckout is syncing') |
| 103 return 'FAKE' | 69 return unicode('FAKE') |
|
iannucci
2013/09/20 23:42:53
u'FAKE' ?
What is this fixing (I'm assuming somet
Paweł Hajdan Jr.
2013/09/21 01:40:27
It's fixing an exception that unicode is expected
| |
| 104 | 70 |
| 105 @staticmethod | 71 @staticmethod |
| 106 def apply_patch(*_args): | 72 def apply_patch(*_args): |
| 107 logging.info('FakeCheckout is applying a patch') | 73 logging.info('FakeCheckout is applying a patch') |
| 108 | 74 |
| 109 @staticmethod | 75 @staticmethod |
| 110 def commit(*_args): | 76 def commit(*_args): |
| 111 logging.info('FakeCheckout is committing patch') | 77 logging.info('FakeCheckout is committing patch') |
| 112 return 'FAKED' | 78 return 'FAKED' |
| 113 | 79 |
| 114 @staticmethod | 80 @staticmethod |
| 115 def get_settings(_key): | 81 def get_settings(_key): |
| 116 return None | 82 return None |
| 117 | 83 |
| 84 @staticmethod | |
| 85 def revisions(*_args): | |
| 86 return None | |
| 87 | |
| 118 | 88 |
| 119 def AlertOnUncleanCheckout(): | 89 def AlertOnUncleanCheckout(): |
| 120 """Sends an alert if the cq is running live with local edits.""" | 90 """Sends an alert if the cq is running live with local edits.""" |
| 121 diff = subprocess2.capture(['gclient', 'diff'], cwd=ROOT_DIR).strip() | 91 diff = subprocess2.capture(['gclient', 'diff'], cwd=ROOT_DIR).strip() |
| 122 if diff: | 92 if diff: |
| 123 cq_alerts.SendAlert( | 93 cq_alerts.SendAlert( |
| 124 'CQ running with local diff.', | 94 'CQ running with local diff.', |
| 125 ('Ruh-roh! Commit queue was started with an unclean checkout.\n\n' | 95 ('Ruh-roh! Commit queue was started with an unclean checkout.\n\n' |
| 126 '$ gclient diff\n%s' % diff)) | 96 '$ gclient diff\n%s' % diff)) |
| 127 | 97 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 try: | 181 try: |
| 212 work_dir = os.path.join(ROOT_DIR, 'workdir') | 182 work_dir = os.path.join(ROOT_DIR, 'workdir') |
| 213 # Use our specific subversion config. | 183 # Use our specific subversion config. |
| 214 checkout.SvnMixIn.svn_config = checkout.SvnConfig( | 184 checkout.SvnMixIn.svn_config = checkout.SvnConfig( |
| 215 os.path.join(ROOT_DIR, 'subversion_config')) | 185 os.path.join(ROOT_DIR, 'subversion_config')) |
| 216 | 186 |
| 217 url = 'https://chromiumcodereview.appspot.com' | 187 url = 'https://chromiumcodereview.appspot.com' |
| 218 gaia_creds = creds.Credentials(os.path.join(work_dir, '.gaia_pwd')) | 188 gaia_creds = creds.Credentials(os.path.join(work_dir, '.gaia_pwd')) |
| 219 if options.dry_run: | 189 if options.dry_run: |
| 220 logging.debug('Dry run - skipping SCM check.') | 190 logging.debug('Dry run - skipping SCM check.') |
| 221 if options.only_issue: | 191 if options.only_issue: |
|
Isaac (away)
2013/09/21 09:32:49
How come we're blocking this case now? I think th
Paweł Hajdan Jr.
2013/09/24 02:40:43
Isaac, do you consider this blocking the CL or jus
| |
| 222 print( | 192 parser.error('--only-issue is not supported with dry run') |
| 223 'Using read-only Rietveld; using only issue %d' % | |
| 224 options.only_issue) | |
| 225 else: | 193 else: |
| 226 print('Using read-only Rietveld') | 194 print('Using read-only Rietveld') |
| 227 # Make sure rietveld is not modified. | 195 # Make sure rietveld is not modified. |
| 228 rietveld_obj = ReadOnlyRietveld( | 196 rietveld_obj = rietveld.ReadOnlyRietveld( |
| 229 url, | 197 url, |
| 230 options.user, | 198 options.user, |
| 231 gaia_creds.get(options.user), | 199 gaia_creds.get(options.user), |
| 232 None, | 200 None) |
| 233 options.only_issue) | |
| 234 else: | 201 else: |
| 235 AlertOnUncleanCheckout() | 202 AlertOnUncleanCheckout() |
| 236 print('WARNING: The Commit Queue is going to commit stuff') | 203 print('WARNING: The Commit Queue is going to commit stuff') |
| 237 if options.only_issue: | 204 if options.only_issue: |
| 238 print('Using only issue %d' % options.only_issue) | 205 print('Using only issue %d' % options.only_issue) |
| 239 rietveld_obj = OnlyIssueRietveld( | 206 rietveld_obj = OnlyIssueRietveld( |
| 240 url, | 207 url, |
| 241 options.user, | 208 options.user, |
| 242 gaia_creds.get(options.user), | 209 gaia_creds.get(options.user), |
| 243 None, | 210 None, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 return 23 | 320 return 23 |
| 354 except errors.ConfigurationError as e: | 321 except errors.ConfigurationError as e: |
| 355 parser.error(str(e)) | 322 parser.error(str(e)) |
| 356 return 1 | 323 return 1 |
| 357 return 0 | 324 return 0 |
| 358 | 325 |
| 359 | 326 |
| 360 if __name__ == '__main__': | 327 if __name__ == '__main__': |
| 361 fix_encoding.fix_encoding() | 328 fix_encoding.fix_encoding() |
| 362 sys.exit(main()) | 329 sys.exit(main()) |
| OLD | NEW |