[Zope] Python script to modify the permision on photos

Chris Withers chris at simplistix.co.uk
Wed May 26 05:57:17 EDT 2004


kbond wrote:

> So far I already play around in "spe" and get the following:
> ++++++++++++++++++++++module++++++++++++++++++++++++++
> #! /usr/bin/env python
> 
> import os, sys
> sys.path.append("/usr/lib/zope/lib/python")
> import Zope
> Zope.configure("/home/yml/myZopeInstances/sitePerso/etc/zope.conf")
> app = Zope.app()

You could do the work in a Script (Python) too, then you don't have to do this 
dance, or worry about managing transactions, conflict errors, and the rest for 
yourself...

> photo = chant3.get('Chantier 053.jpg')
> photo.manage_permission("View", "MyRole",1)
> 
> I have several questions concerning this code:
> How can I check, by script, that I have done a modification on the 
> permission?

That's pretty involved. The only way I could find to do it was with this function:

     def checkSettings(object,permissionname,acquire=0,roles=[]):
         # check the roles and acquire settings for a permission on an
         # object are as expected
         happy=0
         for pstuff in object.ac_inherited_permissions(1):
             name,value = pstuff[:2]
             if name==permissionname:
                 p = Permission(name,value,object)
                 groles=p.getRoles(default=[])
                 acquired=isinstance(groles,types.ListType)
                 expected={}
                 for role in roles:
                     expected[role]=1
                 got={}
                 for role in groles:
                     got[role]=1
                 self.assertEqual((acquire,expected),(acquired,got))
                 happy=1
         if not happy:
             raise ValueError,"'%s' not found in permissions: %s" % (
                                    permissionname,all_names
                                    )

So, to test your edit above, you would do:
checkSettings(photo,'View',1,['MyRole'])

> Please I am stuck And I do not know where to search I have googled the 
> whole evening without any success.

Now, if you're wondering why your changes aren't "sticking", see what I said 
about Script (Python)'s.

your need to do a:

get_transaction().commit()

..after you've made your changes, but the n you gotta worry abotu conflict errors..

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk




More information about the Zope mailing list