Exemple #1
0
 def test_copy_stored_file_when_local(self, mock):
     tmp = tempfile.mkstemp()[1]
     copy_stored_file(tmp,
                      tmp,
                      src_storage=local_storage,
                      dst_storage=private_storage)
     assert not mock.called
     local_storage.delete(tmp)
Exemple #2
0
def _resize_video(src, instance, lib=None, **kw):
    """
    Given a preview object and a file somewhere: encode into the full
    preview size and generate a thumbnail.
    """
    log.info('[1@None] Encoding video %s' % instance.pk)
    lib = lib or library
    if not lib:
        log.info('Video library not available for %s' % instance.pk)
        return

    video = lib(src)
    video.get_meta()
    if not video.is_valid():
        log.info('Video is not valid for %s' % instance.pk)
        return

    if waffle.switch_is_active('video-encode'):
        # Do the video encoding.
        try:
            video_file = video.get_encoded(mkt.ADDON_PREVIEW_SIZES[1])
        except Exception:
            log.info('Error encoding video for %s, %s' %
                     (instance.pk, video.meta), exc_info=True)
            return

    # Do the thumbnail next, this will be the signal that the
    # encoding has finished.
    try:
        thumbnail_file = video.get_screenshot(mkt.ADDON_PREVIEW_SIZES[0])
    except Exception:
        # We'll have this file floating around because the video
        # encoded successfully, or something has gone wrong in which case
        # we don't want the file around anyway.
        if waffle.switch_is_active('video-encode'):
            local_storage.delete(video_file)
        log.info('Error making thumbnail for %s' % instance.pk, exc_info=True)
        return

    copy_stored_file(thumbnail_file, instance.thumbnail_path,
                     src_storage=local_storage, dst_storage=public_storage)
    if waffle.switch_is_active('video-encode'):
        # Move the file over, removing the temp file.
        copy_stored_file(video_file, instance.image_path,
                         src_storage=local_storage,
                         dst_storage=public_storage)
    else:
        # We didn't re-encode the file.
        copy_stored_file(src, instance.image_path, src_storage=local_storage,
                         dst_storage=public_storage)
        #
    # Now remove local files.
    local_storage.delete(thumbnail_file)
    if waffle.switch_is_active('video-encode'):
        local_storage.delete(video_file)

    # Ensure everyone has read permission on the file.
    instance.sizes = {'thumbnail': mkt.ADDON_PREVIEW_SIZES[0],
                      'image': mkt.ADDON_PREVIEW_SIZES[1]}
    instance.save()
    log.info('Completed encoding video: %s' % instance.pk)
    return True
 def test_copy_stored_file_when_local(self, mock):
     tmp = tempfile.mkstemp()[1]
     copy_stored_file(tmp, tmp, src_storage=local_storage,
                      dst_storage=private_storage)
     assert mock.not_called
     local_storage.delete(tmp)
Exemple #4
0
def _resize_video(src, instance, lib=None, **kw):
    """
    Given a preview object and a file somewhere: encode into the full
    preview size and generate a thumbnail.
    """
    log.info('[1@None] Encoding video %s' % instance.pk)
    lib = lib or library
    if not lib:
        log.info('Video library not available for %s' % instance.pk)
        return

    video = lib(src)
    video.get_meta()
    if not video.is_valid():
        log.info('Video is not valid for %s' % instance.pk)
        return

    if waffle.switch_is_active('video-encode'):
        # Do the video encoding.
        try:
            video_file = video.get_encoded(mkt.ADDON_PREVIEW_SIZES[1])
        except Exception:
            log.info('Error encoding video for %s, %s' %
                     (instance.pk, video.meta), exc_info=True)
            return

    # Do the thumbnail next, this will be the signal that the
    # encoding has finished.
    try:
        thumbnail_file = video.get_screenshot(mkt.ADDON_PREVIEW_SIZES[0])
    except Exception:
        # We'll have this file floating around because the video
        # encoded successfully, or something has gone wrong in which case
        # we don't want the file around anyway.
        if waffle.switch_is_active('video-encode'):
            local_storage.delete(video_file)
        log.info('Error making thumbnail for %s' % instance.pk, exc_info=True)
        return

    copy_stored_file(thumbnail_file, instance.thumbnail_path,
                     src_storage=local_storage, dst_storage=public_storage)
    if waffle.switch_is_active('video-encode'):
        # Move the file over, removing the temp file.
        copy_stored_file(video_file, instance.image_path,
                         src_storage=local_storage,
                         dst_storage=public_storage)
    else:
        # We didn't re-encode the file.
        copy_stored_file(src, instance.image_path, src_storage=local_storage,
                         dst_storage=public_storage)
        #
    # Now remove local files.
    local_storage.delete(thumbnail_file)
    if waffle.switch_is_active('video-encode'):
        local_storage.delete(video_file)

    # Ensure everyone has read permission on the file.
    instance.sizes = {'thumbnail': mkt.ADDON_PREVIEW_SIZES[0],
                      'image': mkt.ADDON_PREVIEW_SIZES[1]}
    instance.save()
    log.info('Completed encoding video: %s' % instance.pk)
    return True
Exemple #5
0
        return '', 'Signer is not configured.'
    app_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'nagios_check_packaged_app.zip')
    signed_path = tempfile.mktemp()
    try:
        packaged.sign_app(local_storage.open(app_path),
                          signed_path,
                          None,
                          False,
                          local=True)
        return '', 'Package signer working'
    except PackageSigningError, e:
        msg = 'Error on package signing (%s): %s' % (destination, e)
        return msg, msg
    finally:
        local_storage.delete(signed_path)


# Not called settings to avoid conflict with django.conf.settings.
def settings_check():
    required = [
        'APP_PURCHASE_KEY', 'APP_PURCHASE_TYP', 'APP_PURCHASE_AUD',
        'APP_PURCHASE_SECRET'
    ]
    for key in required:
        if not getattr(settings, key):
            msg = 'Missing required value %s' % key
            return msg, msg

    return '', 'Required settings ok'
Exemple #6
0
def package_signer():
    destination = getattr(settings, 'SIGNED_APPS_SERVER', None)
    if not destination:
        return '', 'Signer is not configured.'
    app_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'nagios_check_packaged_app.zip')
    signed_path = tempfile.mktemp()
    try:
        packaged.sign_app(local_storage.open(app_path), signed_path, None,
                          False, local=True)
        return '', 'Package signer working'
    except PackageSigningError, e:
        msg = 'Error on package signing (%s): %s' % (destination, e)
        return msg, msg
    finally:
        local_storage.delete(signed_path)


# Not called settings to avoid conflict with django.conf.settings.
def settings_check():
    required = ['APP_PURCHASE_KEY', 'APP_PURCHASE_TYP', 'APP_PURCHASE_AUD',
                'APP_PURCHASE_SECRET']
    for key in required:
        if not getattr(settings, key):
            msg = 'Missing required value %s' % key
            return msg, msg

    return '', 'Required settings ok'


def solitude():