diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-05-28 13:49:18 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-05-28 13:49:18 +0000 |
| commit | 82fefc4220a26b37484d2c79db4fdaeb9aebf7e9 (patch) | |
| tree | f58149ef83b2bd8748751230d6691dc442100d08 /repoze/bfg/scripting.py | |
| parent | 5968cd6ab617d6b25a43cd3bd3866d4a8f635638 (diff) | |
| download | pyramid-82fefc4220a26b37484d2c79db4fdaeb9aebf7e9.tar.gz pyramid-82fefc4220a26b37484d2c79db4fdaeb9aebf7e9.tar.bz2 pyramid-82fefc4220a26b37484d2c79db4fdaeb9aebf7e9.zip | |
- Add a ``get_app`` API functions to the ``paster`` module. This
obtains a WSGI application from a config file given a config file
name and a section name. See the ``repoze.bfg.paster`` API docs for
more information.
- Add a new module named ``scripting``. It contains a ``get_root``
API function, which, provided a Router instance, returns a traversal
root object and a "closer". See the ``repoze.bfg.scripting`` API
docs for more info.
Diffstat (limited to 'repoze/bfg/scripting.py')
| -rw-r--r-- | repoze/bfg/scripting.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/repoze/bfg/scripting.py b/repoze/bfg/scripting.py new file mode 100644 index 000000000..5399b7d77 --- /dev/null +++ b/repoze/bfg/scripting.py @@ -0,0 +1,20 @@ +def get_root(app, environ=None): + """ Return a tuple composed of ``(root, closer)`` when provided a + ``repoze.bfg.router.Router`` instance as the ``app`` argument. + The ``root`` returned is the application root object. The + ``closer`` returned is a callable (accepting no arguments) that + should be called when your scripting application is finished using + the root. If ``environ`` is not None, it is used as the + environment passed to the BFG application root factory. An empty + environ is constructed and passed to the root factory if + ``environ`` is None.""" + registry = app.registry + threadlocals = {'registry':registry, 'request':None} + app.threadlocal_manager.push(threadlocals) + if environ is None: + environ = {} + def closer(environ=environ): # keep environ alive via this function default + app.threadlocal_manager.pop() + root = app.root_factory(environ) + return root, closer + |
