Exemplo n.º 1
0
        thumb = os.path.join(thumb_dir,
                             md5 + '.jpg')
        if not os.path.isfile(thumb):
            im.thumbnail((128, 128), Image.ANTIALIAS)
            im.save(thumb)

        print md5sum.hexdigest(), mimetype, file_path

        # save file information to the database
        try:
            file_path_hash = hashlib.md5()
            file_path_hash.update(file_path.encode('utf-8'))
            fph = file_path_hash.hexdigest()

            f = File(mime_type=mimetype, size=sfile.st_size, mtime=sfile.st_mtime,
                     md5sum=md5, tn_path=thumb, file_path=file_path, file_path_hash=fph)
            f.save()
        except django.db.utils.IntegrityError:
            f = File.objects.get(file_path_hash=fph)
            if sfile.st_mtime == f.mtime:
                print "Already in database and up-to-date, skipping %s ..." % (file_path,)
                continue
            f.mime_type = mimetype
            f.size = sfile.st_size
            f.mtime = sfile.st_mtime
            f.md5sum = md5
            f.tn_path = thumb
            f.save()
        except:
            raise