Exemplo n.º 1
0
    def _setup(self):
        """
        Does the actual method configuration, this is here because the
        method configuration must happen after the class is defined
        """
        if not self.is_setup:

            #construct the default name
            name_func = getattr(self.parent_class,
                                'get_element_type', None) or getattr(
                                    self.parent_class, 'get_label', None)
            default_path = (name_func()
                            if name_func else 'gremlin') + '.groovy'

            self.path = self.path or default_path
            if self.path.startswith('/'):
                path = self.path
            else:
                path = inspect.getfile(self.parent_class)
                path = os.path.split(path)[0]
                path += '/' + self.path

            #TODO: make this less naive
            gremlin_obj = None
            for grem_obj in parse(path):
                if grem_obj.name == self.method_name:
                    gremlin_obj = grem_obj
                    break

            if gremlin_obj is None:
                raise ThunderdomeGremlinException(
                    "The method '{}' wasnt found in {}".format(
                        self.method_name, path))

            for arg in gremlin_obj.args:
                if arg in self.arg_list:
                    raise ThunderdomeGremlinException(
                        "'{}' defined more than once in gremlin method arguments"
                        .format(arg))
                self.arg_list.append(arg)

            self.function_body = gremlin_obj.body
            self.function_def = gremlin_obj.defn
            self.is_setup = True
Exemplo n.º 2
0
    def _setup(self):
        """
        Does the actual method configuration, this is here because the
        method configuration must happen after the class is defined
        """
        if not self.is_setup:

            #construct the default name
            name_func = getattr(self.parent_class, 'get_element_type', None) or getattr(self.parent_class, 'get_label', None)
            default_path = (name_func() if name_func else 'gremlin') + '.groovy'

            self.path = self.path or default_path
            if self.path.startswith('/'):
                path = self.path
            else:
                path = inspect.getfile(self.parent_class)
                path = os.path.split(path)[0]
                path += '/' + self.path

            #TODO: make this less naive
            gremlin_obj = None
            for grem_obj in parse(path):
                if grem_obj.name == self.method_name:
                    gremlin_obj = grem_obj
                    break

            if gremlin_obj is None:
                raise ThunderdomeGremlinException("The method '{}' wasnt found in {}".format(self.method_name, path))

            for arg in gremlin_obj.args:
                if arg in self.arg_list:
                    raise ThunderdomeGremlinException("'{}' defined more than once in gremlin method arguments".format(arg))
                self.arg_list.append(arg)

            self.function_body = gremlin_obj.body
            self.function_def = gremlin_obj.defn
            self.is_setup = True
Exemplo n.º 3
0
 def configure_method(self, klass, attr_name, gremlin_path):
     """
     Configures the methods internals
     
     :param klass: the class object this function is being added onto
     :param attr_name: the attribute name this function is being added to the class as
     """
     self.attr_name = attr_name
     self.method_name = self.method_name or self.attr_name
     if not self.is_configured:
         self.path = self.path or gremlin_path or 'gremlin.groovy'
         if self.path.startswith('/'):
             path = self.path
         else:
             path = inspect.getfile(klass)
             path = os.path.split(path)[0]
             path += '/' + self.path
             
         #TODO: make this less naive
         gremlin_obj = None
         for grem_obj in parse(path):
             if grem_obj.name == self.method_name:
                 gremlin_obj = grem_obj
                 break
             
         if gremlin_obj is None:
             raise ThunderdomeGremlinException("The method'{}' wasnt found in {}".format(self.method_name, path))
         
         for arg in gremlin_obj.args:
             if arg in self.arg_list:
                 raise ThunderdomeGremlinException("'{}' defined more than once in gremlin method arguments".format(arg))
             self.arg_list.append(arg)
         
         self.function_body = gremlin_obj.body
         self.function_def = gremlin_obj.defn
         self.is_configured = True