[Grok-dev] Put the user-defined permissions in a separate .py file?

Hector Blanco white.lists at gmail.com
Wed Jan 12 12:24:15 EST 2011


Agh... It seems close... The best result (I think) I've got is by doing:

 ------------ configure.zcml ----------------
<configure xmlns="http://namespaces.zope.org/zope"
           xmlns:grok="http://namespaces.zope.org/grok">
  <include package="grok" />
  <includeDependencies package="." />
  <include package="backlib.user.Permissions"/>
  <grok:grok package="." />
</configure>
-------------------------------------------------
but then I get this error when I try to start the server:
> IOError: [Errno 2] No such file or directory: '/home/ae/myOwn-cms/backlib/user/configure.zcml'

I have a slightly strange directory structure. The python libraries I
develop are "outside" my server:

+ myOwn-cms/
+              backlib/
>                     user/
>                         User.py
>                         Permissions.py
     [ ... other external modules ...]

+              server/
>                     bin/
>                     log/
>                     parts/
>                     src/
>                         server/
>                              app.py
>                              rest.py

My grokproject is called "server". The "backlib" directory is added to
the $PYTHONPATH before starting the server so I can import the modules
I've created properly:
    export PYTHONPATH=$PYTHONPATH:/home/ae/myOwn-cms
    bin/paster serve --reload parts/etc/debug.ini

This way, in server/src/server/app.py (for instance) I can say:
    from backlib.user.User import User
    user = User()

I don't know if all this I said influences (or matters) somehow but,
just in case... Anyhow, despite of being untested, your idea seems to
go in the right direction...

Will keep trying... I guess I may have to create the
/home/ae/myOwn-cms/backlib/user/configure.zcml that it's asking for.
I'll investigate on that (I've never created one, but Google is
powerful and it will probably give me an answer)

Thanks for the hint!


2011/1/10 Jan-Wijbrand Kolman <janwijbrand at gmail.com>:
> On 12/23/10 18:08 PM, Hector Blanco wrote:
>  > If I create a "Permissions.py" file, I put this permission in it and
>> then I import "permissions" in app.py, when I try to start the server,
>> I get:
>
> Putting the permissions in one module sounds to me like a good idea. We
> do it too in our apps.
>
> The reason you get the error, is because app.py is "grokked" before
> "permission.py" and thus the permissions are not declared. It made me
> wonder why we, in our apps, do not have this error... And the answer is
> rather simple: we put our view code in a browser subpackage. The
> permission module live in the parent package, and thus is grokked before
> the views (that make use of the permissions) are grokked.
>
> It is unfortunate that the grokking-order influences how code is
> organized in packages. The work around I see is to make sure the
> permission.py module is grokked before the rest of the package from the
> configure.zcml (untested, but it might work):
>
> configure.zcml:
>
>   <configure
>     xmlns="http://namespaces.zope.org/zope"
>     xmlns:grok="http://namespaces.zope.org/grok"
>     >
>     <include package="grok" />
>     <includeDependencies package="." />
>
>     <include package="MyApp.permission"/>
>     <include package="MyApp" />
>
>   </configure>
>
>
> regards, jw
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev
>


More information about the Grok-dev mailing list