コード例 #1
0
ファイル: fix_user_images.py プロジェクト: fligtar/zamboni
    def handle(self, *args, **options):
        from django.conf import settings
        from users.tasks import delete_photo, resize_photo

        if not os.path.isdir(settings.USERPICS_PATH):
            sys.exit("Can't read pics path: %s" % settings.USERPICS_PATH)

        converted = 0
        for root, dirs, files in os.walk(settings.USERPICS_PATH):
            for file in files:
                if file[-4:] in ('.jpg', '.gif'):
                    name, _ = os.path.splitext(file)
                    oldfile = "%s/%s" % (root, file)
                    newfile = "%s/%s.png" % (root, name)

                    if os.path.isfile(newfile):
                        delete_photo(oldfile)
                    else:
                        resize_photo(oldfile, newfile)
                        converted += 1
                        if converted % 100 == 0:
                            print "Converted %s images..." % converted

                elif file.endswith('.png') or file.endswith('__unconverted'):
                    pass
                else:
                    print "Not sure what to do with: %s" % file
        print "All done."
コード例 #2
0
ファイル: test_tasks.py プロジェクト: LittleForker/zamboni
def test_delete_photo():
    dst = tempfile.NamedTemporaryFile(mode='r+w+b', suffix='.png',
                                      delete=False)
    path = os.path.dirname(dst.name)
    settings.USERPICS_PATH = path
    delete_photo(dst.name)

    assert not os.path.exists(dst.name)
コード例 #3
0
def test_delete_photo():
    dst_path = tempfile.mktemp(suffix='.png', dir=settings.TMP_PATH)
    dst = storage.open(dst_path, mode='wb')
    with dst:
        dst.write('test data\n')
    path = os.path.dirname(dst_path)
    settings.USERPICS_PATH = path
    delete_photo(dst_path)

    assert not storage.exists(dst_path)
コード例 #4
0
ファイル: test_tasks.py プロジェクト: abdellah-bn/olympia
def test_delete_photo():
    dst_path = tempfile.mktemp(suffix='.png',
                               dir=settings.TMP_PATH)
    dst = storage.open(dst_path, mode='wb')
    with dst:
        dst.write('test data\n')
    path = os.path.dirname(dst_path)
    settings.USERPICS_PATH = path
    delete_photo(dst_path)

    assert not storage.exists(dst_path)