Esempio n. 1
0
 def either(self, default_key, *values):
     """Fallback to the value of a configuration key if none of the
     `*values` are true."""
     return first(None, [
         first(None, values),
         starpromise(self.conf.get, default_key),
     ])
Esempio n. 2
0
    def autodiscover_tasks(self,
                           packages=None,
                           related_name='tasks',
                           force=False):
        """Try to autodiscover and import modules with a specific name (by
        default 'tasks').

        If the name is empty, this will be delegated to fixups (e.g. Django).

        For example if you have an (imagined) directory tree like this::

            foo/__init__.py
               tasks.py
               models.py

            bar/__init__.py
                tasks.py
                models.py

            baz/__init__.py
                models.py

        Then calling ``app.autodiscover_tasks(['foo', bar', 'baz'])`` will
        result in the modules ``foo.tasks`` and ``bar.tasks`` being imported.

        :param packages: List of packages to search.
            This argument may also be a callable, in which case the
            value returned is used (for lazy evaluation).
        :keyword related_name: The name of the module to find.  Defaults
            to "tasks", which means it look for "module.tasks" for every
            module in ``packages``.
        :keyword force: By default this call is lazy so that the actual
            autodiscovery will not happen until an application imports the
            default modules.  Forcing will cause the autodiscovery to happen
            immediately.

        """
        if force:
            return self._autodiscover_tasks(packages, related_name)
        signals.import_modules.connect(starpromise(
            self._autodiscover_tasks,
            packages,
            related_name,
        ),
                                       weak=False,
                                       sender=self)
Esempio n. 3
0
    def autodiscover_tasks(self, packages=None,
                           related_name='tasks', force=False):
        """Try to autodiscover and import modules with a specific name (by
        default 'tasks').

        If the name is empty, this will be delegated to fixups (e.g. Django).

        For example if you have an (imagined) directory tree like this::

            foo/__init__.py
               tasks.py
               models.py

            bar/__init__.py
                tasks.py
                models.py

            baz/__init__.py
                models.py

        Then calling ``app.autodiscover_tasks(['foo', bar', 'baz'])`` will
        result in the modules ``foo.tasks`` and ``bar.tasks`` being imported.

        :param packages: List of packages to search.
            This argument may also be a callable, in which case the
            value returned is used (for lazy evaluation).
        :keyword related_name: The name of the module to find.  Defaults
            to "tasks", which means it look for "module.tasks" for every
            module in ``packages``.
        :keyword force: By default this call is lazy so that the actual
            autodiscovery will not happen until an application imports the
            default modules.  Forcing will cause the autodiscovery to happen
            immediately.

        """
        if force:
            return self._autodiscover_tasks(packages, related_name)
        signals.import_modules.connect(starpromise(
            self._autodiscover_tasks, packages, related_name,
        ), weak=False, sender=self)
Esempio n. 4
0
 def either(self, default_key, *values):
     """Fallback to the value of a configuration key if none of the
     `*values` are true."""
     return first(None, [
         first(None, values), starpromise(self.conf.get, default_key),
     ])