Exemplo n.º 1
0
    def do_process_key(self, key):
        log.debug('{} getting file in temp storage'.format(key))
        active_storage.copy(key, temp_storage)

        log.debug('{} creating resized images'.format(key))
        create_resized_images(temp_storage.path(), key)

        log.debug('{} uploading files to active storage'.format(key))
        for resized in resized_keys(key):
            temp_storage.move(resized, active_storage)

        temp_storage.delete(key)

        with self.lock:
            self.processed += 1
Exemplo n.º 2
0
    def do_process_key(self, key):
        log.debug('{} getting file in temp storage'.format(key))
        active_storage.copy(key, temp_storage)

        log.debug('{} creating resized images'.format(key))
        create_resized_images(temp_storage.path(), key)

        log.debug('{} uploading files to active storage'.format(key))
        for resized in resized_keys(key):
            temp_storage.move(resized, active_storage)

        temp_storage.delete(key)

        with self.lock:
            self.processed += 1
Exemplo n.º 3
0
def publish(request):
    filename = request.POST['filename']
    already_published = active_storage.exists(filename)
    if 'crop' in request.POST:
        crop_options = request.POST['crop']
        if already_published:
            active_storage.copy(filename, temp_storage)
        else:
            incoming_storage.copy(filename, temp_storage)
        crop_and_publish_thumbs(filename, crop_options)
        temp_storage.delete(filename)
    else:
        for key in resized_keys(filename):
            if incoming_storage.exists(key):
                incoming_storage.move(key, active_storage)
    if not already_published:
        incoming_storage.move(filename, active_storage)
    return {'success': True}
Exemplo n.º 4
0
def recrop(request):
    # Retrieve and rename file
    old_filename = request.POST['filename']
    base, ext = os.path.splitext(old_filename)
    active_storage.copy(old_filename, temp_storage)
    filename = '{name}{ext}'.format(name=create_pseudo_unique_key(), ext=ext)
    os.rename(temp_storage.object_path(old_filename), temp_storage.object_path(filename))
    temp_storage.copy(filename, active_storage)
    # Crop and generate thumbnails
    if 'crop' in request.POST:
        crop_options = request.POST['crop']
        crop_and_publish_thumbs(filename, crop_options)
    else:
        create_resized_images(temp_storage.path(), filename)
        for key in resized_keys(filename):
            temp_storage.move(key, active_storage)
    temp_storage.delete(filename)
    return {'filename': filename}
Exemplo n.º 5
0
def publish(request):
    if request.POST['secret'] != os.environ['API_SECRET_KEY']:
        raise HTTPForbidden('Bad secret key')
    filename = request.POST['filename']
    already_published = active_storage.exists(filename)
    if 'crop' in request.POST:
        crop_options = request.POST['crop']
        if already_published:
            active_storage.copy(filename, temp_storage)
        else:
            incoming_storage.copy(filename, temp_storage)
        crop_and_publish_thumbs(filename, crop_options)
        temp_storage.delete(filename)
    else:
        for key in resized_keys(filename):
            if incoming_storage.exists(key):
                incoming_storage.move(key, active_storage)
    if not already_published:
        incoming_storage.move(filename, active_storage)
    return {'success': True}