Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/factory.py
Show All 16 Lines | |||||
__all__ = ["get_objstorage", "ObjStorage"] | __all__ = ["get_objstorage", "ObjStorage"] | ||||
_STORAGE_CLASSES: Dict[str, Union[type, Callable[..., type]]] = { | _STORAGE_CLASSES: Dict[str, Union[type, Callable[..., type]]] = { | ||||
"pathslicing": PathSlicingObjStorage, | "pathslicing": PathSlicingObjStorage, | ||||
"remote": RemoteObjStorage, | "remote": RemoteObjStorage, | ||||
"memory": InMemoryObjStorage, | "memory": InMemoryObjStorage, | ||||
"weed": WeedObjStorage, | "seaweedfs": WeedObjStorage, | ||||
"random": RandomGeneratorObjStorage, | "random": RandomGeneratorObjStorage, | ||||
} | } | ||||
_STORAGE_CLASSES_MISSING = {} | _STORAGE_CLASSES_MISSING = {} | ||||
_STORAGE_CLASSES_DEPRECATED = {"weed": "seaweedfs"} | |||||
try: | try: | ||||
from swh.objstorage.backends.azure import ( | from swh.objstorage.backends.azure import ( | ||||
AzureCloudObjStorage, | AzureCloudObjStorage, | ||||
PrefixedAzureCloudObjStorage, | PrefixedAzureCloudObjStorage, | ||||
) | ) | ||||
_STORAGE_CLASSES["azure"] = AzureCloudObjStorage | _STORAGE_CLASSES["azure"] = AzureCloudObjStorage | ||||
Show All 32 Lines | Args: | ||||
that must match exactly the one in the `__init__` method of the | that must match exactly the one in the `__init__` method of the | ||||
class. | class. | ||||
Returns: | Returns: | ||||
subclass of ObjStorage that match the given `storage_class` argument. | subclass of ObjStorage that match the given `storage_class` argument. | ||||
Raises: | Raises: | ||||
ValueError: if the given storage class is not a valid objstorage | ValueError: if the given storage class is not a valid objstorage | ||||
key. | key. | ||||
""" | """ | ||||
if cls in _STORAGE_CLASSES_DEPRECATED: | |||||
warnings.warn( | |||||
f"{cls} objstorage class is deprecated, " | |||||
f"use {_STORAGE_CLASSES_DEPRECATED[cls]} class instead.", | |||||
DeprecationWarning, | |||||
) | |||||
cls = _STORAGE_CLASSES_DEPRECATED[cls] | |||||
if cls in _STORAGE_CLASSES: | if cls in _STORAGE_CLASSES: | ||||
if args is not None: | if args is not None: | ||||
warnings.warn( | warnings.warn( | ||||
'Explicit "args" key is deprecated for objstorage initialization, ' | 'Explicit "args" key is deprecated for objstorage initialization, ' | ||||
"use class arguments keys directly instead.", | "use class arguments keys directly instead.", | ||||
DeprecationWarning, | DeprecationWarning, | ||||
) | ) | ||||
# TODO: when removing this, drop the "args" backwards compatibility | # TODO: when removing this, drop the "args" backwards compatibility | ||||
# from swh.objstorage.api.server configuration checker | # from swh.objstorage.api.server configuration checker | ||||
kwargs = args | kwargs = args | ||||
return _STORAGE_CLASSES[cls](**kwargs) | return _STORAGE_CLASSES[cls](**kwargs) | ||||
else: | else: | ||||
raise ValueError( | raise ValueError( | ||||
"Storage class {} is not available: {}".format( | "Storage class {} is not available: {}".format( | ||||
cls, _STORAGE_CLASSES_MISSING.get(cls, "unknown name") | cls, _STORAGE_CLASSES_MISSING.get(cls, "unknown name") | ||||
) | ) | ||||
) | ) | ||||
Show All 22 Lines |