Mercurial > lcfOS
diff python/ppci/tasks.py @ 334:6f4753202b9a
Added more recipes
author | Windel Bouwman |
---|---|
date | Thu, 13 Feb 2014 22:02:08 +0100 |
parents | 87feb8a23b4d |
children | 86b02c98a717 |
line wrap: on
line diff
--- a/python/ppci/tasks.py Sun Feb 09 15:27:57 2014 +0100 +++ b/python/ppci/tasks.py Thu Feb 13 22:02:08 2014 +0100 @@ -1,3 +1,5 @@ + +import logging class TaskError(Exception): pass @@ -10,6 +12,7 @@ self.subtasks = [] self.completed = False self.dependencies = [] + self.duration = 1 def run(self): raise NotImplementedError("Implement this abstract method!") @@ -34,22 +37,34 @@ class TaskRunner: """ Basic task runner that can run some tasks in sequence """ def __init__(self): + self.logger = logging.getLogger('taskrunner') self.task_list = [] def add_task(self, task): self.task_list.append(task) + @property + def total_duration(self): + return sum(t.duration for t in self.task_list) + def run_tasks(self): + passed_time = 0.0 + total_time = self.total_duration try: for t in self.task_list: - #print('Running {}'.format(t.name)) + self.report_progress(passed_time / total_time, t.name) t.fire() + passed_time += t.duration except TaskError as e: print('Error: {}'.format(e)) return 1 + self.report_progress(1, 'OK') return 0 def display(self): """ Display task how they would be run """ for task in self.task_list: print(task) + + def report_progress(self, percentage, text): + self.logger.info('[{:3.1%}] {}'.format(percentage, text))