Example #1
0
    def add_backend (self, name, conf={}):
        """
        Finds a RapidSMS backend class (given its module name), instantiates and
        (optionally) configures it, and adds it to the list of backends that are
        polled for incoming messages. Returns the configured instance, or raises
        ImportError if the module was invalid.
        """

        # backends live in rapidsms/backends/*.py
        # import it early to check that it's valid
        module_name = "rapidsms.backends.%s" % conf.pop("type")
        __import__(module_name)

        # find the backend class (regardless of its name). it should
        # be the only subclass of rapidsms.Backend defined the module
        cls = get_class(sys.modules[module_name], BackendBase)

        # instantiate and configure the backend instance.
        # (FYI, i think it's okay to configure backends at
        # startup, since the webui isn't affected by them.
        # (except in a purely informative ("you're running
        # _these_ backends") sense))
        backend = cls(self, name)
        backend._configure(**conf)
        self.backends.append(backend)

        return backend
Example #2
0
    def add_app(self, name, conf={}):
        """
        Finds a RapidSMS app class (given its module name), instantiates and
        (optionally) configures it, and adds it to the list of apps that are
        notified of incoming messages. Returns the instance, or None if the app
        module could not be imported.
        """

        # try to import the .app module from this app. it's okay if the
        # module doesn't exist, but all other exceptions will propagate
        module = try_import("%s.app" % name)
        if module is None:
            return None

        # find the app class (regardless of its name). it should be
        # the only subclass of rapidsms.App defined the app module
        cls = get_class(module, AppBase)

        # instantiate and configure the app instance.
        # TODO: app.configure must die, because the webui (in a separate
        # process) can't access the app instances, only the flat modules
        app = cls(self)
        app._configure(**dict(conf))
        self.apps.append(app)

        return app
Example #3
0
    def add_app (self, conf):

        # try to import the .app module from this app. it's okay if the
        # module doesn't exist, but all other exceptions will propagate
        app_module = try_import("%s.app" % conf["type"])

        if app_module is None:
            return None

        # find the app class (regardless of its name). it should be
        # the only subclass of rapidsms.App defined the app module
        app_class = get_class(app_module, rapidsms.App)

        # instantiate and configure the app instance.
        # TODO: app.configure must die, because the webui (in a separate
        # process) can't access the app instances, only the flat modules
        app = app_class(self)
        app._configure(**dict(conf))
        self.apps.append(app)