summaryrefslogtreecommitdiff
path: root/repoze/bfg/scripting.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-05-27 14:03:07 +0000
committerChris McDonough <chrism@agendaless.com>2009-05-27 14:03:07 +0000
commit711b60c05b9573f688994233ec1baac3f89bc45a (patch)
treec58595bc181ab52189b0cc096de099cf8e3bf167 /repoze/bfg/scripting.py
parenta6ead8805b4de79edd0d980942894c0518104d5e (diff)
downloadpyramid-711b60c05b9573f688994233ec1baac3f89bc45a.tar.gz
pyramid-711b60c05b9573f688994233ec1baac3f89bc45a.tar.bz2
pyramid-711b60c05b9573f688994233ec1baac3f89bc45a.zip
Provide b/c for scripts which used ``registry_manager``
Diffstat (limited to 'repoze/bfg/scripting.py')
-rw-r--r--repoze/bfg/scripting.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/repoze/bfg/scripting.py b/repoze/bfg/scripting.py
new file mode 100644
index 000000000..9e83e2fe8
--- /dev/null
+++ b/repoze/bfg/scripting.py
@@ -0,0 +1,18 @@
+_GET_ROOT_ENVIRON = {}
+
+def get_root(router):
+ """ Given a :mod:`repoze.bfg` Router application instance as its
+ ``router`` argument, this callable returns the traversal root of
+ graph as defined by the application's root factory. It also has
+ the effect of pushing a new registry and request on to the
+ internal thread local stack managed by BFG so that registry
+ lookups work properly.
+
+ .. warning:: This function should never be called from *within* a
+ BFG model or view, only from top-level scripts which wish to
+ get the root of a graph to do offline processing."""
+ registry = router.registry
+ threadlocals = {'registry':registry, 'request':None}
+ router.threadlocal_manager.push(threadlocals)
+ return router.root_factory(_GET_ROOT_ENVIRON)
+