swh:1:snp:eb70f1f85391e4b077c211bec36af0061c4bf937
Raw File
Tip revision: a4abad0c8a7bf797fbba9ada197f149f422ac81e authored by Antoine R. Dumont (@ardumont) on 24 November 2017, 10:13:48 UTC
schemata: Add missing __init__.py for build package purposes
Tip revision: a4abad0
__init__.py
# Copyright (C) 2015-2016  The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information

from . import storage

Storage = storage.Storage


def get_storage(cls, args):
    """
    Get a storage object of class `storage_class` with arguments
    `storage_args`.

    Args:
        storage (dict): dictionary with keys:
        - cls (str): storage's class, either 'local' or 'remote'
        - args (dict): dictionary with keys

    Returns:
        an instance of swh.storage.Storage (either local or remote)

    Raises:
        ValueError if passed an unknown storage class.

    """

    if cls == 'remote':
        from .api.client import RemoteStorage as Storage
    elif cls == 'local':
        from .storage import Storage
    else:
        raise ValueError('Unknown storage class `%s`' % cls)

    return Storage(**args)
back to top