| OLD | NEW |
| 1 # coding=utf8 | 1 # coding=utf8 |
| 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 manager class. | 5 """Commit queue manager class. |
| 6 | 6 |
| 7 Security implications: | 7 Security implications: |
| 8 | 8 |
| 9 The following hypothesis are made: | 9 The following hypothesis are made: |
| 10 - Commit queue: | 10 - Commit queue: |
| 11 - Impersonate the same svn credentials that the patchset owner. | 11 - Impersonate the same svn credentials that the patchset owner. |
| 12 - Can't impersonate a non committer. | 12 - Can't impersonate a non committer. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 def __init__(self): | 105 def __init__(self): |
| 106 super(PendingQueue, self).__init__() | 106 super(PendingQueue, self).__init__() |
| 107 self.pending_commits = [] | 107 self.pending_commits = [] |
| 108 | 108 |
| 109 | 109 |
| 110 class PendingManager(object): | 110 class PendingManager(object): |
| 111 """Fetch new issues from rietveld, pass the issues through all of verifiers | 111 """Fetch new issues from rietveld, pass the issues through all of verifiers |
| 112 and then commit the patches with checkout. | 112 and then commit the patches with checkout. |
| 113 """ | 113 """ |
| 114 | 114 |
| 115 def __init__(self, rietveld, checkout_obj, pre_patch_verifiers, verifiers): | 115 def __init__(self, rietveld, checkout_obj, pre_patch_verifiers, verifiers, |
| 116 post_process): |
| 116 """ | 117 """ |
| 117 Args: | 118 Args: |
| 118 pre_patch_verifiers: Verifiers objects that are run before applying the | 119 pre_patch_verifiers: Verifiers objects that are run before applying the |
| 119 patch. | 120 patch. |
| 120 verifiers: Verifiers object run after applying the patch. | 121 verifiers: Verifiers object run after applying the patch. |
| 122 post_process: List of lambda(checkout, patches) functions that post |
| 123 process an applied patch. |
| 121 """ | 124 """ |
| 122 assert len(pre_patch_verifiers) or len(verifiers) | 125 assert len(pre_patch_verifiers) or len(verifiers) |
| 123 self.rietveld = rietveld | 126 self.rietveld = rietveld |
| 124 self.checkout = checkout_obj | 127 self.checkout = checkout_obj |
| 125 self.pre_patch_verifiers = pre_patch_verifiers | 128 self.pre_patch_verifiers = pre_patch_verifiers or [] |
| 126 self.verifiers = verifiers | 129 self.verifiers = verifiers or [] |
| 130 self.post_process = post_process or [] |
| 127 self.all_verifiers = pre_patch_verifiers + verifiers | 131 self.all_verifiers = pre_patch_verifiers + verifiers |
| 128 self.queue = PendingQueue() | 132 self.queue = PendingQueue() |
| 129 # Assert names are unique. | 133 # Assert names are unique. |
| 130 names = [x.name for x in pre_patch_verifiers + verifiers] | 134 names = [x.name for x in pre_patch_verifiers + verifiers] |
| 131 assert len(names) == len(set(names)) | 135 assert len(names) == len(set(names)) |
| 132 | 136 |
| 133 def look_for_new_pending_commit(self): | 137 def look_for_new_pending_commit(self): |
| 134 """Looks for new reviews on self.rietveld with c+ set. | 138 """Looks for new reviews on self.rietveld with c+ set. |
| 135 | 139 |
| 136 Calls _new_pending_commit() on all new review found. | 140 Calls _new_pending_commit() on all new review found. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 patches = self.rietveld.get_patch(pending.issue, pending.patchset) | 293 patches = self.rietveld.get_patch(pending.issue, pending.patchset) |
| 290 if not patches: | 294 if not patches: |
| 291 raise base.DiscardPending( | 295 raise base.DiscardPending( |
| 292 pending, 'No diff was found for this patchset.') | 296 pending, 'No diff was found for this patchset.') |
| 293 if pending.relpath: | 297 if pending.relpath: |
| 294 patches.set_relpath(pending.relpath) | 298 patches.set_relpath(pending.relpath) |
| 295 pending.files = [p.filename for p in patches] | 299 pending.files = [p.filename for p in patches] |
| 296 if not pending.files: | 300 if not pending.files: |
| 297 raise base.DiscardPending( | 301 raise base.DiscardPending( |
| 298 pending, 'No file was found in this patchset.') | 302 pending, 'No file was found in this patchset.') |
| 299 self.checkout.apply_patch(patches) | 303 self.checkout.apply_patch(patches, self.post_process) |
| 300 except checkout.PatchApplicationFailed, e: | 304 except checkout.PatchApplicationFailed, e: |
| 301 out = 'Can\'t apply patch for file %s.' % e.filename | 305 out = 'Can\'t apply patch for file %s.' % e.filename |
| 302 if e.status: | 306 if e.status: |
| 303 out += '\n%s' % e.status | 307 out += '\n%s' % e.status |
| 304 raise base.DiscardPending(pending, out) | 308 raise base.DiscardPending(pending, out) |
| 305 except patch.UnsupportedPatchFormat, e: | 309 except patch.UnsupportedPatchFormat, e: |
| 306 raise base.DiscardPending(pending, str(e)) | 310 raise base.DiscardPending(pending, str(e)) |
| 307 except subprocess.CalledProcessError, e: | 311 except subprocess.CalledProcessError, e: |
| 308 stdout = getattr(e, 'stdout', '') | 312 stdout = getattr(e, 'stdout', '') |
| 309 out = 'Failed to apply the patch.' | 313 out = 'Failed to apply the patch.' |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 raise base.DiscardPending(pending, out) | 352 raise base.DiscardPending(pending, out) |
| 349 | 353 |
| 350 def load(self, filename): | 354 def load(self, filename): |
| 351 """Loads the commit queue state from a JSON file.""" | 355 """Loads the commit queue state from a JSON file.""" |
| 352 self.queue = model.load_from_json_file(filename) | 356 self.queue = model.load_from_json_file(filename) |
| 353 self.queue.pending_commits = self.queue.pending_commits or [] | 357 self.queue.pending_commits = self.queue.pending_commits or [] |
| 354 | 358 |
| 355 def save(self, filename): | 359 def save(self, filename): |
| 356 """Save the commit queue state in a simple JSON file.""" | 360 """Save the commit queue state in a simple JSON file.""" |
| 357 model.save_to_json_file(filename, self.queue) | 361 model.save_to_json_file(filename, self.queue) |
| OLD | NEW |