[Zope-CMF] Accessing skins objects

Charlie Clark charlie at begeistert.org
Tue Feb 10 05:59:58 EST 2009


Am 10.02.2009 um 10:16 schrieb Charlie Clark:

> Now the profile results:
> 1) View
>  4499 function calls (4476 primitive calls) in 0.110 CPU seconds
>
> 2) PythonScript
>  12830 function calls (12786 primitive calls) in 0.154 CPU seconds

I've added an interator which reduces the number of calls:

  2370 function calls (2362 primitive calls) in 0.041 CPU seconds

But this reduces data transfer still further to between 10 and 20 MB/s!

While I'm convinced that the code is probably better I'm at a loss  
about the slowdown. This is the code for comments:

class FilesIterator(object):

     size = 0
     files = []

     def __init__(self, files):
         for f, size in files:
             self.files.append(f)
             self.size += size

     def next(self):
         while self.files:
             f = open(self.files.pop(), "rb")
             data = f.read()
             f.close()
             return data

class Javascript(ViewBase):
     """Return all Javascript from the skin as a single string"""

     folder_name = 'js'
     content_type = 'application/x-javascript'

     @memoize
     def contents(self):
         skin_tool = getToolByName(self.context, 'portal_skins')
         layer = skin_tool.getDefaultSkin()
         skin = skin_tool.getSkinByName(layer)
         folder = getattr(skin, self.folder_name)
         obs = [(ob._filepath, ob.get_size()) for ob in  
folder.objectValues()
                        if ob.meta_type == "Filesystem File"]
         fs = FilesIterator(obs)
         return fs

     def __call__(self):
         bundle = self.contents()
         self.request.response.setHeader("Content-Type",  
self.content_type)
         self.request.response.setHeader("Content-Length", bundle.size)
         data = bundle.next()
         while data:
             self.request.response.write(data)
             data = bundle.next()

I did look at the file_iterator in ZPublisher.Iterators but I couldn't  
see a way to combine that with a list of files.

Charlie
--
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226





More information about the Zope-CMF mailing list