Exemplo n.º 1
0
    def copy(self, destdir):
        for f in self.files + [ self.fxd_file, self.image, self.edl_file ]:
            if f:
                error_msg=''
                if vfs.isoverlay(f):
                    d = vfs.getoverlay(destdir)
                else:
                    d = destdir

                if not os.path.isdir(d):
                    os.makedirs(d)

                if os.path.isdir(f):
                    dst = os.path.join(d, os.path.split(f)[1])
                    shutil.copytree(f, dst)
                else:
                    dst = os.path.join(d, os.path.split(f)[1])
                    if os.path.exists(dst):
                        if config.SHOPPINGCART_CLOBBER:
                            try:
                                os.unlink(dst)
                            except IOError, e:
                                error_msg='Can\'t delete "%s": %s' % (dst, e)

                        else:
                            error_msg='Can\'t copy "%s", destination exists' % dst
                    else:
                        try:
                            shutil.copy2(f, d)
                        except IOError, e:
                            error_msg='Can\'t copy "%s": %s' % (f, e)
Exemplo n.º 2
0
    def copy(self, destdir):
        for f in self.files + [self.fxd_file, self.image, self.edl_file]:
            if f:
                error_msg = ''
                if vfs.isoverlay(f):
                    d = vfs.getoverlay(destdir)
                else:
                    d = destdir

                if not os.path.isdir(d):
                    os.makedirs(d)

                if os.path.isdir(f):
                    dst = os.path.join(d, os.path.split(f)[1])
                    shutil.copytree(f, dst)
                else:
                    dst = os.path.join(d, os.path.split(f)[1])
                    if os.path.exists(dst):
                        if config.SHOPPINGCART_CLOBBER:
                            try:
                                os.unlink(dst)
                            except IOError, e:
                                error_msg = 'Can\'t delete "%s": %s' % (dst, e)

                        else:
                            error_msg = 'Can\'t copy "%s", destination exists' % dst
                    else:
                        try:
                            shutil.copy2(f, d)
                        except IOError, e:
                            error_msg = 'Can\'t copy "%s": %s' % (f, e)
Exemplo n.º 3
0
 def move(self, destdir):
     for f in self.files + [ self.fxd_file, self.image, self.edl_file ]:
         if f:
             if vfs.isoverlay(f):
                 d = vfs.getoverlay(destdir)
             else:
                 d = destdir
             if not os.path.isdir(d):
                 os.makedirs(d)
             os.system('mv "%s" "%s"' % (f, d))
Exemplo n.º 4
0
 def move(self, destdir):
     for f in self.files + [ self.fxd_file, self.image, self.edl_file ]:
         if f:
             if vfs.isoverlay(f):
                 d = vfs.getoverlay(destdir)
             else:
                 d = destdir
             if not os.path.isdir(d):
                 os.makedirs(d)
             os.system('mv "%s" "%s"' % (f, d))
Exemplo n.º 5
0
 def copy(self, destdir):
     for f in self.files + [ self.fxd_file, self.image, self.edl_file ]:
         if f:
             if vfs.isoverlay(f):
                 d = vfs.getoverlay(destdir)
             else:
                 d = destdir
             if not os.path.isdir(d):
                 os.makedirs(d)
             if os.path.isdir(f):
                 dst = os.path.join(d, os.path.split(f)[1])
                 shutil.copytree(f, dst)
             else:
                 shutil.copy2(f, d)
