import os.path

import snactor.output_processors  # noqa
from snactor.registry.output_processors import get_output_processor
from snactor.registry.schemas import LATEST
from snactor.registry import must_get_actor


class Definition(object):
    def __resolve_channel_type(self, channels):
        """
            Resolve type of input / output channel. The version field is optional and if
            not set, a LATEST is used as a string identifier.

            type:
              name: Name
              version: Version
        """
        for channel in channels:
            channel["type"].setdefault("version", LATEST)

    def __init__(self, name, init=None):
        init = init or {}
        self.base_path = os.path.dirname(os.path.abspath(init['$location']))
        self.name = name
        self.init = init
        self.tags = set(init.get('tags', ()))
        self.inputs = init.get('inputs') or ()
        self.__resolve_channel_type(self.inputs)

        self.outputs = init.get('outputs') or ()
        if not isinstance(self.outputs, (list, tuple)):
            self.outputs = (self.outputs,)
        self.__resolve_channel_type(self.outputs)

        self.description = init.get('description', 'No description has been provided for this actor')

        self.remote = init.get('remote')
        execute = init.get('execute')
        if execute:
            self.executable = execute.get('executable', None)
            if self.executable and not os.path.isabs(self.executable):
                self.executable = os.path.abspath(os.path.join(self.base_path, self.executable))
            self.arguments = execute.get('arguments', [])
            self.output_processor = get_output_processor(execute.get('output-processor', None))
            self.script_file = execute.get('script-file')
            if self.script_file:
                self.arguments.insert(0, self.script_file)
        elif init.get('group'):
            self.actors = map(must_get_actor, init.get('group', ()))

@@ -208,16 +208,68 @@
 actor%0A%0A%0A
+class InvalidDefinitionError(Exception):%0A    pass%0A%0A%0A
 class De
@@ -2041,16 +2041,125 @@
 t('group', ()))%0A
+        else:%0A            raise InvalidDefinitionError(%22Actor does not contain an execute or group section%22)%0A

Raise an exception if neither group or execute has been specified in an actor