Esempio n. 1
0
    def add_app(self, module_name):
        """
        Find the app named *module_name*, instantiate it, and add it to
        the list of apps to be notified of incoming messages. Return the
        app instance.
        """
        cls = None
        try:
            cls = AppBase.find(module_name)
        except Exception as e:
            traceback.print_exc(e)

        # couldn't find the app, is it a class name instead?
        if not cls:
            try:
                cls = HttpRouter.definition_from_string(module_name)
            except Exception as ee:
                traceback.print_exc(ee)

        # still no dice, warn the user
        if not cls:
            self.error("Unable to find SMS application with module: '%s'" % module_name)
            return None

        app = cls(self)
        self.apps.append(app)
        return app
Esempio n. 2
0
    def get_app(self, module_name):
        """
        Access installed app by name.

        :param module_name: Dotted path to RapidSMS app.
        :returns: ``AppBase`` object if found, otherwise ``None``.
        """
        cls = AppBase.find(module_name)
        if cls is None:
            return None
        for app in self.apps:
            if type(app) == cls:
                return app
        raise KeyError("The %s app was not found in the router!" % module_name)
Esempio n. 3
0
    def get_app(self, module_name):
        """
        Access installed app by name.

        :param module_name: Dotted path to RapidSMS app.
        :returns: ``AppBase`` object if found, otherwise ``None``.
        """
        cls = AppBase.find(module_name)
        if cls is None:
            return None
        for app in self.apps:
            if type(app) == cls:
                return app
        raise KeyError("The %s app was not found in the router!" % module_name)
 def add_app(self, module_name):
     """
     Find the app named *module_name*, instantiate it, and add it to
     the list of apps to be notified of incoming messages. Return the
     app instance.
     """
     if not inspect.isclass(module_name):
         cls = AppBase.find(module_name)
         if cls is None: return None
     else:
         cls = module_name
     app = cls(self)
     self.apps.append(app)
     return app
Esempio n. 5
0
 def add_app(self, module_name):
     """
     Find the app named *module_name*, instantiate it, and add it to
     the list of apps to be notified of incoming messages. Return the
     app instance.
     """
     if not inspect.isclass(module_name):
         try:
             cls = AppBase.find(module_name)
         except AttributeError:
             cls = None
     elif issubclass(module_name, AppBase):
         cls = module_name
     if not cls:
         return None
     app = cls(self)
     self.apps.append(app)
     return app
 def add_app(self, module_name):
     """
     Find the app named *module_name*, instantiate it, and add it to
     the list of apps to be notified of incoming messages. Return the
     app instance.
     """
     if not inspect.isclass(module_name):
         try:
             cls = AppBase.find(module_name)
         except AttributeError:
             cls = None
     elif issubclass(module_name, AppBase):
         cls = module_name
     if not cls:
         return None
     app = cls(self)
     self.apps.append(app)
     return app
Esempio n. 7
0
    def add_app(self, module_name):
        """
        Add RapidSMS app to router. Installed apps will be notified of
        incoming and outgoing messages. If ``module_name`` is a Django app,
        the method looks in ``app_name.app`` for an ``AppBase`` subclass to
        use.

        :param module_name: ``AppBase`` object or dotted path to RapidSMS app.
        :returns: ``AppBase`` object if found, otherwise ``None``.
        """
        if isinstance(module_name, basestring):
            cls = AppBase.find(module_name)
        elif issubclass(module_name, AppBase):
            cls = module_name
        if not cls:
            return None
        app = cls(self)
        self.apps.append(app)
        return app
Esempio n. 8
0
    def add_app(self, module_name):
        """
        Add RapidSMS app to router. Installed apps will be notified of
        incoming and outgoing messages. If ``module_name`` is a Django app,
        the method looks in ``app_name.app`` for an ``AppBase`` subclass to
        use.

        :param module_name: ``AppBase`` object or dotted path to RapidSMS app.
        :returns: ``AppBase`` object if found, otherwise ``None``.
        """
        if isinstance(module_name, basestring):
            cls = AppBase.find(module_name)
        elif issubclass(module_name, AppBase):
            cls = module_name
        if not cls:
            return None
        app = cls(self)
        self.apps.append(app)
        return app
Esempio n. 9
0
    def add_app(self, module_name):
        """
        Find the app named *module_name*, instantiate it, and add it to
        the list of apps to be notified of incoming messages. Return the
        app instance.
        """
        try:
            cls = AppBase.find(module_name)
        except:
            import traceback
            traceback.print_exc()
            cls = None

        if cls is None:
            self.error("Unable to find SMS application with module: '%s'" % module_name)
            return None

        app = cls(self)
        self.apps.append(app)
        return app
Esempio n. 10
0
    def handle_noargs(self, **options):
        verbosity = int(options.get("verbosity", 1))

        # fetch all of the apps (identified by their module name,
        # which is unique) that we already have objects for
        known_module_names = list(App.objects.values_list("module", flat=True))

        # find any running apps which currently
        # don't have objects, and fill in the gaps
        for module_name in settings.INSTALLED_APPS:
            if module_name not in known_module_names:
                # Assure the module is a rapidsms app with an App class
                if AppBase.find(module_name):
                    known_module_names.append(module_name)
                    app = App.objects.create(module=module_name)

                    # log at the same level as syncdb's "created table..."
                    # messages, to stay silent when called with -v 0
                    if verbosity >= 1:
                        print "Added persistant app %s" % app
Esempio n. 11
0
    def add_app(self, module_name):
        """
        Find the app named *module_name*, instantiate it, and add it to
        the list of apps to be notified of incoming messages. Return the
        app instance.
        """
        try:
            cls = AppBase.find(module_name)
        except:
            import traceback
            traceback.print_exc()
            cls = None

        if cls is None:
            self.error("Unable to find SMS application with module: '%s'" %
                       module_name)
            return None

        app = cls(self)
        self.apps.append(app)
        return app
Esempio n. 12
0
    def handle_noargs(self, **options):
        verbosity = int(options.get("verbosity", 1))

        # fetch all of the apps (identified by their module name,
        # which is unique) that we already have objects for
        known_module_names = list(App.objects.values_list("module", flat=True))

        # find any running apps which currently
        # don't have objects, and fill in the gaps
        for module_name in settings.INSTALLED_APPS:
            if module_name not in known_module_names:
                # Assure the module is a rapidsms app with an App class
                if AppBase.find(module_name):
                    known_module_names.append(module_name)
                    app = App.objects.create(
                        module=module_name)

                    # log at the same level as syncdb's "created table..."
                    # messages, to stay silent when called with -v 0
                    if verbosity >= 1:
                        print "Added persistant app %s" % app