コード例 #1
0
ファイル: handler.py プロジェクト: antroy/Home
    def prepareThumbDir(self):
        thumbroot = path.join(self.root, ".thumbs")
        if not path.exists(thumbroot):
            os.makedirs(thumbroot)

        thumbs = [path.join(".thumbs", x) for x in os.listdir(thumbroot) if x.endswith(".jpg")]
        LOG.debug("[prepareThumbDir] Thumbnails: %s" % thumbs)

        requiredThumbs = {}

        for pic in self.pics:
            name, ext = path.splitext(pic)
            thumbnail = path.join(".thumbs", name + "-thumb" + ext)
            requiredThumbs[thumbnail] = pic

        LOG.debug("[prepareThumbDir] Required Thumbs: %s", requiredThumbs.keys())

        for thumb in thumbs:
            if not (thumb in requiredThumbs.keys()):
                os.remove(path.join(self.root, thumb))

        for thumb in requiredThumbs.keys():
            if not (thumb in thumbs):
                m = antim.manipulator(path.join(self.root, requiredThumbs[thumb]))
                LOG.debug("[prepareThumbDir] Creating thumbnail %s", thumb)
                m.createThumb(path.join(self.root, thumb))
コード例 #2
0
ファイル: handler.py プロジェクト: antroy/Home
    def shrinkPics(self):
        pics = self.pics

        ftped = False

        for p in pics:
            pic = path.join(self.root, p)
            size = path.getsize(pic)
            if path.exists(pic) and size > 200000:
                ftped = True
                client = self.getFtpClient(self.rel_path)

                big_image_name = "%s_big%s" % path.splitext(p)
                self.uploadFile(client, big_image_name, pic)

                opts = antim.get_default_options()
                opts.overwrite = True
                m = antim.manipulator(pic, opts)
                m.process()

                self.uploadFile(client, p, pic)

        if ftped:
            client.close()