def __init__(self, name, action, group=None, dependencies=None, serialize=True): """Parameters: name: the name of the goal. action: the goal action object to invoke this goal. dependencies: the names of other goals which must be achieved before invoking this goal. serialize: a flag indicating whether or not the action to achieve this goal requires the global lock. If true, the action will block until it can acquire the lock. """ self.serialize = serialize self.name = name self.group = group self.dependencies = [Phase(d) for d in dependencies] if dependencies else [] if type(action) == type and issubclass(action, Task): self._task = action else: args, varargs, keywords, defaults = inspect.getargspec(action) if varargs or keywords or defaults: raise GoalError( 'Invalid action supplied, cannot accept varargs, keywords or defaults' ) if len(args) > 2: raise GoalError( 'Invalid action supplied, must accept 0, 1, or 2 args') class FuncTask(Task): def __init__(self, context): Task.__init__(self, context) if not args: self.action = lambda targets: action() elif len(args) == 1: self.action = lambda targets: action(self.context) elif len(args) == 2: self.action = lambda targets: action( self.context, targets) else: raise AssertionError('Unexpected fallthrough') def execute(self, targets): self.action(targets) self._task = FuncTask
def install(self, phase=None, first=False, replace=False, before=None, after=None): """ Installs this goal in the specified phase (or a new phase with the same name as this Goal). The placement of the goal in the execution list of the phase defaults to the end but can be influence by specifying exactly one of the following arguments: first: Places this goal 1st in the phase's execution list replace: Replaces any existing goals in the phase with this goal before: Places this goal before the named goal in the phase's execution list after: Places this goal after the named goal in the phase's execution list """ phase = Phase(phase or self.name) phase.install(self, first, replace, before, after) return phase
def __init__(self, name, action, group=None, dependencies=None): self.name = name self.group = group self.dependencies = [Phase(d) for d in dependencies] if dependencies else [] if type(action) == type and issubclass(action, Task): self._task = action else: args, varargs, keywords, defaults = inspect.getargspec(action) if varargs or keywords or defaults: raise GoalError( 'Invalid action supplied, cannot accept varargs, keywords or defaults' ) if len(args) > 2: raise GoalError( 'Invalid action supplied, must accept 0, 1, or 2 args') class FuncTask(Task): def __init__(self, context): Task.__init__(self, context) if not args: self.action = lambda targets: action() elif len(args) == 1: self.action = lambda targets: action(self.context) elif len(args) == 2: self.action = lambda targets: action( self.context, targets) else: raise AssertionError('Unexpected fallthrough') def execute(self, targets): self.action(targets) self._task = FuncTask