Programmatically assigning roles in plone

Is there a way to programatically assign roles such as can add can edit on a plone website. I would really appreciate if there is a way to do so because i have to be going through every folders on my website and assign roles to each folders which is very tedious and time consuming.

im using plone 4.3 under python 2.7. Any any help would be appreciated, thanks in advance.

See other thread on this topic, I think the answer you are seeking is not imperative ("progrmmatically") but declarative (workflow definition).