From 711b60c05b9573f688994233ec1baac3f89bc45a Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 27 May 2009 14:03:07 +0000 Subject: Provide b/c for scripts which used ``registry_manager`` --- repoze/bfg/scripting.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 repoze/bfg/scripting.py (limited to 'repoze/bfg/scripting.py') 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) + -- cgit v1.2.3