- method = None
- argtypes = ''
- task_prefix = 'TASK:'
- if command_name[:len(task_prefix)] == task_prefix:
- task_name = command_name[len(task_prefix):]
- task_method_candidate = 'task_' + task_name
- if hasattr(Thing, task_method_candidate):
- method = partial(cmd_TASK_colon, task_name)
- task_method = getattr(Thing, task_method_candidate)
- if hasattr(task_method, 'argtypes'):
- argtypes = task_method.argtypes
+ def cmd_SET_TASK_colon(task_name, thing_id, todo, *args):
+ t = self.world.get_thing(thing_id, False)
+ if t is None:
+ raiseArgError('No such Thing.')
+ t.task = Task(t, task_name, args)
+ t.task.todo = todo
+
+ def task_prefixed(command_name, task_prefix, task_command,
+ argtypes_prefix=''):
+ method = None
+ argtypes = ''
+ if command_name[:len(task_prefix)] == task_prefix:
+ task_name = command_name[len(task_prefix):]
+ task_method_candidate = 'task_' + task_name
+ if hasattr(Thing, task_method_candidate):
+ method = partial(task_command, task_name)
+ task_method = getattr(Thing, task_method_candidate)
+ if hasattr(task_method, 'argtypes'):
+ argtypes = task_method.argtypes
+ if method is not None:
+ return method, argtypes_prefix + argtypes
+ return None, argtypes
+
+ method, argtypes = task_prefixed(command_name, 'TASK:', cmd_TASK_colon)
+ if method:
+ return method, argtypes
+ method, argtypes = task_prefixed(command_name, 'SET_TASK:',
+ cmd_SET_TASK_colon,
+ 'int:nonneg int:nonneg')
+ if method: