示例#1
0
    def process_file(self, filename):
        if Picture.objects.filter(path=filename).count() != 0:
            return False
        img = Image.open(filename)
        ts = os.path.getctime(filename)
        creation = datetime.fromtimestamp(ts)
        size = os.path.getsize(filename)
        sha = self.shahash(filename)

        p = Picture()
        p.path = filename.decode('utf-8')
        p.hashcode = sha
        p.creation = creation
        p.width, p.height = img.size
        p.size = size

        if Picture.objects.filter(hashcode=sha).count() > 0:
            p.tags = ['deleted']

        p.save()

        try:
            p.thumbnail = self.generate_thumbnail(img, filename, str(p.id))
        except:
            p.delete()
            raise

        p.save()
        print filename, size, img.format, img.size, img.mode, creation, sha
        return True