2013-06-23 17:03:55 +02:00
|
|
|
from common.exceptions import TaskListError
|
2013-05-02 19:13:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Task(object):
|
2013-06-23 15:26:08 +02:00
|
|
|
phase = None
|
|
|
|
before = []
|
|
|
|
after = []
|
2013-05-02 19:13:35 +02:00
|
|
|
|
|
|
|
def __init__(self):
|
2013-06-23 15:26:08 +02:00
|
|
|
self._check_ordering()
|
2013-05-02 19:13:35 +02:00
|
|
|
|
2013-06-09 18:25:35 +02:00
|
|
|
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 15:26:08 +02:00
|
|
|
|
2013-06-23 17:54:25 +02:00
|
|
|
def __repr__(self):
|
|
|
|
return self.__str__()
|
|
|
|
|
2013-06-23 15:26:08 +02:00
|
|
|
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__)
|
2013-06-23 15:26:08 +02:00
|
|
|
for task in self.before:
|
|
|
|
if self.phase > task.phase:
|
|
|
|
msg = ("The task {self} is specified as running before {other}, "
|
2013-08-11 18:25:05 +02:00
|
|
|
"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))
|
2013-06-23 17:03:55 +02:00
|
|
|
raise TaskListError(msg)
|
2013-06-23 15:26:08 +02:00
|
|
|
for task in self.after:
|
|
|
|
if self.phase < task.phase:
|
|
|
|
msg = ("The task {self} is specified as running after {other}, "
|
2013-08-11 18:25:05 +02:00
|
|
|
"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))
|
2013-06-23 17:03:55 +02:00
|
|
|
raise TaskListError(msg)
|