[Grok-dev] Get grok site "outside" the server (in an external script)
Hector Blanco
white.lists at gmail.com
Tue Jul 26 16:49:55 EDT 2011
Hello everyone
I have built a typical grok application:
-------------- app.py --------------
class MyServer(grok.Application, grok.Container):
def __init__(self):
try:
super(MyServer, self).__init__()
self["MyManager1"] = MyManager1.MyManager1()
self["MyManager2"] = MyManager2.MyManager2()
------------------------------------------
I would like to access that "application" (MyServer) in a python
script outside the web server so I can use the Managers and its
functions.
Ideally, what I need is to be able to open a python console and do
something like:
>>> import grok
>>> site = grok.getSite()
>>> site['MyManager1'].superCoolMethod()
(where superCoolMethod is, as you may have suspected, a function of
the elements of MyManager1 type)
I've been able to create an script that puts in the PYTHOPATH all the
required eggs (the ones found under $HOME/.buildout) but if I try what
I described above, grok.getSite() returns None. It works fine when I
do grok.getSite() inside the server, but not outside.
Is there any way to "manually" connect to the ZopeDB (I'm guessing to
the Data.fs) when the server is not running?
I've also tried something that I seem to remember it worked before,
but without luck today:
>>> from ZODB.interfaces import IDatabase
>>> import grok
>>> from zope.component import getUtility
>>> db = getUtility(IDatabase)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/zignage/.buildout/eggs/zope.component-3.10.0-py2.6.egg/zope/component/_api.py",
line 169, in getUtility
raise ComponentLookupError(interface, name)
zope.component.interfaces.ComponentLookupError: (<InterfaceClass
ZODB.interfaces.IDatabase>, '')
Basically, I want to reach the "MyServer" instance from an external
script and without the server running. Is that possible?
Thank you very much!
More information about the Grok-dev
mailing list