[Grok-dev] Mixing grok and ZCML registration for a directory resource
Martin Aspeli
optilude+lists at gmail.com
Thu Mar 19 23:07:25 EDT 2009
Martin Aspeli wrote:
> Hi,
>
> I'm using five.grok and I have what looks like a bug:
>
> In my package's configure.zcml, I have:
>
> <include package=".browser" />
> <grok:grok package="." />
>
> In browser/configure.zcml, I have:
>
> <browser:resourceDirectory name="foo" directory="resources" />
>
> I then have files in browser/resources/*.css
>
> If I do this, the resource directory is not reachable:
> ++resource++foo/blah gives 404.
>
> However, if I make the grokker do its work before I include my custom
> ZCML, like this, then it works:
>
> <grok:grok package="." />
> <include package=".browser" />
>
> Note that there are other views/viewlets in browser/*.py that are
> grokked correctly in either case.
>
> Any idea what's going on here? I don't get an error or warning on
> startup, the resource just "disappears"...
I think I have an idea, actually, and it's weird.
in five.grok.meta, there's a StaticResourcesGrokker that gets called
dozens of times during startup. It registers resource directories for
each package, looking for the 'static' sub-directory everywhere.
I'd called my custom resourceDirectory ("foo" above) the same name as my
package. Therefore, I think the two were conflicting (although I didn't
get an error).
Surely, the StaticResourcesGrokker should do nothing if the path does
not actually exist? A simple os.path.exists() should do the trick, I guess.
Martin
--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book
More information about the Grok-dev
mailing list