Michael Merickel
2011-07-14 f422adb9108520182c7eee5128c0f1e1f64d2e17
Added p.paster.bootstrap for handling simple loading of INI files.
2 files modified
44 ■■■■ changed files
docs/api/paster.rst 12 ●●●● patch | view | raw | blame | history
pyramid/paster.py 32 ●●●●● patch | view | raw | blame | history
docs/api/paster.rst
@@ -3,14 +3,8 @@
:mod:`pyramid.paster`
---------------------------
.. module:: pyramid.paster
.. automodule:: pyramid.paster
.. function:: get_app(config_file, name=None)
    .. autofunction:: get_app
    Return the WSGI application named ``name`` in the PasteDeploy
    config file ``config_file``.
    If the ``name`` is None, this will attempt to parse the name from
    the ``config_file`` string expecting the format ``ini_file#name``.
    If no name is found, the name will default to "main".
    .. autofunction:: bootstrap
pyramid/paster.py
@@ -9,6 +9,7 @@
from paste.script.command import Command
from pyramid.scripting import get_root
from pyramid.scripting import get_root2
from pyramid.util import DottedNameResolver
from pyramid.scaffolds import PyramidTemplate # bw compat
@@ -35,6 +36,37 @@
    app = loadapp(config_name, name=section, relative_to=here_dir)
    return app
def bootstrap(config_uri, request=None):
    """ Load a WSGI application from the PasteDeploy config file specified
    by ``config_uri``.
    .. note:: Most operations within :app:`Pyramid` expect to be invoked
              within the context of a WSGI request, thus it's important when
              loading your application to anchor it when executing scripts
              and other code that is not normally invoked during active WSGI
              requests.
    .. note:: For a complex config file containing multiple :app:`Pyramid`
              applications, this function will setup the environment under
              the context of the last-loaded :app:`Pyramid` application. You
              may load a specific application yourself by using the
              lower-level functions :meth:`pyramid.paster.get_app` and
              :meth:`pyramid.scripting.get_root2` in conjunction with
              :attr:`pyramid.config.global_registries`.
    ``config_uri`` -- specifies the PasteDeploy config file to use for the
    interactive shell. The format is ``inifile#name``. If the name is left
    off, ``main`` will be assumed.
    ``request`` -- specified to anchor the script to a given set of WSGI
    parameters. For example, most people would want to specify the host,
    scheme and port such that their script will generate URLs in relation
    to those parameters.
    """
    app = get_app(config_uri)
    root, closer = get_root2(request)
    return (app, root, closer)
_marker = object()
class PCommand(Command):