Source code for runway.cfngin.status

"""CFNgin statuses."""
import operator
from typing import Any, Callable, Optional


[docs]class Status: """CFNgin status base class. Attributes: name: Name of the status. code: Status code. reason: Reason for the status. """ code: int name: str reason: Optional[str]
[docs] def __init__(self, name: str, code: int, reason: Optional[str] = None) -> None: """Instantiate class. Args: name: Name of the status. code: Status code. reason: Reason for the status. """ self.name = name self.code = code self.reason = reason or getattr(self, "reason", None)
def _comparison(self, operator_: Callable[[Any, Any], bool], other: Any) -> bool: """Compare self to another object. Args: operator_: Operator for the comparison. other: The other object to compare to self. Raises: NotImplemented: other does not have ``code`` attribute. """ if hasattr(other, "code"): return operator_(self.code, other.code) return NotImplemented
[docs] def __eq__(self, other: Any) -> bool: """Compare if self is equal to another object.""" return self._comparison(operator.eq, other)
[docs] def __ne__(self, other: Any) -> bool: """Compare if self is not equal to another object.""" return self._comparison(operator.ne, other)
[docs] def __lt__(self, other: Any) -> bool: """Compare if self is less than another object.""" return self._comparison(operator.lt, other)
[docs] def __gt__(self, other: Any) -> bool: """Compare if self is greater than another object.""" return self._comparison(operator.gt, other)
[docs] def __le__(self, other: Any) -> bool: """Compare if self is less than or equal to another object.""" return self._comparison(operator.le, other)
[docs] def __ge__(self, other: Any) -> bool: """Compare if self is greater than equal to another object.""" return self._comparison(operator.ge, other)
[docs]class CompleteStatus(Status): """Status name of 'complete' with code of '2'."""
[docs] def __init__(self, reason: Optional[str] = None) -> None: """Instantiate class. Args: reason: Reason for the status. """ super().__init__("complete", 2, reason)
[docs]class FailedStatus(Status): """Status name of 'failed' with code of '4'."""
[docs] def __init__(self, reason: Optional[str] = None) -> None: """Instantiate class. Args: reason: Reason for the status. """ super().__init__("failed", 4, reason)
[docs]class PendingStatus(Status): """Status name of 'pending' with code of '0'."""
[docs] def __init__(self, reason: Optional[str] = None) -> None: """Instantiate class. Args: reason: Reason for the status. """ super().__init__("pending", 0, reason)
[docs]class SkippedStatus(Status): """Status name of 'skipped' with code of '3'."""
[docs] def __init__(self, reason: Optional[str] = None) -> None: """Instantiate class. Args: reason: Reason for the status. """ super().__init__("skipped", 3, reason)
[docs]class SubmittedStatus(Status): """Status name of 'submitted' with code of '1'."""
[docs] def __init__(self, reason: Optional[str] = None) -> None: """Instantiate class. Args: reason: Reason for the status. """ super().__init__("submitted", 1, reason)
[docs]class DidNotChangeStatus(SkippedStatus): """Skipped status with a reason of 'nochange'.""" reason = "nochange"
[docs]class DoesNotExistInCloudFormation(SkippedStatus): """Skipped status with a reason of 'does not exist in cloudformation'.""" reason = "does not exist in cloudformation"
[docs]class NotSubmittedStatus(SkippedStatus): """Skipped status with a reason of 'disabled'.""" reason = "disabled"
[docs]class NotUpdatedStatus(SkippedStatus): """Skipped status with a reason of 'locked'.""" reason = "locked"
COMPLETE = CompleteStatus() FAILED = FailedStatus() INTERRUPTED = FailedStatus(reason="interrupted") NO_CHANGE = DidNotChangeStatus() PENDING = PendingStatus() SKIPPED = SkippedStatus() SUBMITTED = SubmittedStatus() WAITING = PendingStatus(reason="waiting")