bootstrap-vz/base/tasklist.py

35 lines
987 B
Python
Raw Normal View History

2013-06-09 20:29:54 +02:00
import logging
log = logging.getLogger(__name__)
2013-05-02 19:13:35 +02:00
class TaskList(list):
2013-05-16 08:00:28 +02:00
def plugins(self, manifest):
for plugin in manifest.loaded_plugins:
plugin.modify_tasklist(self, manifest)
def run(self, bootstrap_info):
2013-05-02 19:13:35 +02:00
for task in self:
2013-06-09 20:29:54 +02:00
log.info(task)
2013-05-16 08:00:28 +02:00
task.run(bootstrap_info)
2013-05-02 19:13:35 +02:00
2013-05-16 08:00:28 +02:00
def before(self, ref, task):
2013-06-09 20:29:54 +02:00
log.debug('Inserting %s before %s.%s', task, ref.__module__, ref.__name__)
2013-05-16 08:00:28 +02:00
i = next(i for i, task in enumerate(self) if type(task) is ref)
self.insert(i, task)
2013-05-02 19:13:35 +02:00
2013-05-16 08:00:28 +02:00
def replace(self, ref, task):
2013-06-09 20:29:54 +02:00
log.debug('Replacing %s.%s with %s', ref.__module__, ref.__name__, task)
2013-05-16 08:00:28 +02:00
i = next(i for i, task in enumerate(self) if type(task) is ref)
self.pop(i)
self.insert(i, task)
2013-05-02 19:13:35 +02:00
2013-05-16 08:00:28 +02:00
def after(self, ref, task):
2013-06-09 20:29:54 +02:00
log.debug('Inserting %s after %s.%s', task, ref.__module__, ref.__name__)
2013-05-16 08:00:28 +02:00
i = next(i for i, task in enumerate(self) if type(task) is ref)
self.insert(i+1, task)
2013-06-09 20:29:54 +02:00
def append(self, task):
super(TaskList, self).append(task)
log.debug('Appending %s', task)