bootstrap-vz/base/task.py

36 lines
1.1 KiB
Python
Raw Normal View History

from common.exceptions import TaskListError
2013-05-02 19:13:35 +02:00
class Task(object):
phase = None
before = []
after = []
2013-05-02 19:13:35 +02:00
def __init__(self):
self._check_ordering()
2013-05-02 19:13:35 +02:00
def run(self, info):
2013-06-09 18:25:35 +02:00
pass
def __str__(self):
2013-06-09 20:29:54 +02:00
return '{module}.{task}'.format(module=self.__module__, task=self.__class__.__name__)
2013-06-23 17:54:25 +02:00
def __repr__(self):
return self.__str__()
def _check_ordering(self):
2013-06-23 17:54:25 +02:00
def name(ref):
return '{module}.{task}'.format(module=ref.__module__, task=ref.__class__.__name__)
for task in self.before:
if self.phase > task.phase:
msg = ("The task {self} is specified as running before {other}, "
"but its phase {phase} lies after the phase {other_phase}"
2013-06-23 17:54:25 +02:00
.format(self=type(self), other=task, phase=self.phase, other_phase=task.phase))
raise TaskListError(msg)
for task in self.after:
if self.phase < task.phase:
msg = ("The task {self} is specified as running after {other}, "
"but its phase {phase} lies before the phase {other_phase}"
2013-06-23 17:54:25 +02:00
.format(self=type(self), other=task, phase=self.phase, other_phase=task.phase))
raise TaskListError(msg)