| 65 | |
| 66 | |
| 67 | class Status: |
| 68 | type_cls = TaskType |
| 69 | state_cls = State |
| 70 | |
| 71 | def __init__(self, status: str = None): |
| 72 | self.task_status = {} |
| 73 | status_list = list(status[::-1] if status is not None else "") |
| 74 | for _type in self.type_cls: |
| 75 | index = _type.value - 1 |
| 76 | _state = self.state_cls(status_list[index] if len(status_list) > index else "n") |
| 77 | self.task_status[_type] = _state |
| 78 | |
| 79 | @staticmethod |
| 80 | def of(status: str): |
| 81 | return Status(status) |
| 82 | |
| 83 | def __str__(self): |
| 84 | result = [] |
| 85 | for _type in sorted(self.type_cls, key=lambda item: item.value, reverse=True): |
| 86 | result.insert(len(self.type_cls) - _type.value, self.task_status[_type].value) |
| 87 | return "".join(result) |
| 88 | |
| 89 | def __setitem__(self, key, value): |
| 90 | self.task_status[key] = value |
| 91 | |
| 92 | def __getitem__(self, item): |
| 93 | return self.task_status[item] |
| 94 | |
| 95 | def update_status(self, task_type: TaskType, state: State): |
| 96 | self.task_status[task_type] = state |
| 97 | |
| 98 | |
| 99 | def default_status_meta(): |
no outgoing calls
no test coverage detected