Mercurial > lcfOS
view python/ppci/tasks.py @ 329:8f6f3ace4e78
Added build tasks
author | Windel Bouwman |
---|---|
date | Wed, 05 Feb 2014 21:29:31 +0100 |
parents | |
children | 87feb8a23b4d |
line wrap: on
line source
class TaskError(Exception): pass class Task: """ Task that can run, and depend on other tasks """ def __init__(self, name): self.name = name self.subtasks = [] self.completed = False self.dependencies = [] def run(self): raise NotImplementedError("Implement this abstract method!") def fire(self): assert all(t.completed for t in self.dependencies) self.run() self.completed = True def addSubTask(self, tsk): self.subtasks.append(tsk) return tsk def addDependency(self, task): self.dependencies.append(task) return task class TaskRunner: def __init__(self): self.task_list = [] def add_task(self, task): self.task_list.append(task) def run_tasks(self): try: for t in self.task_list: #print('Running {}'.format(t.name)) t.fire() except TaskError as e: print('Error: {}'.format(e)) return 1 return 0