Exemplo n.º 6
0
def get_image(filename, scale, size):
    cache_key = '%s-%s-%dx%d' % (filename, scale, size[0], size[1])

    # First check the loaded image cache
    image = image_cache[cache_key]

    # Second check the on disk cache
    if config.CACHE_IMAGES and not image:
        if vfs.isoverlay(filename):
            cache_dir = os.path.dirname(filename)
        else:
            cache_dir = vfs.getoverlay(filename)
        root,ext = os.path.splitext(filename)
        cache_file = '%s-%s-%dx%d%s' % (USABLE_RESOLUTION,  scale, size[0], size[1], ext)
        cache_filename = os.path.join(cache_dir, cache_file)
        if vfs.exists(cache_filename) and vfs.mtime(cache_filename) > vfs.mtime(filename):
            image = imlib2.open(cache_filename)
            image_cache[cache_key] = image

    # Finally load the image and scale it as required.
    if not image:
        if filename.startswith('http://') or filename.startswith('https://'):
            fp = webcache.get_default_cache().get(filename)
            image = imlib2.open_from_memory(fp.read())
            fp.close()
        else:
            image = imlib2.open(filename)
        w = image.width
        h = image.height
        src_size = (image.width, image.height)

        if scale == 'horizontal':
            w = size[0]
            dst_size = (w, h)

        elif scale == 'vertical':
            h = size[1]
            dst_size = (w, h)

        elif scale == 'both':
            w = size[0]
            h = size[1]
            dst_size = (w, h)

        elif scale == 'aspect':
            aspect_ratio = float(w) / float(h)
            w = size[0]
            h = int(float(w) / aspect_ratio)
            if h > size[1]:
                w = int(float(size[1]) * aspect_ratio)
                h = size[1]

            dst_size = (w, h)

        else:
            if w > size[0]:
                w = size[0]
            if h > size[1]:
                h = size[1]
            size = (w, h)
            src_size = size
            dst_size = size
        logger.log( 9, 'Creating image %s (%dx%d) of size %dx%d using scale %s', filename, src_size[0], src_size[1], dst_size[0], dst_size[1], scale)
        image = image.scale(dst_size, src_size=src_size)

        image_cache[cache_key] = image

        if config.CACHE_IMAGES:
            if not vfs.exists(cache_dir):
                os.makedirs(cache_dir)
            image.save(cache_filename)
            logger.debug('Saved to %s', cache_filename)

    return image
Exemplo n.º 7
0
def get_image(filename, scale, size):
    cache_key = '%s-%s-%dx%d' % (filename, scale, size[0], size[1])

    # First check the loaded image cache
    image = image_cache[cache_key]

    # Second check the on disk cache
    if config.CACHE_IMAGES and not image:
        if vfs.isoverlay(filename):
            cache_dir = os.path.dirname(filename)
        else:
            cache_dir = vfs.getoverlay(filename)
        root, ext = os.path.splitext(filename)
        cache_file = '%s-%s-%dx%d%s' % (USABLE_RESOLUTION, scale, size[0],
                                        size[1], ext)
        cache_filename = os.path.join(cache_dir, cache_file)
        if vfs.exists(cache_filename
                      ) and vfs.mtime(cache_filename) > vfs.mtime(filename):
            image = imlib2.open(cache_filename)
            image_cache[cache_key] = image

    # Finally load the image and scale it as required.
    if not image:
        if filename.startswith('http://') or filename.startswith('https://'):
            fp = webcache.get_default_cache().get(filename)
            image = imlib2.open_from_memory(fp.read())
            fp.close()
        else:
            image = imlib2.open(filename)
        w = image.width
        h = image.height
        src_size = (image.width, image.height)

        if scale == 'horizontal':
            w = size[0]
            dst_size = (w, h)

        elif scale == 'vertical':
            h = size[1]
            dst_size = (w, h)

        elif scale == 'both':
            w = size[0]
            h = size[1]
            dst_size = (w, h)

        elif scale == 'aspect':
            aspect_ratio = float(w) / float(h)
            w = size[0]
            h = int(float(w) / aspect_ratio)
            if h > size[1]:
                w = int(float(size[1]) * aspect_ratio)
                h = size[1]

            dst_size = (w, h)

        else:
            if w > size[0]:
                w = size[0]
            if h > size[1]:
                h = size[1]
            size = (w, h)
            src_size = size
            dst_size = size
        logger.log(9, 'Creating image %s (%dx%d) of size %dx%d using scale %s',
                   filename, src_size[0], src_size[1], dst_size[0],
                   dst_size[1], scale)
        image = image.scale(dst_size, src_size=src_size)

        image_cache[cache_key] = image

        if config.CACHE_IMAGES:
            if not vfs.exists(cache_dir):
                os.makedirs(cache_dir)
            image.save(cache_filename)
            logger.debug('Saved to %s', cache_filename)

    return image