예제 #1
0
파일: router.py 프로젝트: oluka/rapidsms
    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
예제 #2
0
    def app_section(self, name):

        # fetch the current config for this app
        # from raw_data (or default to an empty dict),
        # then copy it, so we don't alter the original
        data = self.raw_data.get(name, {}).copy()

        # "type" is ONLY VALID FOR BACKENDS now. it's not [easily] possible
        # to run multple django apps of the same type side-by-side, so i'm
        # raising here to avoid confusion (and allow apps to be lazy loaded)
        if "type" in data:
            raise Exception(
                'The "type" option is not supported for apps. It does '
                + "nothing, since running multple apps of the same type "
                + "is not currently possible."
            )

        # load the config.py for this app, if possible
        config = try_import("%s.config" % name)
        if config is not None:

            # copy all of the names not starting with underscore (those are
            # private or __magic__) into this component's default config,
            # unless they're already present (ini overrides config.py)
            for var_name in dir(config):
                if not var_name.startswith("_"):
                    if not var_name in data:
                        data[var_name] = getattr(config, var_name)

        # return the component with the additional
        # app-specific data included.
        return data
예제 #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)