- 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
- return method, argtypes
- method_candidate = 'cmd_' + command_name
- if hasattr(self, method_candidate):
- method = getattr(self, method_candidate)
- if hasattr(method, 'argtypes'):
- argtypes = method.argtypes
- return 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.')
+ task_class = self.task_manager.get_task_class(task_name)
+ t.task = task_class(t, args)
+ t.task.todo = todo
+
+ def task_prefixed(command_name, task_prefix, task_command,
+ argtypes_prefix=''):
+ func = None
+ argtypes = ''
+ if command_name[:len(task_prefix)] == task_prefix:
+ task_name = command_name[len(task_prefix):]
+ task_manager_reply = self.task_manager.get_task_class(task_name)
+ if task_manager_reply is not None:
+ func = partial(task_command, task_name)
+ task_class = task_manager_reply
+ argtypes = task_class.argtypes
+ if func is not None:
+ return func, argtypes_prefix + argtypes
+ return None, argtypes
+
+ func, argtypes = task_prefixed(command_name, 'TASK:', cmd_TASK_colon)
+ if func:
+ return func, argtypes
+ func, argtypes = task_prefixed(command_name, 'SET_TASK:',
+ cmd_SET_TASK_colon,
+ 'int:nonneg int:nonneg ')
+ if func:
+ return func, argtypes
+ func_candidate = 'cmd_' + command_name
+ if hasattr(self, func_candidate):
+ func = getattr(self, func_candidate)
+ if hasattr(func, 'argtypes'):
+ argtypes = func.argtypes
+ return func, argtypes