#! /usr/bin/env python # encoding: utf-8 # Thomas Nagy, 2008 (ita) """ This example illustrates the creation of task instances manually It also illustrates the order constraints on the tasks. This may help tool writers. In practice, tasks are created by task generators which handle the constraints globally (creation, dependencies, ordering). Note that the execution in parallel (-j) is supported """ VERSION='0.0.1' APPNAME='test' top = '.' out = 'build' import random import Task, Build, Environment from Constants import * class base(Task.TaskBase): def runnable_status(self): for x in getattr(self, 'run_after', ()): if not x.hasrun: return ASK_LATER return RUN_ME def run(self): print self.__class__.__name__ + " " + getattr(self, "id", "") self.hasrun = 1 class X(base): before = 'Y' class Y(base): pass class Z(base): after = 'Y' class A(base): pass class B(base): pass class I(base): def runnable_status(self): if random.randint(0, 1): return SKIP_ME else: return RUN_ME class J(base): def runnable_status(self): for x in getattr(self, 'run_if', ()): if x.hasrun == NOT_RUN: return ASK_LATER return RUN_ME class Persist(base): after = "X Y Z I J A B" def run(self): cachefile = "test.cache.py" self.env = Environment.Environment() try: self.env.load(cachefile) except (OSError, IOError): pass self.env.myval = (self.env.myval or 0) + 1 print "%s %d" % (self.__class__.__name__, self.env.myval) self.env.store(cachefile) def build(bld): # the order of execution is declared by the constraints 'after' and 'before'" task_a = Z() task_b = Y() task_c = X() # a simple order constraint task_1 = A() task_2 = B() task_2.run_after = [task_1] # run only if the other was skipped (randomly, for illustration purposes) task_i = I() task_j = J() task_j.run_if = [task_i] # store the results between runs, manually task_p = Persist() def configure(conf): pass