Archive for June, 2010

Extract all images of your skin with a script to serve them by apache

Posted in plone on June 21, 2010 by toutpt

Following the unloading Plone conference at budapest last year, you may want to serve images from skin directly by apache.

To do this you will need first to extract images. So here is a small python script to help you:

skintool = context.portal_skins
skin = skintool.getDefaultSkin()
PATHS = skintool.getSkinPath(skin).split(',')

images = skintool.ZopeFind(skintool, obj_metatypes=['Filesystem Image'],search_sub=1)
images_skin = [path for path, obj in images if path.split('/')[0] in PATHS and skintool.isFirstInSkin(path)]
images_str = "\n".join(['/'.join(path.split('/')[1:]) for path,obj in images])
print "You have extracted %s images. Here is the result:"%(len(images_skin))
print images_str
return printed

To use it, you just have to go in the Zope Management Interface (ZMI), Add a Script (Python) with the drop down menu and paste this script. Next you can excecute it with the “test” tab or access it by it’s url.

Write the content of the result page in a text file and then follow this blog post: http://www.makina-corpus.org/blog/use-rewritemap-prevent-proxying-some-static-contents

Hope this will help you to unloading Plone.

How to add a random time between two emails sent from zope.sendmail

Posted in plone, zope on June 15, 2010 by toutpt

I’m using collective.dancing for a mass mailing: +8000 emails to send.

One of the question is how to not be blacklisted ? A first thing I have done today is to add a random time between two sent.

To achieve this I have read the code of zope.sendmail. It is a well documented egg so this is not hard to understand how it works:

  • A maildir (a directory) store mails under files ready to be sent
  • A mailer (a utility) is ready to be called to send email one by one
  • A queue mail delivrery (utility) is ready to put messages inside a maildir
  • A mailqueue processor (not a component, a thread implementation) parse every 3 seconds if there is new emails to send in the mailbox

So to achieve this you just have to unconfigure the plone.smtp utility and declare a new utility called plone.smtp with this code:

import random
import time

from zope.sendmail import mailer

class SMTP(mailer.SMTPMailer):
    """Override SMTPMailer to let a random time"""

    def send(self, fromaddr, toaddrs, message):
        time.sleep(random.uniform(0,2))
        super(SMTP, self).send(fromaddr, toaddrs, message)

It’s working !