StorageClassFactory

class lsst.daf.butler.StorageClassFactory(config: Union[lsst.daf.butler.core.storageClass.StorageClassConfig, str, None] = None)

Bases: object

Factory for StorageClass instances.

This class is a singleton, with each instance sharing the pool of StorageClasses. Since code can not know whether it is the first time the instance has been created, the constructor takes no arguments. To populate the factory with storage classes, a call to addFromConfig() should be made.

Parameters:
config : StorageClassConfig or str, optional

Load configuration. In a ButlerConfig` the relevant configuration is located in the storageClasses section.

Methods Summary

addFromConfig(config, …) Add more StorageClass definitions from a config file.
findStorageClass(pytype, compare_types) Find the storage class associated with this python type.
getStorageClass(storageClassName) Get a StorageClass instance associated with the supplied name.
items()
keys()
makeNewStorageClass(name, baseClass, …) Create a new Python class as a subclass of StorageClass.
registerStorageClass(storageClass, msg, …) Store the StorageClass in the factory.
values()

Methods Documentation

addFromConfig(config: Union[lsst.daf.butler.core.storageClass.StorageClassConfig, lsst.daf.butler.core.config.Config, str]) → None

Add more StorageClass definitions from a config file.

Parameters:
config : StorageClassConfig, Config or str

Storage class configuration. Can contain a storageClasses key if part of a global configuration.

findStorageClass(pytype: Type, compare_types: bool = False) → lsst.daf.butler.core.storageClass.StorageClass

Find the storage class associated with this python type.

Parameters:
pytype : type

The Python type to be matched.

compare_types : bool, optional

If False, the type will be checked against name of the python type. This comparison is always done first. If True and the string comparison failed, each candidate storage class will be forced to have its type imported. This can be significantly slower.

Returns:
storageClass : StorageClass

The matching storage class.

Raises:
KeyError

Raised if no match could be found.

Notes

It is possible for a python type to be associated with multiple storage classes. This method will currently return the first that matches.

getStorageClass(storageClassName: str) → lsst.daf.butler.core.storageClass.StorageClass

Get a StorageClass instance associated with the supplied name.

Parameters:
storageClassName : str

Name of the storage class to retrieve.

Returns:
instance : StorageClass

Instance of the correct StorageClass.

Raises:
KeyError

The requested storage class name is not registered.

items() → ItemsView[str, lsst.daf.butler.core.storageClass.StorageClass]
keys() → KeysView[str]
static makeNewStorageClass(name: str, baseClass: Optional[Type[lsst.daf.butler.core.storageClass.StorageClass], None] = <class 'lsst.daf.butler.core.storageClass.StorageClass'>, **kwargs) → Type[lsst.daf.butler.core.storageClass.StorageClass]

Create a new Python class as a subclass of StorageClass.

Parameters:
name : str

Name to use for this class.

baseClass : type, optional

Base class for this StorageClass. Must be either StorageClass or a subclass of StorageClass. If None, StorageClass will be used.

Returns:
newtype : type subclass of StorageClass

Newly created Python type.

registerStorageClass(storageClass: lsst.daf.butler.core.storageClass.StorageClass, msg: Optional[str, None] = None) → None

Store the StorageClass in the factory.

Will be indexed by StorageClass.name and will return instances of the supplied StorageClass.

Parameters:
storageClass : StorageClass

Type of the Python StorageClass to register.

msg : str, optional

Additional message string to be included in any error message.

Raises:
ValueError

If a storage class has already been registered with that storage class name and the previous definition differs.

values() → ValuesView[lsst.daf.butler.core.storageClass.StorageClass]