| OLD | NEW |
| 1 # coding=utf8 | 1 # coding=utf8 |
| 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 """Defines base classes for pending change verification classes.""" | 5 """Defines base classes for pending change verification classes.""" |
| 6 | 6 |
| 7 import model | 7 import model |
| 8 | 8 |
| 9 | 9 |
| 10 # Verifier state in priority level. | 10 # Verifier state in priority level. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 """Exception to be raised when a pending item should be discarded.""" | 21 """Exception to be raised when a pending item should be discarded.""" |
| 22 | 22 |
| 23 def __init__(self, pending, status): | 23 def __init__(self, pending, status): |
| 24 super(DiscardPending, self).__init__(status) | 24 super(DiscardPending, self).__init__(status) |
| 25 self.pending = pending | 25 self.pending = pending |
| 26 self.status = status | 26 self.status = status |
| 27 | 27 |
| 28 | 28 |
| 29 class Verified(model.PersistentMixIn): | 29 class Verified(model.PersistentMixIn): |
| 30 """A set of verifications that are for a specific patch.""" | 30 """A set of verifications that are for a specific patch.""" |
| 31 persistent = [ | 31 verifications = dict |
| 32 'verifications', | |
| 33 ] | |
| 34 | |
| 35 def __init__(self): | |
| 36 super(Verified, self).__init__() | |
| 37 self.verifications = {} | |
| 38 | 32 |
| 39 def pending_name(self): | 33 def pending_name(self): |
| 40 raise NotImplementedError() | 34 raise NotImplementedError() |
| 41 | 35 |
| 42 def get_state(self): | 36 def get_state(self): |
| 43 """Returns the combined state of all the verifiers for this item. | 37 """Returns the combined state of all the verifiers for this item. |
| 44 | 38 |
| 45 Use priority with the states: IGNORED > FAILED > PROCESSING > SUCCEEDED. | 39 Use priority with the states: IGNORED > FAILED > PROCESSING > SUCCEEDED. |
| 46 """ | 40 """ |
| 47 # If there's an error message, it failed. | 41 # If there's an error message, it failed. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 66 out = (i.error_message for i in self.verifications.itervalues()) | 60 out = (i.error_message for i in self.verifications.itervalues()) |
| 67 return '\n\n'.join(filter(None, out)) | 61 return '\n\n'.join(filter(None, out)) |
| 68 | 62 |
| 69 def apply_patch(self, context, prepare): | 63 def apply_patch(self, context, prepare): |
| 70 """Applies a patch from the codereview tool to the checkout.""" | 64 """Applies a patch from the codereview tool to the checkout.""" |
| 71 raise NotImplementedError() | 65 raise NotImplementedError() |
| 72 | 66 |
| 73 | 67 |
| 74 class IVerifierStatus(model.PersistentMixIn): | 68 class IVerifierStatus(model.PersistentMixIn): |
| 75 """Interface for objects in Verified.verifications dictionary.""" | 69 """Interface for objects in Verified.verifications dictionary.""" |
| 76 persistent = [ | 70 error_message = (None, str) |
| 77 'error_message' | |
| 78 ] | |
| 79 | |
| 80 def __init__(self, error_message=None): | |
| 81 super(IVerifierStatus, self).__init__() | |
| 82 self.error_message = error_message | |
| 83 | 71 |
| 84 def get_state(self): | 72 def get_state(self): |
| 85 """See Verified.get_state().""" | 73 """See Verified.get_state().""" |
| 86 raise NotImplementedError() | 74 raise NotImplementedError() |
| 87 | 75 |
| 88 def postpone(self): # pylint: disable=R0201 | 76 def postpone(self): # pylint: disable=R0201 |
| 89 """See Verified.postpone().""" | 77 """See Verified.postpone().""" |
| 90 return False | 78 return False |
| 91 | 79 |
| 92 | 80 |
| 93 class SimpleStatus(IVerifierStatus): | 81 class SimpleStatus(IVerifierStatus): |
| 94 """Base class to be used for simple true/false verifiers.""" | 82 """Base class to be used for simple true/false verifiers.""" |
| 95 persistent = IVerifierStatus.persistent + [ | 83 state = int |
| 96 'state', | |
| 97 ] | |
| 98 | 84 |
| 99 def __init__(self, state=PROCESSING, error_message=None): | 85 def __init__(self, state=PROCESSING, **kwargs): |
| 100 super(SimpleStatus, self).__init__(error_message) | 86 super(SimpleStatus, self).__init__(state=state, **kwargs) |
| 101 self.state = state | |
| 102 | 87 |
| 103 def get_state(self): | 88 def get_state(self): |
| 104 return self.state | 89 return self.state |
| 105 | 90 |
| 106 | 91 |
| 107 class Verifier(object): | 92 class Verifier(object): |
| 108 name = None | 93 name = None |
| 109 | 94 |
| 110 def __init__(self): | 95 def __init__(self): |
| 111 assert self.name is not None | 96 assert self.name is not None |
| (...skipping 30 matching lines...) Expand all Loading... |
| 142 When verify() is called, it is guaranteed that the patch is applied on the | 127 When verify() is called, it is guaranteed that the patch is applied on the |
| 143 checkout. | 128 checkout. |
| 144 """ | 129 """ |
| 145 def __init__(self, context_obj): | 130 def __init__(self, context_obj): |
| 146 super(VerifierCheckout, self).__init__() | 131 super(VerifierCheckout, self).__init__() |
| 147 self.context = context_obj | 132 self.context = context_obj |
| 148 | 133 |
| 149 def send_status(self, pending, data): | 134 def send_status(self, pending, data): |
| 150 self.context.status.send( | 135 self.context.status.send( |
| 151 pending, {'verification': self.name, 'payload': data}) | 136 pending, {'verification': self.name, 'payload': data}) |
| OLD | NEW |