Exemplo n.º 1
0
def image(static_file, album_slug, slug, thumbnail=False):
    filename = _image_filename(album_slug, slug)
    if not file_updated(static_file.filename, filename):
        raise AlreadyUpdatedError

    if thumbnail:
        size = (
            settings.gallery.THUMBNAIL_WIDTH,
            settings.gallery.THUMBNAIL_HEIGHT
        )
    else:
        size = (
            settings.gallery.IMAGE_WIDTH,
            settings.gallery.IMAGE_HEIGHT
        )

    image = _preprocess_image(
        filename,
        size,
        settings.gallery.QUALITY,
        thumbnail and settings.gallery.CROP_THUMBNAIL
    )

    io = StringIO.StringIO()
    image.save(io, 'JPEG', quality=settings.gallery.QUALITY)
    static_file.content = io.getvalue()
    io.close()
Exemplo n.º 2
0
 def copy_public_dir(self):
     for src_dir, dirnames, filenames in os.walk(settings.PUBLIC_DIR):
         dest_dir = path_append(
             settings.BUILD_DIR,
             src_dir[len(settings.PUBLIC_DIR):]
         )
         try:
             os.mkdir(dest_dir)
         except OSError as err:
             if err.errno != errno.EEXIST:
                 raise
         for filename in filenames:
             dest_path = os.path.join(dest_dir, filename)
             src_path = os.path.join(src_dir, filename)
             if file_updated(dest_path, src_path):
                 self.logger.info("[copy] %(src)s %(dest)s", {
                     'src': src_path,
                     'dest': dest_path,
                 })
                 shutil.copy(src_path, dest_dir)