Beispiel #1
0
    def load(self, module):
        """Load a specific module.

        This method:
            Get the Repository class defined in the module
            Write this class in the bundle's repositories
            Return the class

        """
        name = Rule.module_name(module)
        bundle_name = Rule.bundle_name(module)
        bundle = self.server.bundles[bundle_name]
        rep_class = Rule.find_class(module, Repository)

        # Write the class in the bundles
        model_name = self.get_model_name(rep_class)
        bundle.repositories[model_name] = rep_class
        return rep_class
Beispiel #2
0
    def unload(self, module):
        """Unload th emodule containing the controllers.

        Delete all the routes connected with this controller.

        """
        name = Rule.module_name(module)
        class_name = name.capitalize()
        ctl_class = getattr(module, class_name)
        self.server.dispatcher.delete_routes_for_controller(ctl_class)
Beispiel #3
0
 def load(self, module):
     """Load a specific package.
     
     This method:
         Get the Plugin class defined in the module
         Register this plugin in the plugin manager
         Subscribe this plugins.
         Return the class
     
     """
     name = Rule.module_name(module)
     plg_class = getattr(module, "Plugin")
     self.server.plugin_manager.register(name, plg_class)
     return plg_class
Beispiel #4
0
    def load(self, module):
        """Load a specific module.

        This method:
            Get the Controller class defined in the module
            Get the controller's bundle
            Instanciate the Controller class
            Set the server instance attribute
            Write the newly created object in the bundle's controllers
            Return the object

        """
        bundle_name = Rule.bundle_name(module)
        bundle = self.server.bundles[bundle_name]
        name = Rule.module_name(module)
        class_name = name.capitalize()
        ctl_class = getattr(module, class_name)
        ctl_object = ctl_class(bundle)
        ctl_object.server = self.server

        # Write the object in the bundle
        bundle.controllers[class_name] = ctl_object

        # Add the controller's routes
        routes = tuple(bundle.routes.items())
        routes = [(name, infos) for name, infos in routes if infos[1] == \
                class_name]
        for route, (pattern, ctl_name, action, methods) in routes:
            route_name = bundle_name + "." + route
            function = getattr(ctl_object, action)
            route = self.server.dispatcher.add_route(
                    route_name, pattern, ctl_object, function, methods)
            route.bundle = bundle
            route.controller_name = class_name
            route.action_name = action

        return ctl_object
Beispiel #5
0
    def load(self, module):
        """Load a specific module.

        This method:
            Get the Model class defined in the module
            Try to find the corresponding repository
            Write this dclass in the model's bundle
            Return the class

        """
        name = Rule.module_name(module)
        bundle_name = Rule.bundle_name(module)
        bundle = self.server.bundles[bundle_name]
        class_name = name.capitalize()
        mod_class = getattr(module, class_name)
        mod_class.bundle = bundle
        mod_name = get_name(mod_class)

        # Try to find the corresponding repository
        if mod_name in bundle.repositories:
            rep_class = bundle.repositories[mod_name]
            print("Found the repository", rep_class)
        else:
            rep_class = Repository
            print("Create a new repository")

        repository = rep_class(self.data_connector, mod_class)
        mod_class._repository = repository

        # Write the class in the bundles
        bundle.models[mod_name] = mod_class

        # Record the new bundle in the data connector
        self.data_connector.repository_manager.record_model(mod_class)

        return mod_class
Beispiel #6
0
    def load(self, module):
        """Load a specific module.

        This method:
            Get the Service class defined in the module
            Register this class in the server's services
            Return the class

        """
        name = Rule.module_name(module)
        class_name = name.capitalize()
        svc_class = getattr(module, class_name)


        # Register the service in the server
        self.server.services.register(svc_class)
        return svc_class
Beispiel #7
0
 def load(self, module):
     """Load a specific module.
     
     This method:
         Get the WebSocketHandler class defined in the module
         Return the class
     
     """
     name = Rule.module_name(module)
     class_name = name.capitalize()
     wsh_class = getattr(module, class_name)
     
     wsh_class.handlers = []
     if not wsh_class.ws_point:
         raise ValueError("the 'ws_point' class attribute is not " \
                 "set in {}".format(wsh_class))
     
     return wsh_class