Coverage for python/lsst/daf/butler/datastores/fileLikeDatastore.py : 89%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This file is part of daf_butler. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (http://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>.
Config, DatabaseDict, DatabaseDictRecordBase, DatasetTypeNotSupportedError, DatastoreConfig, DatastoreValidationError, FileDescriptor, FileTemplates, FileTemplateValidationError, Formatter, FormatterFactory, Location, LocationFactory, StorageClass, StoredFileInfo, )
"""Describes the contents of a datastore record of a dataset in the registry.
The record is usually populated by a `StoredFileInfo` object. """
class DatastoreFileGetInformation: """Collection of useful parameters needed to retrieve a file from a Datastore. """
"""The location from which to read the dataset."""
"""The `Formatter` to use to deserialize the dataset."""
"""Stored information about this file and its formatter."""
"""Parameters to use for post-processing the retrieved dataset."""
"""The component to be retrieved (can be `None`)."""
"""Generic Datastore for file-based implementations.
Should always be sub-classed since key abstract methods are missing.
Parameters ---------- config : `DatastoreConfig` or `str` Configuration as either a `Config` object or URI to file.
Raises ------ ValueError If root location does not exist and ``create`` is `False` in the configuration. """
"""Path to configuration defaults. Relative to $DAF_BUTLER_DIR/config or absolute path. Can be None if no defaults specified. """
"""Class to use to represent datastore records."""
"""Root directory or URI of this `Datastore`."""
"""Factory for creating locations relative to the datastore root."""
"""Factory for creating instances of formatters."""
"""File templates that can be used by this `Datastore`."""
"""Place to store internal records about datasets."""
"""Set any filesystem-dependent config options for this Datastore to be appropriate for a new empty repository with the given root.
Parameters ---------- root : `str` URI to the root of the data repository. config : `Config` A `Config` to update. Only the subset understood by this component will be updated. Will not expand defaults. full : `Config` A complete config with all defaults expanded that can be converted to a `DatastoreConfig`. Read-only and will not be modified by this method. Repository-specific options that should not be obtained from defaults when Butler instances are constructed should be copied from ``full`` to ``config``. overwrite : `bool`, optional If `False`, do not modify a value in ``config`` if the value already exists. Default is always to overwrite with the provided ``root``.
Notes ----- If a keyword is explicitly defined in the supplied ``config`` it will not be overridden by this method if ``overwrite`` is `False`. This allows explicit values set in external configs to be retained. """ toUpdate={"root": root}, toCopy=("cls", ("records", "table")), overwrite=overwrite)
raise ValueError("No root directory specified in configuration")
# Name ourselves either using an explicit name or a name # derived from the (unexpanded) root else: # We use the unexpanded root in the name to indicate that this # datastore can be moved without having to update registry. self.config["root"])
# Support repository relocation in config # Existence of self.root is checked in subclass
# Now associate formatters with storage classes universe=self.registry.dimensions)
# Read the file naming templates universe=self.registry.dimensions)
# Storage of paths and formatters, keyed by dataset_id value=self.Record, key="dataset_id", registry=registry)
"""Convert a `StoredFileInfo` to a suitable database record.
Parameters ---------- info : `StoredFileInfo` Metadata associated with the stored Dataset.
Returns ------- record : `DatastoreRecord` Record to be stored. """ storage_class=info.storageClass.name, checksum=info.checksum, file_size=info.file_size)
"""Convert a record associated with this dataset to a `StoredItemInfo`
Parameters ---------- record : `DatastoreRecord` Object stored in the record table.
Returns ------- info : `StoredFileInfo` The information associated with this dataset record as a Python class. """ # Convert name of StorageClass to instance path=record.path, storageClass=storageClass, checksum=record.checksum, file_size=record.file_size)
"""Find the `Location` of the requested dataset in the `Datastore` and the associated stored file information.
Parameters ---------- ref : `DatasetRef` Reference to the required `Dataset`.
Returns ------- location : `Location` Location of the dataset within the datastore. Returns `None` if the dataset can not be located. info : `StoredFileInfo` Stored information about this file and its formatter. """ # Get the file information (this will fail if no file)
# Use the path to determine the location
"""Check parameters for ``get`` and obtain formatter and location.
Parameters ---------- ref : `DatasetRef` Reference to the required Dataset. parameters : `dict` `StorageClass`-specific parameters that specify, for example, a slice of the Dataset to be loaded.
Returns ------- getInfo : `DatastoreFileGetInformation` Parameters needed to retrieve the file. """
# Get file metadata and internal metadata
# We have a write storage class and a read storage class and they # can be different for concrete composites.
# Check that the supplied parameters are suitable for the type read
# Is this a component request?
FileDescriptor(location, readStorageClass=readStorageClass, storageClass=writeStorageClass, parameters=parameters))
assemblerParams, component, readStorageClass)
"""Check the arguments for ``put`` and obtain formatter and location.
Parameters ---------- inMemoryDataset : `object` The Dataset to store. ref : `DatasetRef` Reference to the associated Dataset.
Returns ------- location : `Location` The location to write the dataset. formatter : `Formatter` The `Formatter` to use to write the dataset.
Raises ------ TypeError Supplied object and storage class are inconsistent. DatasetTypeNotSupportedError The associated `DatasetType` is not handled by this datastore. """
# Work out output file name except KeyError as e: raise DatasetTypeNotSupportedError(f"Unable to find template for {ref}") from e
# Get the formatter based on the storage class FileDescriptor(location, storageClass=storageClass))
"""Update registry to indicate that this dataset has been stored, specifying file metadata.
Parameters ---------- ref : `DatasetRef` Dataset to register. formatter : `Formatter` Formatter to use to read this dataset. path : `str` Path to dataset relative to datastore root. size : `int` Size of the serialized dataset. checksum : `str`, optional Checksum of the serialized dataset. Can be `None`. """ # Associate this dataset with the formatter for later read. file_size=size, checksum=checksum)
"""URI to the Dataset.
Parameters ---------- ref : `DatasetRef` Reference to the required Dataset. predict : `bool` If `True`, allow URIs to be returned of datasets that have not been written.
Returns ------- uri : `str` URI string pointing to the Dataset within the datastore. If the Dataset does not exist in the datastore, and if ``predict`` is `True`, the URI will be a prediction and will include a URI fragment "#predicted". If the datastore does not have entities that relate well to the concept of a URI the returned URI string will be descriptive. The returned URI is not guaranteed to be obtainable.
Raises ------ FileNotFoundError A URI has been requested for a dataset that does not exist and guessing is not allowed.
""" # if this has never been written then we have to guess
else: # If this is a ref that we have written we can get the path. # Get file metadata and internal metadata
# Use the path to determine the location
"""Validate some of the configuration for this datastore.
Parameters ---------- entities : iterable of `DatasetRef`, `DatasetType`, or `StorageClass` Entities to test against this configuration. Can be differing types. logFailures : `bool`, optional If `True`, output a log message for every validation error detected.
Raises ------ DatastoreValidationError Raised if there is a validation problem with a configuration. All the problems are reported in a single exception.
Notes ----- This method checks that all the supplied entities have valid file templates and also have formatters defined. """
except FileTemplateValidationError as e: templateFailed = str(e)
messages.append(templateFailed)
# Docstring is inherited from base class self.constraints.getLookupKeys()
# Docstring is inherited from base class # The key can be valid in either formatters or templates so we can # only check the template if it exists if lookupKey in self.templates: try: self.templates[lookupKey].validateTemplate(entity) except FileTemplateValidationError as e: raise DatastoreValidationError(e) from e |