Logo Search packages:      
Sourcecode: zope-cps-portaltransforms version File versions  Download package


import os
import tempfile
import re
import shutil
from os.path import join, basename

from Products.PortalTransforms.interfaces import itransform
from utils import bin_search

00010 class commandtransform:
    """abstract class for external command based transform
    __implements__ = itransform

    def __init__(self, name=None, binary=None, **kwargs):
        if name is not None:
            self.__name__ = name
        if binary is not None:
            self.binary = bin_search(binary)

    def name(self):
        return self.__name__

00024     def initialize_tmpdir(self, data, **kwargs):
        """create a temporary directory, copy input in a file there
        return the path of the tmp dir and of the input file
        tmpdir = tempfile.mktemp()
        filename = kwargs.get("filename", '')
        fullname = join(tmpdir, basename(filename))
        filedest = open(fullname , "wb").write(data)
        return tmpdir, fullname

    def subObjects(self, tmpdir):
        imgs = []
        for f in os.listdir(tmpdir):
            result = re.match("^.+\.(?P<ext>.+)$", f)
            if result is not None:
                ext = result.group('ext')
                if ext in ('png', 'jpg', 'gif'):
        path = join(tmpdir, '')
        return path, imgs

    def fixImages(self, path, images, objects):
        for image in images:
            objects[image] = open(join(path, image), 'rb').read()

    def cleanDir(self, tmpdir):

Generated by  Doxygen 1.6.0   Back to index