[Zope] Python script to modify the permision on photos

kbond kbond at free.fr
Fri May 28 23:15:42 EDT 2004

Chris Withers wrote:

> 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...

I am not sure to understand the previous statement could you please be 
more explicit?

>> 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
Thank you for your help.
I now need to digest what you sent to me that look nice but for some 
unexpected reason I am not yet able to get it up and running.
I guess this is a matter playing a bit with your function in order to 
taylor it to meet my expectation.
There is still a couple of thing that are unclear to me:
-How can I list all the role available on an object?
-How can I get the permissions list granted on an object?
- Which module should I import in my script in order to run your function?
- Is there somewhere a nice tutorial that will help me to be familiar 
with the ZOPE API?

As I guess you noticed I am a newbie in the zope world so I am sorry 
asking stupid things

More information about the Zope mailing list