summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2011-07-13 22:57:09 -0500
committerMichael Merickel <michael@merickel.org>2011-07-14 19:56:44 -0500
commitf422adb9108520182c7eee5128c0f1e1f64d2e17 (patch)
tree91afc3037e6dc43f2858f91c1f74d65b9cae3f55
parentc01a8429ca4f385f0443f324c76d57b17d77dedb (diff)
downloadpyramid-f422adb9108520182c7eee5128c0f1e1f64d2e17.tar.gz
pyramid-f422adb9108520182c7eee5128c0f1e1f64d2e17.tar.bz2
pyramid-f422adb9108520182c7eee5128c0f1e1f64d2e17.zip
Added p.paster.bootstrap for handling simple loading of INI files.
-rw-r--r--docs/api/paster.rst12
-rw-r--r--pyramid/paster.py32
2 files changed, 35 insertions, 9 deletions
diff --git a/docs/api/paster.rst b/docs/api/paster.rst
index 6668f3c77..09e768fae 100644
--- a/docs/api/paster.rst
+++ b/docs/api/paster.rst
@@ -3,14 +3,8 @@
:mod:`pyramid.paster`
---------------------------
-.. module:: pyramid.paster
+.. automodule:: pyramid.paster
-.. function:: get_app(config_file, name=None)
-
- 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:: get_app
+ .. autofunction:: bootstrap
diff --git a/pyramid/paster.py b/pyramid/paster.py
index 7d75def75..9ebeacab9 100644
--- a/pyramid/paster.py
+++ b/pyramid/paster.py
@@ -9,6 +9,7 @@ from paste.deploy import loadapp
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 @@ def get_app(config_uri, name=None, loadapp=loadapp):
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):