[Grok-dev] setting up local utilities from outside grok

Christian Klinger cklinger at novareto.de
Thu Jul 9 06:21:06 EDT 2009


Hi Jasper,

maybe you can look on zope.app.generation. I am not 100 % sure
if your usecase is doable with that package.

I try to give you a little code snippet which maybe works...

1. Add a directory called 'generations' in your package.
2. put this snippet into the generations/__init__.py:

from zope.app.generations.generations import SchemaManager

UVCSchemaManager = SchemaManager(
     minimum_generation = 1,
     generation = 2,
     package_name = __name__
)

3. Add an generations/install.py file with this content:
    (Note this file gets called exactly 1 times on startup of zope)

import zope.app.generations.utility

def evolve(context):
     print "Install Generation"
     root = zope.app.generations.utility.getRootFolder(context)
     #do your stuff here....

Hope this helps.
Please let me know if it works for you.
(Because i have the same problem but no time to tackle it...)

- Christian


> Hi list,
> 
> I've got a small issue with setting up local utilities on a
> grok.Application; I have something like the following:
> 
> class MyWonderfulApp(grok.Application):
>     grok.local_utility(PluggableAuthentication, provides=IAuthentication,
>                        setup=setup_authentication)
> 
> This works fine if I instantiate my application through the webinterface.
> However, I'd like to be able to instantiate my application using some code
> (which doesn't know a lot about grok), where I do something like:
> 
> 
> grok.grok('my.app')
> root = get_apps_root()  # this sets up the ZODB connection and returns the
>                         # root object
> 
> if 'test' not in root:
>     root['test'] = app = MyWonderfulApp(...)
>     ...
>     transaction.commit()
> 
> The application is available, I can access views, but no sitemanager or
> localutil is registered, and my authentication thing is not set up.
> 
> Is there an easy way to get this to work?
> 
> Cheers,



More information about the Grok-dev mailing list