예제 #1
0
def recreate_all_image_size_downloads(root, registry):  # pragma: no cover
    """Recreate all image size downloads to optimize file size."""
    from adhocracy_core.sheets.asset import IAssetMetadata
    from adhocracy_core.sheets.image import IImageMetadata
    from adhocracy_core.resources.image import add_image_size_downloads
    from adhocracy_core.resources.image import IImageDownload
    catalogs = find_service(root, 'catalogs')
    assets = _search_for_interfaces(catalogs, IAssetMetadata)
    images = [x for x in assets if IImageMetadata.providedBy(x)]
    count = len(images)
    for index, image in enumerate(images):
        logger.info('Migrating resource {0} of {1}'.format(index + 1, count))
        for old_download in image.values():
            if IImageDownload.providedBy(old_download):
                del image[old_download.__name__]
        add_image_size_downloads(image, registry)
        catalogs.reindex_index(image, 'interfaces')  # we missed reindexing
예제 #2
0
def recreate_all_image_size_downloads(root, registry):  # pragma: no cover
    """Recreate all image size downloads to optimize file size."""
    from adhocracy_core.sheets.asset import IAssetMetadata
    from adhocracy_core.sheets.image import IImageMetadata
    from adhocracy_core.resources.image import add_image_size_downloads
    from adhocracy_core.resources.image import IImageDownload
    catalogs = find_service(root, 'catalogs')
    assets = _search_for_interfaces(catalogs, IAssetMetadata)
    images = [x for x in assets if IImageMetadata.providedBy(x)]
    count = len(images)
    for index, image in enumerate(images):
        logger.info('Migrating resource {0} of {1}'.format(index + 1, count))
        for old_download in image.values():
            if IImageDownload.providedBy(old_download):
                del image[old_download.__name__]
        add_image_size_downloads(image, registry)
        catalogs.reindex_index(image, 'interfaces')  # we missed reindexing
예제 #3
0
def update_asset_download_children(root, registry):  # pragma: no cover
    """Add asset downloads and update IAssetMetadata sheet."""
    from adhocracy_core.sheets.asset import IAssetMetadata
    from adhocracy_core.sheets.image import IImageMetadata
    from adhocracy_core.resources.asset import add_metadata
    from adhocracy_core.resources.image import add_image_size_downloads
    catalogs = find_service(root, 'catalogs')
    assets = _search_for_interfaces(catalogs, IAsset)
    count = len(assets)
    for index, asset in enumerate(assets):
        logger.info('Migrating resource {0} of {1}'.format(index + 1, count))
        old_downloads = [x for x in asset]
        for old in old_downloads:
            del asset[old]
        try:
            if IAssetMetadata.providedBy(asset):
                add_metadata(asset, registry)
            if IImageMetadata.providedBy(asset):
                add_image_size_downloads(asset, registry)
        except AttributeError:
            logger.warn('Asset {} has no downloads to migrate.'.format(asset))
예제 #4
0
def update_asset_download_children(root, registry):  # pragma: no cover
    """Add asset downloads and update IAssetMetadata sheet."""
    from adhocracy_core.sheets.asset import IAssetMetadata
    from adhocracy_core.sheets.image import IImageMetadata
    from adhocracy_core.resources.asset import add_metadata
    from adhocracy_core.resources.image import add_image_size_downloads
    catalogs = find_service(root, 'catalogs')
    assets = _search_for_interfaces(catalogs, IAsset)
    count = len(assets)
    for index, asset in enumerate(assets):
        logger.info('Migrating resource {0} of {1}'.format(index + 1, count))
        old_downloads = [x for x in asset]
        for old in old_downloads:
            del asset[old]
        try:
            if IAssetMetadata.providedBy(asset):
                add_metadata(asset, registry)
            if IImageMetadata.providedBy(asset):
                add_image_size_downloads(asset, registry)
        except AttributeError:
            logger.warn('Asset {} has no downloads to migrate.'.format(asset))