Coverage for python/lsst/daf/butler/core/fileTemplates.py : 97%

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/>.
"""Configuration information for `FileTemplates`"""
"""Collection of `FileTemplate` templates.
Parameters ---------- config : `FileTemplatesConfig` or `str` Load configuration. default : `str`, optional If not `None`, a default template to use if no template has been specified explicitly in the configuration. """
# We can disable defaulting with an empty string in a config # or by using a boolean else: else:
"""Retrieve the `FileTemplate` associated with the dataset type.
If the lookup name corresponds to a component the base name for the component will be examined if the full component name does not match.
Parameters ---------- entity : `DatasetType`, `DatasetRef`, or `StorageClass` Instance to use to look for a corresponding template. A `DatasetType` name or a `StorageClass` name will be used depending on the supplied entity. Priority is given to a `DatasetType` name.
Returns ------- template : `FileTemplate` Template instance to use with that dataset type.
Raises ------ KeyError No template could be located for this Dataset type. """
# Get the names to use for lookup
# Get a location from the templates
# if still not template give up for now.
"""Format a path template into a fully expanded path.
Parameters ---------- template : `str` Template string.
Notes ----- The templates use the standard Format Specification Mini-Language with the caveat that only named fields can be used. The field names are taken from the DataUnits along with several additional fields:
- datasetType: `str`, `DatasetType.name` - component: `str`, name of the StorageClass component - collection: `str`, `Run.collection` - run: `int`, `Run.id`
At least one or both of `run` or `collection` must be provided to ensure unique filenames.
The mini-language is extended to understand a "?" in the format specification. This indicates that a field is optional. If that DataUnit is missing the field, along with the text before the field, unless it is a path separator, will be removed from the output path. """
"""Format a template string into a full path.
Parameters ---------- ref : `DatasetRef` The dataset to be formatted.
Returns ------- path : `str` Expanded path.
Raises ------ KeyError Requested field is not defined and the field is not optional. Or, `component` is specified but "component" was not part of the template. """ # Extract defined non-None units from the dataId
# Remove the non-standard character from the spec else:
# If this is optional ignore the format spec # and do not include the literal text prior to the optional # field unless it contains a "/" path separator else: raise KeyError("{} requested in template but not defined and not optional".format(field_name))
# Now use standard formatting
# Complain if we were meant to use a component self.template))
# Complain if there's no run or collection
# Since this is known to be a path, normalize it in case some double # slashes have crept in
# It should not be an absolute path (may happen with optionals) path = os.path.relpath(path, start="/")
|